HTML Semantics Cheat Sheet
HTML Semantics Cheat Sheet
Document
<title>
Second most important piece of content.
Shown in the browser tab & search results.
Should be unique for every page on the site.
<header>
When inside <body> it's the website masthead.
When inside <article> it's the most important information.
<footer>
When inside <body> it's the website footer.
When inside <article> it's the least important information.
<main>
Primary content of the page.
<nav>
Defines a group a navigation links.
<article>
A piece of content that's independent.
Could be removed from this website and still make sense.
<section>
A group in a series of related content pieces.
<aside>
Secondary content not required to understand the main content.
<main>
<h1>Dinos-R-Us</h1>
</main>
<footer>
<p>© 2063 Dinos-R-Us</p>
</footer>
</body>
Lists
<ul>
An unordered list—the order of items isn't important.
Can only have <li> elements as direct children.
<ol>
An ordered list—the order of the items is important.
Could be alphabetical, numerical, best to worst, etc.
Can only have <li> elements as direct children.
<li>
A single list item.
Must be inside a <ul> , <ol> or <menu> .
Can have most other elements inside it.
<dl>
A description list—a grouping of terms and definitions.
Words & definitions, titles & summaries, data points, etc.
Can only have <dt> and <dd> elements as direct children.
<dt>
Description title, the term of the item.
Must come before the <dd> .
<dd>
Description definition, the data, or text of the item.
Can be multiple <dd> tags underneath one <dt> .
Unordered list
<ul>
<li>Tyrannosaurus</li>
<li>Spinosaurus</li>
<li>Velociraptor</li>
</ul>
Ordered list
<ol>
<li>Mercury</li>
<li>Venus</li>
<li>Earth</li>
<li>Mars</li>
</ol>
Description list
<dl>
<dt>Length</dt>
<dd>2.3 m</dd>
<dt>Weight</dt>
<dd>4 tonnes</dd>
</dl>
<menu>
For semantically marking up a web application's toolbar of buttons.
The <menu> tag also uses <li> tags inside—one for each toolbar button.
You may still have to remove the bullets.
Menutoolbar list
<menu>
<li><button>Like</button></li>
<li><button>Share</button></li>
<li><button>Comment</button></li>
</menu>
Text
<a href="…">
For making hyperlinks.
href is the path to where the link should go.
<h1>
The most important piece of content on the page.
On the homepage this should be the company's name.
On inside pages this should be the page title.
<h2> , <h3> , <h4> , <h5> , <h6>
Content headings, each a sub-heading of the one above.
The <h2> is a sub-heading of <h1> , <h3> a sub-heading of <h2> , etc.
<hgroup>
Allows you to group multiple headings together and have them semantically treated as a single heading.
It's primary purpose is for subheadings.
<p>
A generic paragraph of text.
<blockquote>
A large, stand alone quote from another source.
<cite>
A citation for another source, often used with quotations.
A person's name, a URL, a book, a movie title, etc.
<q>
A small quotation embedded within other content.
<em>
A string of emphasized, slightly more important text.
Screen readers will change their voice for this text.
<strong>
A string of highly emphasized, much more important text.
Screen readers will change their voice for this text.
<ins datetime="…">
Content that was inserted after the document was published.
datetime defines when it was added.
<del datetime="…">
Content that was deleted after the document was published.
datetime defines when it was removed.
<abbr title="…">
An acronym or abbreviation, like “HTML”, “CSS”, etc.
title contains the expanded version, like “Hypertext Markup Language”.
<dfn>
A definition of a term on the page.
Should only be used once of the term.
<mark>
Used to highlight a piece of text for reference.
The keywords in a search results page, the current navigation item.
<i>
Defines technical term, a ship name, a book title, a thought, sarcasm, another language.
<b>
Defines a keyword, like product name in a review, a lead sentence in a paragraph.
<s>
Content that's no longer relevant to the document.
Consider if the <del> element is better suited first.
<u>
Labels the text as having a non-textual annotation.
A misspelled word, a Chinese proper name, etc.
<small>
Represents side comments and fine print.
<address>
Contact information, email, tel, postal address, etc.
Blockquotes
<blockquote>
<p>Dinosaurs may be extinct from the face of the planet</p>
<footer>— <cite>Steve Miller</cite></footer>
</blockquote>
Addresses
<address>
Jet Propulsion Laboratory
<br>4800 Oak Grove Drive
<br>Pasadena, California
<br>91109
</address>
Text edits
<p>Launchpad 39A owned by <del datetime="2014-04-14">NASA</del>
<ins datetime="2014-04-14">SpaceX</ins></p>
Heading groups
<hgroup>
<h1>Star Wars</h1>
<h2>The Empire Strikes Back</h2>
</hgroup>
Abbreviations
<abbr title="Star Trek: The Wrath of Khan">ST:TWOK</abbr>
Other languages
<i lang="fr">Bonjour</i>
<figure>
Embeds annotated images, illustrations, photos, code, etc.
Could be moved out of place and would still make sense.
<figcaption>
For adding a caption/annotation to the <figure> .
Must be inside a <figure> element—cannot stand alone.
<picture>
Responsive image insertion—allows developers to provide different images for different contexts.
<source>
Must be inside <picture> , <video> or <audio> to define the different versions of content.
For example, in video it gives paths to the MP4 and WEBM formats.
<track>
Used to pair captions, chapters, etc. with <video> elements.
Basic images
<img src="images/dino.jpg" alt="An beautiful, long-necked Brontosaurus">
Responsiveimages
See Responsive & retina images for details.
<picture>
<source media="(min-width: 60em)" srcset="images/dino-wide.jpg">
<source media="(min-width: 38em)" srcset="images/dino-rectangle.jpg">
<img src="images/dino-small.jpg" alt="All the dinosaurs!">
</picture>
<sub>
Defines text as being subscript.
<sup>
Defines text as being superscript.
<var>
Represents a variable in math or programming.
<time datetime="…">
Marks some text as a time or date.
datetime defines the machine readable version.
<data value="…">
Marks elements as being a numerical piece of information.
value provides the machine readable version.
<code>
Defines a piece of text as a code sample.
<pre>
A piece of text that has a specific formatting, where tabs, whitespaces, etc. should be maintained.
<kbd>
Something a user should type into their computer.
<samp>
Something a user should see output from a computer.
Time
Apollo 11 landed on the moon <time datetime="1969-07-20T20:18">July 20, 1969</time>
Data
Argentinosaurus weighted approximately <data value="90">90 tonnes</data>
Maths
E = mc<sup>2</sup>
Meaningless tags
<div>
Inherits meaning from its children.
Divides content into logical groups, when no other tag is better suited.
Has restrictions on what elements it can be inside.
<span>
Inherits meaning from its children.
Be careful
<br>
Creates a line break that's significant to the content.
Useful in poems and addresses where the division of lines is important.
Do not useto createspacein adesign—use margins andpadding.
<hr>
Represents a thematic break in the content.
For example, a scene change or topic change.
Do not useto createahorizontal line—use CSS borders.
<button>
Represents a interactive, clickable button.
Should be used in forms and with JavaScript.
Donotuse tolink toanotherpage—usethe <a> tag.
<wbr>
Presents an opportunity for the browser to add a line-break if necessary.
Groups strings of text, when no other tag is better suited.
Links
<h2 id="herbivores">Herbivores</h2>
Links tophonenumbers
Start with tel: , use international format
<a href="tel:+18005552368">Call Me!</a>
Date/time formats
Applytothe d a t e t i m e = " " attribute of the < t i m e > , < d e l > & < i n s > elements.
Year
Format: YYYY
Example: 1963
Year,month
Format: YYYY-MM
Example: 1963-11
Nov. 1963
Year,month, day
Format: YYYY-MM-DD
Example: 1963-11-23
Nov.23, 1963
Year,week
Format: YYYY-Wdd
Example: 1963-W47
1936,the week ofNov.18–24
Hour, minute
Format: HH:MM
Example: 17:16
5:16PM
UTC timezone
Format: Z
Example: Z
UTC timezone
Timezone offsets
Format: ±HH:MM
Example: -05:00
Eastern Standard Time, Daylight Savings
Periodofdays,hours
Format: PddDThhH
Example: P686DT23H
686 days,23hours
Periodofhours
Format: PThhH
Example: PT23H
23hours
Periodofminutes
Format: PTmmM
Example: PT18M
18minutes
Exact dateexample
<time datetime="1963-11-23T12:16:20Z">Premiere of the most important TV show of all
time</time>
Rangeoftime periods