Stylesheet loading and critical CSS
Definition and purpose
Critical CSS is the styling needed for the initial visible experience, not a fixed list of properties. A matching external stylesheet in the document head can delay rendering until it is available.
Essential first
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { color: navy; padding: 12px; } </style> </head> <body> <header id="a">Library</header> <main id="b">Article</main> </body></html>The header has readable text and spacing without any optional decoration.
Syntax and mental model
Keep essential layout and readable colors available first. Split genuinely print-only rules with media="print"; this is a media condition, not a guarantee that the file will not download. Inlining a small critical subset can remove a request dependency but increases HTML size, may duplicate cached CSS, and must respect CSP. Compare network waterfall, first paint and repeat navigation with DevTools; use the two inline style blocks below as a local model of a split, not a network benchmark.
Print-only decoration
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { color: navy; } @media print { #a { color: black; border-bottom: 2px solid; } } </style> </head> <body> <header id="a">Library</header> <main id="b">Article</main> </body></html>Screen keeps navy; print uses black and a separator. Move the print block to a separate media=print stylesheet for a local network comparison.
Common mistakes
Do not hide essential content until an optional stylesheet or script arrives. Do not infer faster loading from a smaller CSS file alone.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: CSS-related events, Font metrics and layout stability, Shapes and paint implications. Next lesson: Containment and content visibility.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Stylesheet loading and critical CSS — knowledge check
Five questions on stylesheet loading and critical css.
What determines critical CSS?
Can a nonmatching print sheet download?
What is an inlining trade-off?
What should be compared?
What if optional styles never load?