Performance: First CSS stylesheet
This affects the page's initial load speed and how quickly styles are applied to content, impacting the first visible paint.
Jump into concepts and practice - no test required
<link rel="stylesheet" href="small-styles.css" media="all">
@import url('large-styles.css'); body { background: white; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| @import large CSS | Minimal | 0 before CSS loads | Blocks paint until CSS loads | [X] Bad |
| Direct <link> to small CSS | Minimal | 0 before CSS loads | Paints quickly after CSS loads | [OK] Good |
styles.css in an HTML document?p { color: blue; }
p.special { color: red; }<p class="special">Hello!</p>
p.special targets paragraphs with class "special" and overrides p styles.p.special.body {
background-color: #fff
color: black;
}background-color is not last and misses semicolon.body selector is valid, CSS can be inside external or style tags.<h1> headings on your page to be green, but only those inside a <section> should be bold. Which CSS code achieves this?h1 { color: green; } colors all h1 headings green.section h1 { font-weight: bold; } targets only h1 inside section and makes them bold.