What are microformats? | HTML

HTML microformats are a way of embedding structured data into HTML documents using special class names, attributes, and values. Microformats are designed to make it easier for machines to understand the content of a web page, by providing semantic information about the data on the page.

Types of Microformats

There are a number of different types of microformats, each with their own specific syntax and purpose. Some common examples include:

  1. hCard: Used to represent contact information, such as a person's name, email address, phone number, and so on.
  2. hCalendar: Used to represent calendar events, such as a concert or conference, including the date, time, location, and other details.
  3. hReview: Used to represent reviews of products or services, including the reviewer's name, the item being reviewed, and a rating.

How to use Microformats

To use microformats, you need to add the appropriate class names and attributes to the HTML markup on your page. For example, to use the hCard microformat, you would add the "vcard" class to a div or span element that contains the person's contact information. Within that element, you would use class names like "fn" for the person's full name, "email" for their email address, and so on.

Following is an example of how the hCard microformat might be used:

<div class="vcard"> <div class="fn">Cris Walter</div> <div class="org">Intl Inc.</div> <div class="tel">+1-555-555-1414</div> <a class="email" href="mailto:cris.walter@example.com">cris.walter@example.com</a> </div>
Full Source | HTML Microformats
<!DOCTYPE html> <html> <head> <title>Example Microformats</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <h1>Example Microformats</h1> <h2>h-card</h2> <div class="vcard"> <p class="fn">Cris Wlater</p> <p class="org">Intl Inc.</p> <a class="email" href="mailto:cris.walter@intl.com">cris.walter@intl.com</a> </div> <h2>h-event</h2> <div class="vevent"> <p class="summary">Webinar: How to Use Microformats</p> <p class="description">Join us for a webinar on how to use microformats to improve your website.</p> <p class="dtstart">2023-06-01T10:00:00-07:00</p> <p class="dtend">2023-06-01T11:00:00-07:00</p> <p class="location">Online</p> <a class="url" href="https://example.com/webinar">More information</a> </div> <script type="application/ld+json"> { "@context": "http://schema.org/", "@type": "Organization", "name": "Intl Inc.", "url": "https://www.acme.com/", "logo": "https://www.acme.com/logo.png", "contactPoint": { "@type": "ContactPoint", "telephone": "+1-555-1234", "contactType": "customer service" } } </script> </body> </html>
run this source code Browser View

Example Microformats

h-card

Cris Wlater

Intl Inc.

h-event

Webinar: How to Use Microformats

Join us for a webinar on how to use microformats to improve your website.

2023-06-01T10:00:00-07:00

2023-06-01T11:00:00-07:00

Online

More information

In this example, two microformats: h-card and h-event. The h-card microformat is used to mark up information about a person or organization. The h-event microformat is used to mark up information about an event.

The h-card microformat is represented by the .vcard class. The fn class is used to mark up the person or organization name, the org class is used to mark up the organization name, and the email class is used to mark up the email address.

The h-event microformat is represented by the .vevent class. The summary class is used to mark up the event name, the description class is used to mark up the event description, the dtstart class is used to mark up the event start date and time, the dtend class is used to mark up the event end date and time, and the location class is used to mark up the event location.

Finally, included a script that uses JSON-LD to mark up information about the organization, including its name, URL, logo, and contact information.

Note that in order for microformats to be useful, they need to be used consistently throughout a website, and preferably across multiple websites. The microformats should also be documented in a way that makes it clear how they are used and what each class represents.

Conclusion:

By using microformats like hCard, you can provide more semantic information about the data on your page, making it easier for search engines and other tools to understand and make use of that data. This can improve the accessibility, usability, and findability of your web content. Additionally, it can enable your content to be consumed by a wide range of tools and services, such as social media platforms, directory services, and mobile devices.