Performance: Semantic vs non-semantic elements
This affects page rendering speed and accessibility, impacting how browsers and assistive technologies process content.
<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 |
|---|---|---|---|---|
| Non-semantic <div> with ARIA roles | More DOM nodes with added attributes | Multiple reflows if roles added dynamically | Higher paint cost due to layout shifts | [X] Bad |
| Semantic elements like <header>, <nav> | Fewer DOM operations, native roles | Single reflow on load | Lower paint cost with stable layout | [OK] Good |
<article> which represents an independent piece of content.<div> and <span> are generic containers without meaning. <b> is a presentational element without semantic meaning.<header> is the semantic tag for page or section headers.<head><head> contains metadata, not visible content. <heading> is not a valid HTML tag.<div><h1>Title</h1><p>Paragraph</p></div>
<div> usage<div> is a non-semantic container that can hold any flow content including headings and paragraphs.<h1> will display as a large bold heading, and <p> as a paragraph below it, both visible inside the container.<section><div>Content</section></div>
<div> opens inside <section> but closes after </section>, breaking proper nesting.<div> should close before </section>.<div><div>Main content</div><div>Footer info</div></div>
<main> is the semantic tag for main page content, and <footer> is for footer information.<div> with semantic tags<div> to <main> and the footer <div> to <footer> improves meaning and accessibility.Pass the test and this pattern moves unknown