In HTML5, Microdata is a way to embed structured data within HTML documents. It allows you to provide additional information about the content on your web page in a machine-readable format. This can be useful for search engines and other applications that want to understand the meaning of the content.

Here's a basic example of how to use Microdata in HTML5:

html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Microdata Example</title> </head> <body> <article itemscope itemtype="http://schema.org/Article"> <h1 itemprop="name">How to Use Microdata in HTML5</h1> <p>Published on <time itemprop="datePublished" datetime="2023-01-01">January 1, 2023</time></p> <div itemprop="author" itemscope itemtype="http://schema.org/Person"> <p>Written by <span itemprop="name">John Doe</span></p> </div> <div itemprop="publisher" itemscope itemtype="http://schema.org/Organization"> <p>Published by <span itemprop="name">Your Website</span></p> </div> <div itemprop="articleBody"> <p>This is a tutorial on how to use Microdata in HTML5. Microdata allows you to embed structured data...</p> <!-- More content goes here --> </div> </article> </body> </html>

In this example:

  • The <article> element represents the main content of the page.
  • The itemscope attribute indicates that the element defines the scope of the microdata.
  • The itemtype attribute specifies the type of the item using a URL from a vocabulary like schema.org.
  • The itemprop attribute is used to define properties of the item.

In this case:

  • name, datePublished, and author are properties of the Article item.
  • name is a property of the Person item.
  • name is a property of the Organization item.

When a search engine or other tool processes this page, it can understand the structured data and use it to provide more informative search results or for other purposes.

Make sure to replace the content and properties with the relevant information for your specific use case. You can refer to schema.org for a wide range of vocabulary to use in your Microdata.