
- Astro JS Architecture
- Astro JS - Islands
- Astro JS - Islands Architecture
- Astro JS Routing
- Astro JS - Routing
- Astro JS - Dynamic Routing
- Astro JS - Redirecting Routes
- Astro JS - i18n Routing
- Astro JS Build UI
- Astro JS - Components
- Astro JS - Slots
- Astro JS - Layouts
- Astro JS - Fonts
- Astro JS - Scripts
- Astro JS Styling and CSS
- Astro JS - Styling
- Astro JS - CSS Cascading Order
- Astro JS - CSS Integration
- Astro JS Advanced Topics
- Astro JS - Prefetching
- Astro JS - Middleware
- Astro JS - Endpoints
- Astro JS - View Transition
Astro JS - CSS Integration
CSS in Astro
Astro framework have inbuilt support for CSS. You can use internal CSS, external CSS, and CSS preprocessors in Astro. In the last chapter, we discussed how to use the types of CSS in Astro project. In this chapter, we will discuss how to integrate Astro with other technologies like Tailwind CSS, and CSS preprocessors.
Astro Tailwind CSS Integration
Astro uses vite plugin to support Tailwind CSS. You can use Tailwind CSS in Astro by installing the plugin. The following steps show how to integrate Tailwind CSS in Astro:
Step 1: Install Tailwind CSS
First, you need to install Tailwind CSS in your Astro project. You can install Tailwind CSS using the following command:
>> npx astro add tailwind
Step 2: Import Tailwind CSS
After installing Tailwind CSS, you need to import it in your Astro project. You can import Tailwind CSS in your Astro project using the following command:
// src/styles/global.css @tailwind base;
Step 3: Use Tailwind CSS
After importing Tailwind CSS, you can use it in your Astro project. You can use Tailwind CSS classes in your Astro project as shown below:
// src/pages/index.astro --- import "../styles/global.css"; --- <style> .container { @apply bg-blue-500 text-white p-4; } </style>
CSS Preprocessors in Astro
Astro supports CSS preprocessors like Sass, Less, and Stylus. You can use CSS preprocessors in Astro by installing the plugin. The section below shows how to install and use different CSS preprocessors in Astro.
Astro Sass Integration
To use Sass in Astro, you need to install the Sass plugin. Run the following command to install the Sass plugin in Astro:
>> npm install sass
Now, to use SASS keep "scss" as valve for lang attribute in <style> tag. Let's see an example.
// src/pages/index.astro <style lang="scss"> $color: blue; .container { background-color: $color; } </style>
Astro Stylus Integration
To use Stylus in Astro, you need to install the Stylus plugin. Run the following command to install the Stylus plugin in Astro:
>> npm install stylus
Now, to use Stylus keep "stylus" as valve for lang attribute in <style> tag. Let's see an example.
// src/pages/index.astro <style lang="stylus"> $color = blue; .container { background-color: $color; } </style>
Astro Less Integration
To use Less in Astro, you need to install the Less plugin. Run the following command to install the Less plugin in Astro:
>> npm install less
Now, to use Less keep "less" as valve for lang attribute in <style> tag. Let's see an example.
// src/pages/index.astro <style lang="less"> @color: blue; .container { background-color: @color; } </style>