Playground

Getting started

Install, import and render your first component.

Install

Monoline is two packages: @monoline/css (plain CSS, works anywhere) and @monoline/react (React components that render the same classes). React 18 or newer is a peer dependency.

bash
npm install @monoline/react @monoline/css

A minimal React app

Import the stylesheet once at your entry point, then import components by name.

main.tsx
import {createRoot} from 'react-dom/client';
import '@monoline/css';
import {Button} from '@monoline/react';

createRoot(document.getElementById('root')!).render(
  <Button>Save</Button>
);

Set a theme and accent on <html> (see Theming). Without attributes you get the warm theme with the orange accent.

index.html
<html lang="en" data-theme="warm" data-accent="orange">

Load only the CSS you use

import '@monoline/css' is the easy start: one file with every component (about 18 KB gzip). Most apps use a fraction of it. The better path is the core plus one small file per component you use. Each bundle already contains the styles of the parts it renders (a Form brings Field and Button), and every file is wrapped in a cascade layer, so order does not matter between components.

main.tsx
import '@monoline/css/core.css';              // tokens, themes, accents, base: always
import '@monoline/css/components/button.css';
import '@monoline/css/components/dialog.css';
import '@monoline/css/components/card.css';

Each component page shows its import line under Details. In code, import {styles} from '@monoline/react' is a map from component name to its file, for tooling and for checking what you load (styles.core, styles.button). Measured, minified and gzipped (npm run size):

You loadCSS gzip
everything: @monoline/css18.3 KB
core only3.4 KB
core + Button3.8 KB
core + the 11 components of the landing example6.2 KB
core + the 21 components of the dashboard example10.3 KB

The three example apps in examples/ use this path. Without a bundler, link core.css and the component files from node_modules/@monoline/css/dist/ in the same way, or copy the source files with the CLI.

If you write your own CSS, it wins over Monoline without specificity tricks, because Monoline lives in @layer monoline.* and unlayered CSS beats any layer. Your .card or .badge rules apply as written.

Spacing between blocks

A Field, Heading, Text or Button has no outer margin, so siblings in a plain div touch. Form and Stack space their children. Card and Dialog content and .prose do it for you (--flow, default --s4; a heading after a block gets 1.5 steps); Drawer and Alert are flex and grid containers with a gap of their own. Anywhere else, add the flow class to the container, and set --flow (or flow-s2 to flow-s8) to change the step.

Page.tsx
<section className="flow">
  <Heading level={2}>Billing</Heading>
  <Text>Your plan renews on the 1st.</Text>
  <Button>Update card</Button>
</section>

Plain CSS, no React

Every component is a set of class names. Link the stylesheet and write HTML.

index.html
<link rel="stylesheet" href="node_modules/@monoline/css/dist/monoline.css">

<html data-theme="warm" data-accent="green">
  <button class="btn btn-solid">Save</button>
  <button class="btn btn-line">Cancel</button>
</html>

An optional script, @monoline/css/monoline.js, adds behaviour through data attributes: data-ml-theme and data-ml-accent buttons, [data-tabs], data-dialog-open, data-drawer-open, data-toast and data-copy.

Or copy the source

If you would rather own the component code, use the CLI (next guide) to copy components into your project.