# Installing Master CSS

Choose a framework integration, check CDN availability, or generate a stylesheet with the CLI.

Choose the setup that fits your project: [Integrations](#integrations) connects Master CSS to a framework or build tool, and [CLI](#cli) generates a stylesheet for projects without a bundler. [CDN](#cdn) provides a plain HTML setup for the default preset.

<a id="integrations"></a>

## Integrations

Use an integration for an existing app. Static rendering is the default: the build finds complete class names in source and delivers a stylesheet to the browser. Choose your framework for its setup files and instructions, or use the automatic installer below.

**Frameworks**

- [React](/guide/installation/vite#react)
- [Vue.js](/guide/installation/vite#vue)
- [SvelteKit](/guide/installation/svelte)
- [Next.js](/guide/installation/nextjs)
- [Nuxt.js](/guide/installation/nuxtjs)
- [Astro](/guide/installation/astro)
- [Angular](/guide/installation/angular)
- [React Router](/guide/installation/vite#react-router)
- [TanStack Start](/guide/installation/vite#tanstack-start)
- [Lit](/guide/installation/lit)

**Build tools**

- [Vite](/guide/installation/vite)
- [Webpack](/guide/installation/webpack)
- [Rspack](/guide/installation/webpack#rspack)
- [Rsbuild](/guide/installation/webpack#rsbuild)

**Server-rendered apps**

- [Express](/guide/installation/server-rendered#express)
- [PHP](/guide/installation/server-rendered#php)
- [Laravel](/guide/installation/server-rendered#laravel)
- [Rails](/guide/installation/server-rendered#rails)
- [ASP.NET Core](/guide/installation/server-rendered#aspnet-core)
- [Blazor](/guide/installation/server-rendered#blazor)
- [WordPress](/guide/installation/server-rendered#wordpress)
- [Shopify](/guide/installation/server-rendered#shopify)

**Development tools**

- [Storybook](/guide/installation/storybook)
- [Visual Studio Code](/guide/language-service#set-up-vs-code)

The four rendering modes are `static`, `prerender`, `runtime`, and `progressive`. See [rendering support by integration](/guide/rendering-modes#integration-support) for the options available to your framework.

<a id="set-up-with-an-ai-agent"></a>

### Set up with an AI agent

A coding agent can run this setup for you. Paste the prompt below into the agent from the app's root directory. It inspects the project and asks you for the rendering mode, the setup scope and whether existing styles move to Master CSS before changing files, then runs the installer, registers the MCP server and checks the first style in the browser.

Set up Master CSS

```text
You are working in an existing web application. Set up Master CSS end to end.

Documentation: https://css.master.co/guide/installation

First inspect the project before editing: package manager, Node.js version, framework and build tool, the existing CSS entry and where it is imported, the current styling system, ESLint setup, dev/build/test commands, and agent guidance files such as AGENTS.md.

Before editing, ask me these and wait for the answers. Do not choose them yourself:
- Rendering mode: static (the default; build-time CSS from complete class names), prerender, runtime, or progressive. See https://css.master.co/guide/rendering-modes.
- Setup scope: the full setup (ESLint config, MCP package, AGENTS.md guidance) or --minimal (framework integration only).
- Existing styling: if the project uses Tailwind CSS or another styling system, whether to migrate it to Master CSS (the default) or keep it in place. See https://css.master.co/guide/migration.

Then adopt Master CSS conservatively:
1. Use Node.js 24 or later and run every command from the app root, where its package.json lives.
2. Preview the plan: npm create @master/css@latest -- --yes --dry-run (add --framework <name> if detection is wrong, and --minimal if I chose it). Show me the plan.
3. Run the same command without --dry-run. It installs every Master CSS package at the installer's version; keep them on that one version.
4. Finish any framework-specific steps the installer prints. Confirm the app imports the CSS entry that contains @import '@master/css'; installing the packages alone does not load it.
5. If I chose to migrate, convert the existing styling to Master CSS by following the matching guide under https://css.master.co/guide/migration (Tailwind CSS: https://css.master.co/guide/migration/tailwindcss), keep the rendered result unchanged, and remove the old styling dependencies only after nothing uses them. If I chose to keep it, leave the existing styling system in place.
6. Register the MCP server with this agent's native registration path and an absolute root, using the project's installed package: npx @master/css-mcp --root <absolute app path>. If the project has no @master/css-mcp, install it as a dev dependency at the same version as @master/css first. Then install the skill: npx skills add master-co/css --skill master-css.
7. Add the project's actual validation commands below the generated ## Master CSS block in AGENTS.md.
8. Preserve the existing architecture and avoid unrelated refactors.
9. Verify: start the dev server and render <p class="w-fit mx-auto my(0) p-md r-md b(1) b-solid b-line-divider bg-surface-raised text-sm fg-text-strong">Hello World</p> (className in JSX). Confirm 1rem of padding, change p-md to p-lg and confirm 1.5rem. Then run the project's lint, build and tests. With MCP, call mastercss_workspace_info and mastercss_setup_audit and confirm the root and stylesheet entries belong to this app.

When finished, summarize the changed files, the rendering mode and options chosen, behavior intentionally left unchanged, the validation results, and anything not verified in a browser.
```

<a id="installation"></a>

### Before you start

Use Node.js 24 or later and open the app's root directory, where its `package.json` lives. The installer updates an existing project; it does not create a framework starter. Your app should already have a working development command.

<a id="package-availability"></a>

### Package versions

Use the version shown in this documentation for the installer, integrations and other Master CSS packages. Keep these packages on the same version when installing or upgrading them manually. A package that exists under another npm tag does not establish compatibility with this setup.

For a local runtime evaluation, use the [built-checkout CDN example](#cdn). Keep its script, compiled program and base stylesheet from the same build.

For manual setup or framework-specific files, use the [integration guides](/guide/installation#integrations). If your project has no matching build integration, follow the [standalone CLI setup](/guide/installation#cli).

<a id="add-master-css"></a>

### Add Master CSS

Run the installer from the project root. It detects the framework and package manager, updates the setup files, and installs Master CSS packages that match the installer's version.

```bash
npm create @master/css@2.1.8 -- --yes
```

**Review or limit the setup**

`--yes` accepts the recommended defaults. These include the core integration, ESLint configuration, the MCP package, and Master CSS guidance in `AGENTS.md`. The printed MCP registration and skill-installation commands are optional next steps for your coding tools; the installer does not run them.

Add `--dry-run` to inspect the plan without changing project files or installing the planned dependencies:

```bash
npm create @master/css@2.1.8 -- --yes --dry-run
```

For only the core framework setup, add `--minimal` to the install command. It skips the ESLint, MCP and agent-guidance additions. If you prefer to install dependencies yourself, add `--no-install`.

<a id="check-the-stylesheet-connection"></a>

### Check the stylesheet connection

Read the setup summary and finish any framework-specific instructions it prints. Some integrations need a follow-up setup command or a separate CSS generation process; see your [framework's guide](/guide/installation#integrations) for those steps.

Confirm that your app loads the stylesheet the installer created or updated. That stylesheet should contain:

```css
@import '@master/css';
```

For example, a plain Vite app commonly imports `./style.css` from `src/main.js`. The CSS file's name and import location depend on the framework. Installing the packages alone does not load the stylesheet into your page.

**Connect your source to the page**

- **Source.** A complete class such as p-md appears in a source file the integration scans. The app stylesheet imports @master/css to supply the preset definitions.
- **Build integration.** The two source artifacts feed the configured integration, which generates CSS for the recognized classes. The installer configures this connection; the integration does the ongoing development and build work.
- **Page.** The app loads its stylesheet so the resulting CSS reaches the browser. The p-md rule applies 1rem of padding with the preset. Package installation alone does not establish the stylesheet import.

The integration reads class names from source and definitions from your stylesheet. Your app must load that stylesheet for the resulting CSS to reach the page.

<a id="start-using-master-css"></a>

### Start using Master CSS

Start or restart your app's development server with its existing command, such as `npm run dev`. Put this markup in a visible page or component. In JSX, write `className` in place of `class`.

```html
<p class="w-fit mx-auto my(0) p-md r-md b(1) b-solid b-line-divider bg-surface-raised text-sm fg-text-strong">
Hello World
</p>
```

```css disclosure=generated-css
@layer theme{:root,:host{--color-zinc-90:oklch(24.6% .0022 265);--color-zinc-100:oklch(15% .0016 265)}:root,:host{--color-surface-raised:light-dark(var(--color-white), var(--color-zinc-90));--color-line-divider:light-dark(oklch(0% 0 none / .12), oklch(100% 0 none / .12));--color-text-strong:light-dark(var(--color-zinc-100), var(--color-white))}:root,:host{--color-white:oklch(100% 0 none)}:root,:host{--font-size-sm:.875rem;--text-sm:var(--font-size-sm);--text-sm--line-height:1.5;--text-sm--letter-spacing:0;--radius-md:.375rem;--spacing-md:1rem}}@layer utilities{.text-sm{font-size:var(--text-sm);line-height:var(--text-sm--line-height, normal);letter-spacing:var(--text-sm--letter-spacing, normal)}.bg-surface-raised{background-color:var(--color-surface-raised)}.b-line-divider{border-color:var(--color-line-divider)}.r-md{border-radius:var(--radius-md)}.b-solid{border-style:solid}.b\(1\){border-width:calc(1 * 1px)}.fg-text-strong{color:var(--color-text-strong)}.my\(0\){margin-block:calc(0 * 1px)}.mx-auto{margin-inline:auto}.p-md{padding:var(--spacing-md)}.w-fit{width:fit-content}}
```

With the preset, p-md adds 1rem of padding on every side of the text.

You should see text inside a small bordered surface. Change `p-md` to `p-lg` and save: its padding should grow from `1rem` to `1.5rem` on all four sides. This checks that changes in your source reach the page, beyond the installer completing successfully.

**Verify the whole path with one small edit**

A source edit changes p-md to p-lg, the compiled padding changes, and the browser box visibly grows.

A successful install is only the first step. Changing the class checks discovery, generation and stylesheet delivery together.

<a id="cdn"></a>

## CDN

A CDN installation runs Master CSS in the browser without a build tool. It suits a plain HTML prototype; generated styles depend on JavaScript. Use an integration or the CLI when the page needs styles without JavaScript.

Keep the runtime script, compiled program and preset stylesheet on the same Master CSS version. The template uses matching versioned URLs. The same [package version requirement](#package-availability) applies to [Integrations](#integrations) and [CLI](#cli).

Save this template as `index.html`:

```html name=index.html
<!DOCTYPE html>
<html lang="en" hidden>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="preload" as="style" href="https://cdn.master.co/css-preset@2.1.8/src/base.css">
  <link rel="preload" as="script" href="https://cdn.master.co/css-runtime@2.1.8">
  <link rel="preload" as="fetch" crossorigin href="https://cdn.jsdelivr.net/npm/@master/css-runtime@2.1.8/dist/default-program.bin">
  <link rel="stylesheet" href="https://cdn.master.co/css-preset@2.1.8/src/base.css">
  <script src="https://cdn.master.co/css-runtime@2.1.8"></script>
</head>

<body>
  <h1 class="m-2xl italic font-5xl font-heavy fg-text-strong">Hello World</h1>
</body>

</html>
```

The heading should have a `3rem` margin, a `2.5rem` italic font at weight `900`, and the preset's strong text color. Change `font-5xl` to `font-6xl`: the text grows to `3rem`. The runtime also observes class changes made by JavaScript.

The stylesheet supplies the base rules and layer order. The classic script starts automatically, loads its matching compiled program, then generates the initial classes after the document finishes parsing. It removes `hidden` when those rules are ready. The three preload links start the stylesheet, script, and program requests early; the binary uses `as="fetch" crossorigin` because the runtime fetches data, not a module. The binary preload and runtime fetch use the jsDelivr destination directly because the Master CDN redirect does not carry CORS headers. The CDN setup uses the default preset; use an integration to compile custom `@theme` or `@utility` definitions.

**Try a local build**

From a built checkout, copy `packages/preset/src/base.css`, `packages/runtime/dist/global.min.js`, and `packages/runtime/dist/default-program.bin` into one directory beside `index.html`. Keep the script and program from the same build.

Replace both stylesheet URLs with `./base.css`, both script URLs with `./global.min.js`, and the program preload URL with `./default-program.bin`. Serve the directory over HTTP and open `index.html`. The runtime resolves the program beside an explicit script file; at a Master CDN or jsDelivr npm package entry, it resolves `dist/default-program.bin` inside that package.

`hidden` is optional. It prevents an unstyled first paint; handled program-loading errors and the runtime's three-second startup timeout reveal the content. If JavaScript is disabled or the script itself cannot download, it cannot remove the attribute. Omit `hidden` when content must stay readable in those cases, or deliver static CSS.

For a Content Security Policy, allow the CDN and its jsDelivr redirect target for scripts, stylesheet loading and program fetching (`connect-src`), and allow the runtime's generated stylesheet. No Wasm is fetched. See [Runtime rendering](/guide/rendering-modes#runtime-rendering) for loading and hydration behavior.

<a id="cli"></a>

## CLI

Generate a static stylesheet from your HTML without adding a bundler. The CLI scans complete class names and writes CSS that you load with a normal stylesheet link. Use this setup when your project does not have a matching [framework integration](/guide/installation#integrations).

<a id="install-master-css"></a>

### Install Master CSS

Install Master CSS [CLI](https://www.npmjs.com/package/@master/css-cli) as a development dependency.

```bash
npm install -D @master/css-cli@2.1.8
```

<a id="create-your-css-entry"></a>

### Create your CSS entry

Create a stylesheet that imports the default Master CSS entry.

```css name=main.css
@import "@master/css";
```

<a id="run-the-build-command"></a>

### Run the build command

Run the command to scan sources and write `master.css`.

```bash
npx @master/css-cli generate "index.html" --output master.css --watch
```

<a id="load-the-generated-stylesheet"></a>

### Load the generated stylesheet

Save the document below as `index.html`. The watcher generates `master.css` from its class names. Serve the directory and open the page to see the styled paragraph.

```html name=index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="./master.css"> <!-- [!code highlight] -->
</head>
<body>
  <p id="master-check" class="w-fit m(0) p-md b-solid b(1) b-line-divider r-md text-sm font-regular bg-surface-raised fg-text-strong">Hello World</p>
</body>
</html>
```

<a id="build-for-deployment"></a>

### Build for deployment

The watch command stays running and updates the output when a selected source changes. For a production build, omit `--watch` so the command writes its output and exits:

```bash
npx @master/css-cli generate "index.html" --output master.css
```

Deploy `index.html`, `master.css` and the neighboring CSS assets referenced by the generated stylesheet. Preserve their relative paths: copying only `master.css` can leave its imported styles missing. Keep each generated asset set together when publishing a new build.

Load the deployed page and check that every stylesheet request succeeds. The paragraph should keep its generated padding, border and surface colors with JavaScript disabled. [Scanning class names](/guide/scanning-and-pruning) explains how to include sources outside the ordinary application scope.

<a id="if-the-style-does-not-appear"></a>

## If the style does not appear

Check that the page renders the markup you edited and loads the app stylesheet. Then check that the build integration is enabled and scans that source file. Keep class names complete, as in `p-lg`; constructing them from fragments such as `p-${size}` prevents a static scan from seeing the final class.

If the installer reports an unrecognized framework or incomplete setup, follow the matching [integration guide](/guide/installation#integrations) or the [CLI guide](/guide/installation#cli). For files outside the normal application scope, see [Scanning class names](/guide/scanning-and-pruning).

Once the spacing change works, continue with the [Syntax tutorial](/guide/syntax-tutorial) to build a card with interaction states and responsive conditions.
