Semantic HTML
Using structured semantic HTML elements within the <body> of an HTML page is a form of SEO that enhances machine readability.
HTML Elements
There are 115 HTML elements
HTML Layout
- Header
- Main
- Footer
<!DOCTYPE html><html lang="en"></body></html>Other special elements may be in the
<body>, such as:
- Toast notifications
- Modals
- Special fx
- …
MDN Web Docs — Structuring documents
Header
- Brand — logo
- Navigation
- Controls — search · theme selector · language selector ···
<header> <!-- logo --> </a> <!-- pages --> </ul> </nav>Advanced - controls — 31 collapsed lines
<!-- controls --> <div role="toolbar" class="controls">
<!-- search --> <label for="site-search" class="sr-only">Search site</label> </form>
<!-- theme switcher --> <label for="theme-toggle" class="theme-switch" aria-label="Toggle dark mode"></label>
<!-- language selector --> <summary aria-label="Select Language">English</summary> </ul> </details>
<!-- Subscribe to newsletter --> ... </div> <!-- authentication --> </ul> </header>Footer
- Brand — logo · headline · socials · contact
- Navigation
- Legal — privacy policy · terms of service
<footer>Brand — 19 collapsed lines
<!-- brand --> <!-- logo --> </a> </h2> <!-- headline --> <!-- social media --> </ul> </nav> </hgroup> <!-- pages --> </ul> </hgroup> </ul> </hgroup> </nav> </section>Additional sections — 15 collapsed lines
<!-- copyright --> <!-- legal documents --> </ul> </nav> </section> <!-- credit --> </section> </footer>Main
- Aside
- Sections
- Aside
The page content should be in
<main>
Section
Page content should be divided using
<section>
<section id='hero'>...</section><section id='about'>...</section><section id='contact'>...</section>Aside
Aside typically contains:
- Table of contents navigation
- Related pages navigation
- Comments
- …
Article
Article typically contains:
- Forum post
- Blog article
- User comment
- Widget
- …
Content Elements
Heading
There should only be one
<h1>title per page
<h1>Title</h1><h2>Subtitle</h2>Paragraph
<p>Wake up, Tenno.</p><p>The cake is a lie.</p>List
<ul> <li>Half life</li> <li>Death stranding</li> <li>Cyberpunk</li></ul>Description List
<dl> <dt>Notch</dt> <dd>Creator of Minecraft</dd> <dt>Gabe Newell</dt> <dd>Creator of Valve</dd> <dt>Hideo Kojima</dt> <dd>Creator of Death Stranding</dd></dl>Collapsible
<details> <summary>Click me</summary> Secret message</details>Figure Elements
Table
More table elements
<table> <tr> <th>Column 1</th> <th>Column 2</th> </tr> <tr> <td>Cell 1</td> <td>Cell 2</td> </tr>4 collapsed lines
<tr> <td>Cell 1</td> <td>Cell 2</td> </tr> </table>Quote
<blockquote> It's always too soon to quit</blockquote><p> <cite>Norman Vincent Peale</cite></p>Code
<pre> function main() { console.log('hello world!') }</pre><output> hello world!</output>Image
Advanced image elements
<imgAdvanced — 4 collapsed lines
/>
Audio
Advanced audio elements
<audioAdvanced — 5 collapsed lines
></audio>Video
Advanced video elements
<videoAdvanced — 6 collapsed lines
></video>Map
Canvas
This element requires Javascript
<canvas width="300" height="150"> Javascript is disabled</canvas>Embed
<iframeAdvanced — 5 collapsed lines
></iframe>Figure
<figure> <figcaption> Tun Tun Tun Sahur </figcaption></figure>
Interactive Elements
Link
Join my Minecraft server!</a> Open in new tab
Contact links
Email me!</a> Call a fictional number!</a> Text a fictional number!</a>Email me!
Call a fictional number!
Text a fictional number!
Download link
<a> Download my resume!</a>Download my resume!
Relations
<a rel="help" href="/help" >...</a> Document links
"me" Link represents the document's owner · useful for socials
"author" Link to an author of the document or article
"bookmark" Permalink for the article or document
"tag" Link to a tag applied to this document
"search" Link to search through the document and its related pages
"help" Link to context-sensitive help
Button
Button requires Javascript to function when used outside of
<form>
<button>Click me!</button>Input
Input requires Javascript to function when used outside of
<form>
Specialized
<input type=checkbox> |
checkbox | |
<input type=radio> |
radio | |
<input type=range> |
range | |
<input type=color> |
color | |
<input type=file> |
file |
Textbox
<input type=text> |
text | |
<input type=number> |
number | |
<input type=email> |
||
<input type=tel> |
telephone | |
<input type=url> |
url | |
<input type=password> |
password | |
<input type=search> |
search |
Date time
<input type=date> |
date | |
<input type=month> |
month & year | |
<input type=week> |
week & year | |
<input type=datetime-local> |
date time | |
<input type=time> |
time |
Button
Textarea
Textarea requires Javascript to function when used outside of
<form>
<textareaAdvanced — 6 collapsed lines
> Alot of text can be put in here!</textarea>Select
Select requires Javascript to function when used outside of
<form>
<select> Choose an option </option> <hr/> <option value="html">HTML</option> <option value="css">CSS</option> <option value="js">JS</option>Option group — 5 collapsed lines
<optgroup label="Legacy"> <option value="php">PHP</option> <option value="flash">Flash</option> <option value="java">JApplet</option> </optgroup> </select>Form
<form> |
form |
<label> |
label · optional |
<fieldset> |
field set · optional |
<legend> |
legend · optional |
<output> |
result output · optional |
Form HTML
Dialog
Dialog HTML
<dialog id="dialog-modal"> <p>This is a dialog!</p></dialog> Popover HTML
<p>This is a popover!</p></dialog>Search
<search> <label for="movie">Find a Movie</label> </form></search>Navigation
<nav> </ul></nav> Breadcrumbs HTML
<nav class="breadcrumbs"> <li>Semantic HTML</li> </ol></nav>.breadcrumbs ol { list-style-type: none; padding-left: 0;
li { display: inline-block;
a::after { display: inline-block; color: black; content: "▸"; font-size: 80%; font-weight: bold; padding: 0 3px; } }}Menu
This element is equivalent to
<ul>
stephcraft.net</a><menu></menu>Contact
<address> contact@stephcraft.net </a> (555) 555-5555 </a></address>Stephcraft
(555) 555-5555
Text Elements
Line breaks
Text annotations
Text highlights
<mark> |
mark — highlight | highlight |
<ins cite datetime> |
insert | added |
<del cite datetime> |
delete |
Text notations
Text formatting
Machine readable
<data value> |
data | <data value="minecraft-java">Minecraft: Java Edition</data> |
<time datetime> |
time | <time datetime="2001-09-11">Sep 11</time> |