Microformats Explained
What Are Microformats?
Microformats are simple HTML classes that add semantic meaning to your existing HTML. They don’t require special syntax or separate files—you just add class names to elements you already have. The key insight: your HTML can be both human-readable (what browsers render) and machine-readable (what feed readers and tools like Granary can parse).
Why Use Them?
Instead of maintaining a separate RSS/Atom feed file, you can mark up your HTML page with microformats. Tools like Granary can then read your page and convert it into various feed formats (RSS, JSON Feed, etc.) automatically. One source of truth, multiple outputs.
The Classes We’re Using
Container: h-feed
The h-feed class marks the container that holds a collection of items. Think of it as the <channel> in RSS or the root <feed> in Atom.
<main class="h-feed">
<!-- feed items go here -->
</main>
Feed Properties: p-name, p-summary
These describe the feed itself:
p-name: The title/name of the feedp-summary: A description of what the feed contains
Individual Items: h-entry
Each item in the feed is wrapped in an element with the h-entry class. This is like an <item> in RSS or an <entry> in Atom.
<div class="h-entry">
<!-- entry content -->
</div>
Entry Properties
u-photo: The URL of a photo (used on<img>tags or links)p-name: The title/name of the entryp-summary: Brief description of the entrydt-published: The publication date/time (use<time>withdatetimeattribute)e-content: The main content of the entry, which can contain multiple html elements
How It Works
- You write normal HTML with semantic classes added
- Browsers render it normally (the classes are just CSS hooks)
- Microformat parsers (like Granary) read the classes and extract structured data
- Granary converts your HTML page into RSS, JSON Feed, etc.
Example Structure
<main class="h-feed">
<h2 class="p-name">Photo Feed</h2>
<p class="p-summary">Description of the feed</p>
<div class="h-entry">
<img src="photo.jpg" class="u-photo" alt="Description" />
<p class="p-name">Photo Title</p>
<time class="dt-published" datetime="2024-01-15T10:00:00Z">Jan 15, 2024</time>
<p class="p-content">Photo description or caption</p>
</div>
<!-- more h-entry items -->
</main>
Converting to RSS with Granary
Granary provides a hosted service that converts your microformats HTML pages into RSS feeds automatically. Simply add a link in your HTML <head> that points to Granary’s conversion service:
<link rel="alternate" type="application/rss+xml" title="RSS"
href="https://granary.io/url?input=html&output=rss&url=https://alabut.com/projects/microformats/photos/combined-feed/">
How it works:
- Granary fetches your HTML page
- Parses the microformats (
h-feed,h-entry,u-photo, etc.) - Converts them to standard RSS format
- Feed readers can subscribe to the Granary URL, which acts as a proxy
Output formats:
- RSS:
output=rss - Atom:
output=atom - JSON Feed:
output=jsonfeed
Example RSS feed URL:
https://granary.io/url?input=html&output=rss&url=https://alabut.com/projects/microformats/photos/combined-feed/
Testing
You can test your microformats using:
- Microformats Parser - paste your HTML to see what gets extracted
- Granary - converts microformats to various feed formats
- Monocle Preview - preview how your feed will appear in social readers:
- Browser extensions like IndieWebify.Me to validate
Resources
- Microformats.org - official documentation
- h-feed specification
- h-entry specification
- u-photo specification