In Astro, you want to apply a CSS file globally to all pages. Which method correctly applies global styles?
Think about where global styles should be linked so they affect the whole site.
Global CSS files should be linked once in the root layout's
so all pages inherit the styles. Importing CSS inside components or using inline styles does not apply styles globally.You want to use Tailwind CSS in your Astro project. Which code snippet correctly imports Tailwind's base styles globally?
Tailwind uses special directives inside CSS files, not script tags or inline styles.
Tailwind CSS is imported via @tailwind directives inside a global CSS file, which is then linked globally. Script tags or inline styles do not load Tailwind properly.
You added a global CSS file and linked it in your root layout, but styles are not showing on pages. What is the most likely cause?
Check the URL path in your <link> tag carefully.
If the CSS file path is wrong or missing the leading slash, the browser cannot find the file, so styles won't apply. Astro supports global CSS via root layout linking.
Astro components have scoped styles by default. How does this affect using CSS frameworks like Bootstrap or Tailwind?
Think about the difference between global and scoped CSS in Astro.
CSS frameworks like Bootstrap or Tailwind provide global styles. Astro's scoped styles inside components do not affect these global styles. Therefore, frameworks must be imported globally.
Given a global CSS file setting body { background-color: white; } and a component scoped style setting body { background-color: black; }, what background color will the page body have when rendered?
Consider how scoped styles are applied in Astro and CSS specificity.
Scoped styles in Astro targeting the body do not apply because Astro adds unique attribute selectors (e.g., body[data-astro-xxx] {}), which do not match the actual body element. Therefore, only the global style applies, resulting in a white background.
