0
0
HTMLmarkup~8 mins

Semantic vs non-semantic elements in HTML - Performance Comparison

Choose your learning style9 modes available
Performance: Semantic vs non-semantic elements
MEDIUM IMPACT
This affects page rendering speed and accessibility, impacting how browsers and assistive technologies process content.
Structuring a webpage with meaningful HTML elements
HTML
<header>Site Title</header>
<nav>Menu</nav>
<main>Content</main>
<footer>Footer info</footer>
Semantic elements provide built-in meaning and structure, helping browsers render content more predictably and assistive technologies navigate easily.
📈 Performance GainReduces CLS by providing stable layout roles and improves accessibility without extra scripting.
Structuring a webpage with meaningful HTML elements
HTML
<div id="header">Site Title</div>
<div id="nav">Menu</div>
<div id="main">Content</div>
<div id="footer">Footer info</div>
Non-semantic <div> elements do not convey meaning to browsers or assistive tools, causing extra work for accessibility and potential layout shifts.
📉 Performance CostIncreases CLS due to lack of inherent layout roles and may cause extra reflows when scripts add ARIA roles.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Non-semantic <div> with ARIA rolesMore DOM nodes with added attributesMultiple reflows if roles added dynamicallyHigher paint cost due to layout shifts[X] Bad
Semantic elements like <header>, <nav>Fewer DOM operations, native rolesSingle reflow on loadLower paint cost with stable layout[OK] Good
Rendering Pipeline
Semantic elements help the browser understand page structure early, optimizing style calculation and layout. Non-semantic elements require extra scripts or ARIA attributes to convey meaning, adding complexity.
Style Calculation
Layout
Paint
⚠️ BottleneckLayout stage due to potential reflows caused by dynamic role assignments on non-semantic elements
Core Web Vital Affected
CLS
This affects page rendering speed and accessibility, impacting how browsers and assistive technologies process content.
Optimization Tips
1Use semantic HTML elements to provide meaning and structure.
2Avoid overusing <div> and <span> for layout without semantic purpose.
3Semantic elements reduce layout shifts and improve accessibility.
Performance Quiz - 3 Questions
Test your performance knowledge
Which HTML element improves accessibility and reduces layout shifts?
A<div>
B<main>
C<span>
D<b>
DevTools: Performance
How to check: Record a performance profile while loading the page. Look for layout shifts and reflows in the summary and flame chart.
What to look for: High layout shift scores or multiple reflows indicate poor semantic usage causing CLS issues.