Scoped Styles
Add a<style> tag to any .astro component for automatic CSS scoping:
Global Styles
Opt out of scoping withis:global:
:global():
Dynamic Classes
Useclass:list for conditional classes:
CSS Variables
Pass variables from frontmatter withdefine:vars:
Passing Classes to Children
Accept and apply aclass prop in child components:
External Stylesheets
Import Local Stylesheets
Import CSS files in your component frontmatter:Import from npm Packages
Import stylesheets from npm packages:Link Tags
Load stylesheets frompublic/ or external URLs:
CSS Cascade Order
CSS is evaluated in this order:<link>tags (lowest precedence)- Imported styles
- Scoped styles (highest precedence)
Tailwind CSS
Add Tailwind 4
Install Tailwind using the Astro CLI:Upgrade from Tailwind 3
- Add Tailwind 4 support via CLI or manual installation
-
Uninstall the old integration:
-
Remove from config:
CSS Preprocessors
Astro supports Sass, Stylus, and Less via Vite.Sass
Stylus
Less
LightningCSS
astro.config.mjs:
PostCSS
Create apostcss.config.cjs file:
Framework Styles
React / Preact
Vue
Svelte
Markdown Styling
Style Markdown by:- Adding imported stylesheets to your layout
- Using
<style is:global>in the layout - Adding CSS integrations like Tailwind with the typography plugin