Table of Contents
A common refrain comes up often in the accessibility field. "Use semantic HTML," people say.
But what does that mean and why does it matter? More importantly, what do you get with semantic HTML?
What is Semantic HTML?
The word "semantic" has a few meanings. In computer science, semantics provides the rules for interpreting expressions of code. In this case, semantics lays out the rules for how HTML (the code) gets interpreted. Those rules govern structure and meaning.
HTML stands for Hypertext Markup Language. Invented by Tim Berners-Lee as a way to link together important research documents, HTML has evolved to do much more than that. Early versions had heading elements (h1, h2, etc.), but not the structural elements like
<footer>. Those came later. Each of these elements gives structure to the document, the web page. Creating semantic code means picking the right element for the job, giving your page structure.
The elements also have a meaning underneath. Every element has an implicit role. For example, the
<header> element has the implicit role of "banner." That means that a screen reader will read that role as a landmark.
People who use screen readers can navigate by those landmarks, granting an easier way to skim the content of a page. If a developer used a
<div> instead of a
<header>, the implicit role would be absent, unless provided with extra code. That means the HTML won't be as useful to the machines that interpret it.
What you get with Semantic HTML
When you select the right element for the content you have, you get some things for free. Free as in the web platform gives it to you without any other effort. We talked about one already:
- Structure and meaning gets conveyed to browsers and assistive technologies.
- Some elements come with built in keyboard functionality, for example, the
- Other elements may communicate state to the browser and assistive technology. Radio buttons and checkboxes do this.
- The browser will give you some CSS styles for free.
- Search engines can index the content more efficiently so people can find it.
- Technologies such as RSS readers and Reader mode can parse and style the content effectively.
If you use a
<span> improperly in place of a more semantic element, you may have to recreate functionality. Worse yet, many people who rely on semantic HTML as the key underpinning of the web won't be able to use what you've made. Choose wisely.
- HTML — Structuring the web MDN Web Docs
- Semantic Structure: Regions, Headings, and Lists WebAIM
- Accessibility Through Semantic HTML 24 Ways
- Why, How, and When to Use Semantic HTML and ARIA CSS-Tricks
- Use Semantic HTML for Easy Keyboard Wins Web.dev
- Div Divisiveness Scott O'Hara
- More to Give than Just the Div: Semantics and How to Get Them Right Hidde de Vries
- Understanding semantics Léonie Watson
- A Brief History of Hypertext The History of the Web
- HTML Semantics TetraLogical