HTML semantics
HTML semantics involve using HTML tags that give meaning to the web content. These tags help browsers, search engines, and assistive technologies understand the structure and significance of content on the web page.
Proper use of HTML semantics is crucial for accessibility, as it ensures that all users, including those with disabilities, can navigate, interact with, and understand web content effectively.
FYI, the related RGAA rule is “8. Éléments obligatoires - Dans chaque page web, les balises ne doivent pas être utilisées uniquement à des fins de présentation.”
Using semantic HTML means, use a button to handle interactive content, a link where you change a page, but also main, header, footer & headings to structure the page.
For example,
Don’t
<div class="blog-post">
<div class="title">Understanding HTML Semantics</div>
<div class="date">July 5, 2024</div>
<div class="summary">This post discusses the importance of using proper HTML tags...</div>
<div class="read-more">Read more</div>
</div>
Do
<article class="blog-post">
<h2>Understanding HTML Semantics</h2>
<time datetime="2024-07-05">July 5, 2024</time>
<p>
This post discusses the importance of using proper HTML tags to enhance web accessibility and search
engine optimization...
</p>
<a href="/posts/html-semantics">Read more</a>
</article>
Attention point
Always wrap text in a semantically meaningful tag. Do not use div or span only. Those have decorative purposes only (=== it is to plug the CSS).
Do not use HTML semantics as a visual shortcut. Default browser styles can lead to issues. For example, don’t use a h3 to have a medium-size title if this is the first title of the page.
This point can be easily tackled with the Text component.
<Text>Automatically wrapped in a meaningful p tag if no meaningful ancestor</Text>
Why does semantics matter?
Semantic HTML significantly enhances web accessibility by structuring content meaningfully, which assistive technologies like screen readers leverage to improve user interaction and navigation. For instance, VoiceOver users can navigate through paragraphs using the shortcut Ctrl + Option + Command + P to move to the next paragraph. This allows users with disabilities to efficiently parse through content, understanding its structure and main points without needing to read every detail.