Performance: Common HTML mistakes
Common HTML mistakes affect page load speed, rendering stability, and user experience by causing unnecessary reflows, layout shifts, or blocking resources.
<header><h1>Title</h1><h2>Subtitle</h2></header>
<div><b>Title</b></div><div><i>Subtitle</i></div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using generic <div> with <b>/<i> | Low | 1-2 reflows due to style changes | Medium | [X] Bad |
| Using semantic <header> and <h1>/<h2> | Low | Single reflow | Low | [OK] Good |
| Missing alt attribute on <img> | No extra DOM ops | No reflows | No paint cost | [!] OK but accessibility issue |
| Proper alt attribute on <img> | No extra DOM ops | No reflows | No paint cost | [OK] Good |
| Invalid nesting <p><div> | Browser reparses DOM | Multiple reflows | High | [X] Bad |
| Correct nesting <div><p> | Normal DOM ops | Single reflow | Low | [OK] Good |
<p> must be closed with </p> to define content boundaries.<img src='cat.jpg' alt='cat'> uses single quotes around both src and alt values correctly.<div><p>Hello<div>World</p></div>
<div> cannot be inside a <p> tag because <p> cannot contain block elements like <div>.<p> before the inner <div>, so "World" is outside the paragraph.<ul> <li>Item 1 <li>Item 2</li> </ul>
<li> must be properly closed to separate list items.<li> is not closed, so the browser may merge both items incorrectly.<label>Name</label> <input type="text" id="name">
for attribute matching the input's id.<label for="name">Name</label>\n<input type="text" id="name"> uses for="name" on label and id="name" on input, making it accessible and correct.Pass the test and this pattern moves unknown