Installation

Set up Master CSS in Next.js

Next.js

Guide to setting up Master CSS in your Next.js 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 ~17KB transfer cost

Fully automatic

Capture any program-generated class names

CSS lifecycle

Generated on-demand and frees memory when not in use


Quick start

Clone the example

Copy-paste the commands to quickly start using the https://nextjs.rr.rc.css.master.co example.

You can skip all installation steps.

npm create @master/css@rc project --example next.js-with-runtime-rendering
cd project
npm run dev

Installation

Create a Next.js project

If you don't have a Next.js project, create one first. It's recommended to refer to Create Next App.

npm create next-app --app --ts
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 React into your project via package managers.

npm install @master/css.react@rc

Set up CSS runtime engine

Register Master CSS with official CSSRuntimeProvider and provide instance context.

  1. Register the CSSRuntimeProvider
  2. Import the config ../master.css
  3. Add display: 'none' in <html> to avoid FOUC
import './globals.css'
import CSSRuntimeProvider from '@master/css.react'
import config from '../master.css'
export const metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" style={{ display: 'none' }}>
<body>
<CSSRuntimeProvider config={config}>
{children}
</CSSRuntimeProvider>
</body>
</html>
)
}

Launch server

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

npm run dev

Start using Master CSS

Now style your first element using Master CSS syntax!

export default function Home() {
return (
<h1 className="font:40 font:heavy italic m:12x text:center">Hello World</h1>
)
}

Open your browser to watch the changes.

localhost:3000

Hello World

© Aoyue Design LLC.