Set up Master CSS in Astro

Guide to setting up Master CSS in your Astro project.

Master CSS Static Extraction integrates build tools to scan project source code, extract class names, generate CSS rules, and write them into a virtual CSS module.

Zero runtime

Generate virtual CSS modules at build time


Scan all source code to extract class names

Cross-page caching

Download the CSS bundle for all pages at once

Quick start

Clone the example

Copy-paste the following commands to quickly start using the

You can skip all installation steps.

npx degit master-co/css/examples/astro-with-static-extraction my-project
cd my-project
npm install @master/css-extractor.vite@beta
npm install
npm run dev


Create a project

If you don't have a Astro project, create one first. It's recommended to refer to Getting Started - Astro.

npm create astro@latest project
cd project

Install Master CSS

Install the Master CSS extractor into your project via package managers.

npm install @master/css-extractor.vite@beta

Initialize configuration file

Run npx mcss init to create a configuration file master.css.ts.

npx mcss init

Set up CSS extractor

Add a CSSExtractorPlugin to vite plugins in nuxt.config.ts.

import { CSSExtractorPlugin } from '@master/css-extractor.vite'
export default defineNuxtConfig({
vite: {
plugins: [

Import virtual CSS module

Import the virtual CSS module .virtual/master.css into the src/layouts/Layout.astro.

export interface Props {
title: string;
import ".virtual/master.css";
const { title } = Astro.props;

Launch server

Run npm run dev to start your Astro development server

npm run dev

Start using Master CSS

Now style your first element using Master CSS syntax!

import Layout from '../layouts/Layout.astro';
<Layout title="Welcome to Astro.">
<h1 class="font:40 font:heavy italic m:50 text:center">Hello World</h1>

Open your browser to watch the changes.


Hello World

MIT License © Aoyue Design LLC.