Performance: Inline, internal, and external CSS
This concept affects page load speed and rendering performance by how CSS is loaded and applied to the page.
Jump into concepts and practice - no test required
<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 |
style attribute?style attribute.<style> tag placed inside the <head> section.<style> p { color: blue; } </style> inside the <head> section correctly uses <style> with CSS inside <head>. Others misuse tags or placement.<head>
<style>
p { color: red; }
</style>
</head>
<body>
<p style="color: blue;">Hello World</p>
</body><head>
<link rel="stylesheet" href="styles.css">
<style>
body { background-color: white; }
</style>
</head>