HTML Structured Data: Microdata and JSON-LD
Create an item with microdata
Microdata uses itemscope to create an item, itemtype to identify its vocabulary type and itemprop to identify a property. Schema.org supplies a vocabulary distinct from HTML. Here a visible name belongs to a Person item.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> </head> <body> <div itemscope itemtype="https://schema.org/Person"> <p> Name: <span itemprop="name">Mina</span> </p> </div> </body></html>The visible name is marked as a property of the Person item.
Use a JSON-LD data block
JSON-LD is a linked-data format encoded as JSON. The script type application/ld+json holds data, not executable JavaScript. @context identifies a vocabulary and @type identifies an entity type. JSON requires double-quoted keys and strings.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"Person","name":"Mina"}
</script> </head> <body> <p>Name: Mina</p> </body></html>The data block parses as JSON and describes the same visible name.
Keep data consistent with visible content
Use vocabulary terms that accurately describe the page. Different consumers support different types and may impose additional requirements for rich results. The example describes an article headline, not a complete rich-result eligibility implementation.
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <title>Metadata practice</title> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"Article","headline":"Library opening hours"}
</script> </head> <body> <article> <h1>Library opening hours</h1> <p>Check the schedule before visiting.</p> </article> </body></html>The headline matches h1. The local check does not validate the vocabulary or search eligibility.
Common mistakes and practice
Do not fabricate ratings, authors or offers. Validate JSON syntax, vocabulary semantics and consumer-specific requirements separately. Use safe JSON serialization when embedding dynamic data; raw untrusted strings can break out of script markup.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Structured Data: Microdata and JSON-LD — Knowledge Check
Apply the metadata concepts taught in this lesson.
Which attribute creates a microdata item?
Which attribute identifies a property?
What script type identifies JSON-LD data?
Does valid JSON guarantee a rich result?
What should a structured headline describe?