Semantic HTML refers to the use of HTML markup that conveys meaning about the content, rather than just defining its appearance. By using semantic elements, you communicate the structure and purpose of your content to browsers, search engines, screen readers, and other developers.
The term “semantic” relates to meaning in language or logic. In HTML, semantic elements clearly describe their meaning to both the browser and the developer.
<header> <h1>My Website</h1> <nav> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </nav></header><main> <article> <h2>Article Title</h2> <p>This is the content of the article...</p> </article> <aside> <h3>Related Links</h3> <p>Some related links here...</p> </aside></main><footer> <p>Copyright 2023</p></footer>
Notice how the semantic version clearly communicates the purpose of each section without relying on class names. A screen reader or search engine can immediately understand the structure of the page.
The <fieldset> element groups related form controls, while <legend> provides a caption for the fieldset. Using proper <label> elements associated with form controls is crucial for accessibility.
While semantic HTML is the foundation of accessible web pages, sometimes you need additional information for assistive technologies. Accessible Rich Internet Applications (ARIA) attributes can enhance semantics when needed.
Always prioritize native semantic HTML elements over ARIA attributes when possible. ARIA should be used to enhance semantics, not replace them. As the first rule of ARIA states: “If you can use a native HTML element or attribute with the semantics and behavior you require already built in, instead of re-purposing an element and adding an ARIA role, state or property to make it accessible, then do so.”
Choose elements based on their meaning, not their default styling
Don’t use headings just to make text bigger or tables for layout
Create a logical document outline
Use heading elements (<h1> through <h6>) to create a hierarchical structure
Don’t skip heading levels (e.g., from <h1> to <h3>)
Use landmarks appropriately
Include one main <main> element per page
Use <header>, <footer>, <nav>, and <aside> to define major page areas
Enhance with ARIA when necessary
Add ARIA roles, states, and properties when HTML semantics aren’t sufficient
Test with screen readers to ensure your content is accessible
Provide text alternatives
Use alt attributes for images
Use <figcaption> for figures
Use <caption> for tables
Make interactive elements accessible
Ensure all interactive elements are keyboard accessible
Use proper form labels and button text
Test with accessibility tools
Use tools like axe, WAVE, or Lighthouse to check for accessibility issues
Test with screen readers like NVDA, JAWS, or VoiceOver
Remember that semantic HTML is not just about following rules—it’s about communicating meaning. Always ask yourself: “Does this element accurately represent the meaning of my content?”
All modern browsers fully support HTML5 semantic elements. However, for older browsers (particularly IE8 and below), you might need to include a polyfill like HTML5Shiv or use JavaScript to create and style these elements properly.
Copy
<!-- Include this in the <head> for older IE browsers --><!--[if lt IE 9]> <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js"></script><![endif]-->
With the decline of older browsers, the need for these polyfills has decreased significantly. However, it’s good to be aware of them for projects that need to support legacy browsers.
Semantic HTML is not just a best practice—it’s a fundamental aspect of building accessible, SEO-friendly, and maintainable websites. By using the right elements for the right purpose, you create a solid foundation for your web projects that benefits all users, regardless of how they access your content.Remember that semantics go beyond just using the right tags—they’re about conveying meaning and structure in a way that both humans and machines can understand. As you develop your HTML skills, continually ask yourself if your markup truly represents the meaning of your content.