Performance: Inline, internal, and external CSS
MEDIUM IMPACT
This concept affects page load speed and rendering performance by how CSS is loaded and applied to the page.
<link rel="stylesheet" href="styles.css"> /* styles.css */ div { color: red; font-size: 20px; }
<div style="color: red; font-size: 20px;">Hello</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline CSS | No extra DOM nodes | Triggers reflow per element if styles change | Paint cost per styled element | [X] Bad |
| Internal CSS | No extra DOM nodes | Blocks rendering until parsed | Paint cost after style calculation | [!] OK |
| External CSS | No extra DOM nodes | Non-blocking if loaded properly | Paint cost after style calculation | [OK] Good |