Performance: Clean HTML structure
Clean HTML structure improves browser parsing speed and reduces layout shifts, enhancing page load and visual stability.
<header><h1>Title</h1></header>
<div><div><div><span>Title</span></div></div></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Deeply nested generic <div>s | High (many nodes, deep nesting) | Multiple reflows during layout | Higher paint cost due to complex layout | [X] Bad |
| Semantic, shallow structure | Low (fewer nodes, shallow nesting) | Single reflow | Lower paint cost with stable layout | [OK] Good |
<!DOCTYPE html> <html lang='en'> <head> <meta charset='UTF-8'> <title>Test</title> </head> <body> <header><h1>Welcome</h1></header> <main><p>Hello World</p></main> <footer><p>Footer text</p></footer> </body> </html>
<html> <head> <title>Page</title> <meta name='viewport' content='width=device-width, initial-scale=1.0'> </head> <body> <h1>Hello</h2> <section>Content here</section> </body> </html>
Pass the test and this pattern moves unknown