<!-- Loading and parsing styles.css is render-blocking -->
<link rel="stylesheet" href="styles.css" />
<!-- Loading and parsing print.css is not render-blocking -->
<link rel="stylesheet" href="print.css" media="print" />
<!-- Loading and parsing mobile.css is not render-blocking on large screens -->
<link
rel="stylesheet"
href="mobile.css"
media="screen and (width <= 480px)" />CSS performance optimization / notebook
CSS performance optimization
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
/* Very specific selector */
body div#main-content article.post h2.headline {
font-size: 24px;
}
/* You probably only need this */
.headline {
font-size: 24px;
} /* Selects every element inside the <body> */
body * {
font-size: 14px;
display: flex;
} <link rel="preload" href="style.css" as="style" />
<link
rel="preload"
href="ComicSans.woff2"
as="font"
type="font/woff2"
crossorigin />
<link
rel="preload"
href="bg-image-wide.png"
as="image"
media="(width > 600px)" />.element {
will-change: opacity, transform;
}<!-- Loading and parsing styles.css is render-blocking -->
<link rel="stylesheet" href="styles.css" />
<!-- Loading and parsing print.css is not render-blocking -->
<link rel="stylesheet" href="print.css" media="print" />
<!-- Loading and parsing mobile.css is not render-blocking on large screens -->
<link rel="stylesheet" href="mobile.css" media="screen and (width <= 480px)" />/* Font not loaded here */
@font-face {
font-family: "Open Sans";
src: url("OpenSans-Regular-webfont.woff2") format("woff2");
}
h1,
h2,
h3 {
/* It is actually loaded here */
font-family: "Open Sans", sans-serif;
}<link
rel="preload"
href="OpenSans-Regular-webfont.woff2"
as="font"
type="font/woff2"
crossorigin />@font-face {
font-family: "Open Sans";
src: url("OpenSans-Regular-webfont.woff2") format("woff2");
unicode-range: U+0025-00FF;
}@font-face {
font-family: "someFont";
src: url("/path/to/fonts/someFont.woff") format("woff");
font-weight: normal;
font-style: normal;
font-display: fallback;
}article {
contain: content;
}article {
content-visibility: auto;
contain-intrinsic-size: 1000px;
}