Set up Master CSS in Nuxt.js


Guide to setting up Master CSS in your Nuxt.js project.

Master CSS Progressive Rendering scans the rendered HTML ahead of time, server-side or at build time, generates the corresponding CSS rules for each page, and lazy loads the runtime engine to keep track of the dynamic class names.

Faster page loading

Non-rendering-blocking internal CSS and lazy loading

Fully automatic

Capture any program-generated class names

CSS encapsulation

Only ship the page-used CSS instead of the whole site

Quick start

Clone the example

Copy-paste the commands to quickly start using the example.

You can skip all installation steps.

npm create @master/css@rc project --example nuxt.js
cd project
npm run dev


Create a project

If you don't have a Nuxt.js project, create one first. It's recommended to refer to Get started with Nuxt.js.

npx nuxi@latest init project
cd project

Initialize configuration file

Run npm create @master/css@rc to create a configuration file master.css.ts.

npm create @master/css@rc

Install Master CSS

Install Master CSS Nuxt into your project via package managers.

npm install @master/css.nuxt@rc

Set up CSS runtime engine

  1. Dynamic import('@master/css.vue')
  2. Dynamic import('../master.css')

@master/css.vue and master.css.ts will not be included in the page's initial JavaScript bundle.

<script setup lang="ts">
import { defineAsyncComponent } from 'vue'
const CSSRuntimeProvider = defineAsyncComponent(async () => (await import('@master/css.vue')).CSSRuntimeProvider)
<CSSRuntimeProvider :config="import('./master.css')">

Set up CSS pre-rendering

All CSS rules are pre-rendered and injected into HTML on the server side or at build time.

  • Add a @master/css.nuxt to the nuxt modules
export default defineNuxtConfig({
modules: [

Launch server

Run npm run dev to start your Nuxt.js development server

npm run dev

Start using Master CSS

Now style your first element using Master CSS syntax!

<h1 class="font:40 font:heavy italic m:12x text:center">Hello World</h1>

Open your browser to watch the changes.


Hello World

© Aoyue Design LLC.