# đ Styling
Styling in Astro is meant to be as flexible as youâd like it to be! The following options are all supported:
| Framework | Global CSS | Scoped CSS | CSS Modules |
| :--------------- | :--------: | :--------: | :---------: |
| Astro (`.astro`) | â | â | N/AÂč |
| React / Preact | â | â | â |
| Vue | â | â | â |
| Svelte | â | â | â |
Âč _`.astro` files have no runtime, therefore Scoped CSS takes the place of CSS Modules (styles are still scoped to components, but donât need dynamic values)_
## đ Quick Start
##### Astro
Styling in an Astro component is done by adding a `
Iâm a scoped style and only apply to this component
I have both scoped and global styles
```
**Tips**
- `
```
You should see Tailwind styles compile successfully in Astro.
đ **Tip**: to reduce duplication, try loading `@tailwind base` from a parent page (`./pages/*.astro`) instead of the component itself.
## đ Advanced Styling Architecture in Astro
Many development setups give you the basics on where to put CSS for small things, but very quickly you realize the simple examples fail you as your code scales, and soon you have a mess on your hands. An natural question for any setup is âhow do I architect my styles?â yet not every framework outlines its rules. While weâd like to say _âuse whatever you want,â_ and leave it up to you, the reality is that not all styling approaches will work as well in Astro as others, because Astro is a blend of new ideas (**Partial Hydration** and **JS frameworks with zero runtime JS**) and old (**HTML-first**). It couldnât hurt to try and provide a guide on how to think about styling architecture in Astro, and this section is precisely that.
An example of all styling approaches not being equal in Astro: given that Astro tries and removes runtime JS, and even the framework if possible, itâd be very inefficient to load all of React just to load Styled Components so your page can have styles (in fact weâd discourage using any CSS-in-JS runtime in Astro in general). On the opposite end of the styling spectrum, you _can_ use a completely-decoupled [BEM][bem] or [SMACSS][smacss] approach in Astro. But thatâs a lot of manual maintenance you can avoid, and it leaves out a lof of convenience of [Astro components][astro-syntax].
We think thereâs a great middle ground between easy-to-use-but-slow CSS-in-JS and fast-but-ornery decoupled CSS. This approach doesnât have a fancy name (yet), but works well in Astro, is performant for users, and will be the best styling solution in Astro _for most people_ (provided youâre willing to learn a little). This guide is structured in the form of some basic doâs and donâts up front, followed by the reasoning behind each. Again, the reason theyâre outlined here and not mandated by the framework is that we want you to ultimately make the decisions! But if youâre looking for opinions, youâve found them đ.
### Rules
1. Avoid global styles (other than utility CSS)
2. Use utility CSS
3. Centralize your layouts
4. Donât use flexbox and grid libraries; write them custom when you need them
5. Never use `margin` on a component wrapper
6. Let each component set its own media queries (i.e. donât have global media queries).
_Note: if these rules seem restrictive, theyâre meant to be! As stated, these are strong opinions that may improve your appsâ styles after you learn the reasons why._
#### 1. Avoid global styles
You donât need an explanation on component-based design. You already know that reusing components is a good idea. And itâs this idea that got people used to concepts like [Styled Components][styled-components] and [Styled JSX][styled-jsx]. But rather than burden your users with slow load times, Astro has something better: **built-in scoped styles.**
```html
```
_Note: all the examples here use `lang="scss"` which is a great convenience for nesting, and sharing [colors and variables][sass-use], but itâs entirely optional and you may use normal CSS if you wish._
That `.btn` class is scoped within that component, and wonât leak out. It means that you can **focus on styling and not naming.** Local-first approach fits in very well with Astroâs ESM-powered design, favoring encapsulation and reusability over global scope. While this is a simple example, it should be noted that **this scales incredibly well.** And if you need to share common values between components, [Sassâ module system][sass-use] also gets our recommendation for being easy to use, and a great fit with component-first design.
---
By contrast, Astro does allow global styles via the `:global()` escape hatch, however, this should be avoided if possible. To illustrate this: say you used your button in a `` component, and you wanted to style it differently there. You might be tempted to have something like:
```jsx
---
import Button from './Button.astro';
---
```
This is undesirable because now `