Performance: Inline vs external precedence
This concept affects how quickly styles are applied and how the browser resolves conflicts between inline and external CSS, impacting rendering speed and visual stability.
Jump into concepts and practice - no test required
/* external.css */ .my-text { color: red; font-size: 1.5rem; margin: 1rem; } <!-- HTML --> <div class="my-text">Hello</div>
<div style="color: red; font-size: 1.5rem; margin: 1rem;">Hello</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Inline styles | No extra DOM nodes, but larger HTML | Triggers style recalculation during HTML parsing | Paint triggered after style application | [!] OK |
| External CSS | No extra DOM nodes, smaller HTML | Style recalculation after CSS load | Paint triggered after CSS applied | [OK] Good |
style="color: red;" vs external stylesheet setting color: blue;style attribute with CSS rules inside quotes.style="color: blue;" correctly.<style>
p { color: green; }
</style>
<p style="color: orange;">Hello</p>color: green;, inline style sets color: orange;.<style>
.button { background-color: blue; }
</style>
<button class="button" style="background-color: red;">Click</button>style="..." attribute correctly.p { color: blue; }style="color: red;" works immediately.