Set up Master CSS in Astro
Guide to setting up Master CSS in your Astro project.
Master CSS Runtime Rendering observes changes in DOM class names at browser runtime, generates corresponding CSS rules, and injects them into the running style sheet.
Fixed style cost
All features work out of the box with ~16KB transfer cost
Fully automatic
Capture any program-generated class names
CSS lifecycle
CSS is generated on demand and frees memory when not in use
Quick start
Clone the example
Copy-paste the following commands to quickly start using the astro.rr.beta.css.master.co.
You can skip all installation steps.
npx degit master-co/css/examples/astro-with-runtime-rendering my-projectcd my-projectnpm install @master/css@betanpm installnpm run dev
Installation
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 projectcd project
Install Master CSS
Install Master CSS into your project via package managers.
npm install @master/css@beta
Initialize configuration file
Run npx mcss init
to create a configuration file master.css.ts.
npx mcss init
Set up CSS runtime engine
Modify src/layouts/Layout.astro
:
- Import your custom configuration
master.css.ts
- Initialize the runtime engine
- Add
display: none
to<html>
to avoid FOUC
<html style="display: none"> <head> … <script> import { initRuntime } from "@master/css"; import config from "../../master.css"; initRuntime(config); </script> </head> …<html>
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."> <main> <h1 class="font:40 font:heavy italic m:50 text:center">Hello World</h1> </main></Layout>
Open your browser to watch the changes.