Fix flash of unfocused content by adding critical inline CSS#8
Fix flash of unfocused content by adding critical inline CSS#8
Conversation
Added critical CSS inline in the <head> to prevent flash of unstyled content. The critical styles include color-scheme, background colors, and grid pattern to ensure the page displays correctly before the external CSS loads.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR adds critical inline CSS to the HTML <head> section to prevent flash of unstyled content (FOUC) during page load. The inline styles define the color scheme, background colors, text colors, font family, and grid pattern to ensure the page displays correctly before the external Tailwind CSS file loads.
Key changes include:
- Added inline
<style>block to Head.component.html with critical CSS for html and body elements - Updated Tailwind CSS from v4.1.13 to v4.1.18 in output.css files
- Inline styles include color-scheme, backgrounds, font-family, and the grid pattern that defines the site's visual identity
Reviewed changes
Copilot reviewed 2 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/components/Head.component.html | Added inline critical CSS block for html and body elements to prevent FOUC |
| src/public/output.css | Updated Tailwind CSS version from v4.1.13 to v4.1.18 |
| dist/output.css | Compiled CSS with Tailwind v4.1.18 update |
| dist/index.html | Generated HTML with new inline critical CSS |
| dist/about.html | Generated HTML with new inline critical CSS |
| dist/projects.html | Generated HTML with new inline critical CSS |
| dist/writing.html | Generated HTML with new inline critical CSS (also shows unrelated content changes) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | ||
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); |
There was a problem hiding this comment.
The inline critical CSS uses hardcoded color values that don't exactly match the CSS custom properties in the external stylesheet. In the external CSS, --color-bg-grid is defined as light-dark(#a8a29e0d, #44444833), but the inline styles use light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)). The alpha values are inconsistent: 0d (hex) equals 0.051, not 0.05, and 33 (hex) equals 0.2, not exactly matching. This could cause a subtle visual difference between the initial render and after the external CSS loads, defeating the purpose of preventing FOUC.
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | |
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); | |
| linear-gradient(to right, light-dark(#a8a29e0d, #44444833) 1px, transparent 1px), | |
| linear-gradient(to bottom, light-dark(#a8a29e0d, #44444833) 1px, transparent 1px); |
| html { | ||
| color-scheme: light dark; | ||
| background: light-dark(#fbf7ec, #161617); | ||
| } | ||
| body { | ||
| font-family: "Sentient", serif; | ||
| color: light-dark(#1c1917, #c9c7cd); | ||
| background: light-dark(#fbf7ec, #161617); | ||
| background-image: | ||
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | ||
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); |
There was a problem hiding this comment.
The inline critical CSS hardcodes style values directly instead of referencing CSS custom properties. This creates a maintenance burden where these values must be kept in sync with the external stylesheet manually. If the design colors change in the external CSS (output.css), this inline CSS must also be updated separately, increasing the risk of inconsistencies. Consider using CSS custom properties in the inline styles as well, or establish a build process to automatically extract and inline critical CSS from the source of truth.
| html { | |
| color-scheme: light dark; | |
| background: light-dark(#fbf7ec, #161617); | |
| } | |
| body { | |
| font-family: "Sentient", serif; | |
| color: light-dark(#1c1917, #c9c7cd); | |
| background: light-dark(#fbf7ec, #161617); | |
| background-image: | |
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | |
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); | |
| :root { | |
| --color-bg-light: #fbf7ec; | |
| --color-bg-dark: #161617; | |
| --color-text-light: #1c1917; | |
| --color-text-dark: #c9c7cd; | |
| --color-grid-light: rgb(168 162 158 / 0.05); | |
| --color-grid-dark: rgb(68 68 72 / 0.2); | |
| } | |
| html { | |
| color-scheme: light dark; | |
| background: light-dark(var(--color-bg-light), var(--color-bg-dark)); | |
| } | |
| body { | |
| font-family: "Sentient", serif; | |
| color: light-dark(var(--color-text-light), var(--color-text-dark)); | |
| background: light-dark(var(--color-bg-light), var(--color-bg-dark)); | |
| background-image: | |
| linear-gradient( | |
| to right, | |
| light-dark(var(--color-grid-light), var(--color-grid-dark)) 1px, | |
| transparent 1px | |
| ), | |
| linear-gradient( | |
| to bottom, | |
| light-dark(var(--color-grid-light), var(--color-grid-dark)) 1px, | |
| transparent 1px | |
| ); |
| background: light-dark(#fbf7ec, #161617); | ||
| } | ||
| body { | ||
| font-family: "Sentient", serif; | ||
| color: light-dark(#1c1917, #c9c7cd); | ||
| background: light-dark(#fbf7ec, #161617); | ||
| background-image: | ||
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | ||
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); | ||
| background-size: 24px 24px; | ||
| } |
There was a problem hiding this comment.
The light-dark() CSS function is a relatively new CSS feature (part of CSS Color Module Level 5) that has limited browser support. According to browser compatibility data, it's only supported in Chrome/Edge 123+, Safari 17.5+, and Firefox 120+. Users on older browsers will not see the appropriate light/dark mode colors, which could result in poor contrast or readability issues. Consider adding fallback colors using the @supports rule or CSS custom properties with fallback values to ensure basic styling works in older browsers.
| background: light-dark(#fbf7ec, #161617); | |
| } | |
| body { | |
| font-family: "Sentient", serif; | |
| color: light-dark(#1c1917, #c9c7cd); | |
| background: light-dark(#fbf7ec, #161617); | |
| background-image: | |
| linear-gradient(to right, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px), | |
| linear-gradient(to bottom, light-dark(rgb(168 162 158 / 0.05), rgb(68 68 72 / 0.2)) 1px, transparent 1px); | |
| background-size: 24px 24px; | |
| } | |
| background: #fbf7ec; | |
| } | |
| body { | |
| font-family: "Sentient", serif; | |
| color: #1c1917; | |
| background: #fbf7ec; | |
| background-image: | |
| linear-gradient(to right, rgb(168 162 158 / 0.05) 1px, transparent 1px), | |
| linear-gradient(to bottom, rgb(168 162 158 / 0.05) 1px, transparent 1px); | |
| background-size: 24px 24px; | |
| } | |
| @media (prefers-color-scheme: dark) { | |
| html { | |
| background: #161617; | |
| } | |
| body { | |
| color: #c9c7cd; | |
| background: #161617; | |
| background-image: | |
| linear-gradient(to right, rgb(68 68 72 / 0.2) 1px, transparent 1px), | |
| linear-gradient(to bottom, rgb(68 68 72 / 0.2) 1px, transparent 1px); | |
| } | |
| } |
Removed async CSS loading trick and inline critical CSS in favor of simple synchronous loading. This approach is cleaner and eliminates the flash of unstyled content without additional complexity.
Added critical CSS inline in the to prevent flash of unstyled content.
The critical styles include color-scheme, background colors, and grid pattern
to ensure the page displays correctly before the external CSS loads.