Performance: Why semantic HTML matters
Semantic HTML improves browser rendering efficiency and accessibility, impacting page load speed and user interaction.
<header>Site Title</header> <nav>Menu</nav> <main>Content</main> <footer>Footer info</footer>
<div id="header">Site Title</div> <div id="nav">Menu</div> <div id="main">Content</div> <div id="footer">Footer info</div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Generic <div> for structure | More nodes and attributes | Multiple reflows if scripts rely on inferred structure | Higher paint cost due to complex layout | [X] Bad |
| Semantic tags like <header>, <nav>, <main>, <footer> | Fewer nodes, clearer structure | Minimal reflows, stable layout | Lower paint cost with predictable layout | [OK] Good |
<main> tag is designed to wrap the main content of a page.<div> and <span> are generic containers without meaning; <footer> is for page footer.<header> <h1>Welcome to My Site</h1> </header>
<header> as headings, helping users navigate.<h1> inside <header>, so it reads "Heading level 1, Welcome to My Site".<div> <nav>Main Navigation</nav> </div>
<nav> tag already defines navigation, so wrapping it in a generic <div> adds no meaning.<div> can confuse assistive technologies and developers by adding unnecessary layers.<header> is for site title, <nav> for menus, <main> for main content, <article> for posts, and <footer> for contact info.Pass the test and this pattern moves unknown