# Minium CSS
Minium: the minimum CSS and HTML to build anything.
Minium is a semantic-first CSS library that makes ordinary HTML look good, then adds class-light layouts and components for building real interfaces.
## Minium CSS install notes
1. When the package is published, install it with `npm install minium-css`.
2. Until then, build from the repository and load the built stylesheet from `dist/minium.css`.
3. Import font files from `dist/fonts`.
4. Do not assume Tailwind, Bootstrap, or JavaScript component plugins exist. Minium CSS is plain CSS.
5. Customize the system primarily through CSS custom properties, especially the semantic tokens in the theme layer.
6. The library is built around semantic HTML first, layouts second, components/modifiers third, utilities fourth, and project classes for anything else.
## How HTML feels with Minium
Minium minimizes both the CSS shipped by the library and the HTML written by the user. The library carries the cost so users write less. Reach for tools in this order:
1. **Semantic HTML, no classes.** `main`, `article`, `h1`, `p`, `ul`, `table`, `form`, `button`, `dialog`, `details` already look right. Top-level `header` and `footer` as direct children of `body` get automatic page-shell styling.
2. **One layout or component class.** `.cluster`, `.grid`, `.sidebar`, `.card`, `.alert` carry their own composition and visual defaults.
3. **A small modifier.** `.primary`, `.danger`, `.small`, `.secondary`, `.slim` — short words that tweak the layout/component.
4. **A token-bounded utility.** `gap-l`, `p-m`, `radius-s`, `fg-muted` adjust one variable at a time. Preferred over `style="--var: ..."`.
5. **A project class.** Anything specific to your project (`.hero`, `.pricing-comparison`, `.product-card`) lives in your own `@layer project` CSS.
## Architecture
Minium uses cascade layers to control specificity. The order is:
```
@layer tokens, theme, reset, base, layout, components, project, utilities;
```
- `tokens` — raw palette (Radix color scales).
- `theme` — semantic roles, type scale, spacing scale, semantic colors, shadows, radii.
- `reset` — foundational reset rules.
- `base` — element defaults (the "no-class HTML looks good" layer).
- `layout` — composition primitives. Structural only, no visual styling.
- `components` — curated blocks and objects (card, badge, alert, modal, dropdown, tabs, accordion, avatar, icon, tooltip, etc.).
- `project` — your own classes. Not shipped by the library.
- `utilities` — token-bounded shortcuts. Escape hatches, not building blocks.
## Minium CSS usage rules
1. Prefer semantic HTML before adding classes. Many patterns are intentionally styled through native elements alone.
2. Use documented layout classes for composition: `.flow`, `.cluster`, `.container`, `.grid`, `.repel`, `.switcher`, `.sidebar`, and `.frame`.
3. Use documented component classes only where they exist, such as `.card`, `.alert`, `.badge`, `.pill`, `.avatar`, `.icon`, `.dropdown`, and `.skeleton`.
4. Use semantic state and structure attributes where the library expects them: `role="group"`, `aria-current="page"`, `aria-invalid`, `aria-busy`, `aria-disabled`, and native attributes like `open`, `disabled`, `readonly`, `multiple`, and `popover`. Tooltips use `data-tooltip` and `data-placement` (see Tooltip).
5. Do not invent large component APIs. If a pattern is not described here, build it from semantic HTML plus layout primitives, and a small amount of project CSS.
6. Prefer theme-token overrides over component-specific overrides. Change shared variables first, then override a specific component only if necessary.
7. Prefer token-bounded utility classes (`gap-l`, `p-m`, `bg-raised`, `radius-s`) over inline `style="--var: ..."`.
8. Automatic vertical rhythm already exists in all components. Avoid stacking extra margin utilities or wrapping everything in `.flow` without reason.
9. When a link should behave visually like a button, use `role="button"` and button modifiers rather than styling a plain text link as a pseudo-button.
10. For forms, use the native HTML control pattern first. Minium CSS styles labels, helper text, validation state, and grouped controls around semantic form markup.
11. For navigation, breadcrumbs, pagination, dropdown menus, accordions, and modals, prefer the native HTML structures described below instead of custom JavaScript widgets.
## Customization model
1. Minium CSS is configured through custom properties.
2. The most important token groups are:
`--size-*` for type scale,
`--space-*` and `--gap` for spacing,
`--flow-space*` for vertical rhythm,
`--content-width` and `--main-width` for widths,
`--border-radius-*`, `--border-width`, and `--shadow-*` for shape and depth,
`--color-*` for semantic colors.
3. Most components consume semantic tokens instead of hard-coded values. If you change a token like `--color-primary`, buttons, links, alerts, badges, and focus styles update together.
4. Raw palette values can be Radix-style color scales, but agents should think in semantic roles such as text, surface, border, primary, accent, warning, success, and danger.
5. If the design only needs a global shift in tone, density, spacing, width, radii, or typography, modify tokens in `theme.css` instead of writing new component CSS.
## Adjusting one element with utilities
Token-bounded utility classes are the preferred way to tune one element. They map directly to a design token, so they stay inside the system. Use them instead of `style="--var: ..."` for one-offs.
Rules:
1. Reach for a utility before adding inline `style`.
2. Every utility is bounded to a token — there is no `gap-37px`. If you need an arbitrary value, use `style="--var: ..."` for a one-off, or define a project class for repeated patterns.
3. If you stack four or more utilities on the same element, promote it to a project class named for its intent.
4. Component-scoped escape valves (like `--sidebar-target-width`, `--switcher-breakpoint`, `--grid-min-size`, `--card-padding`, `--avatar-size`, `--n`/`--d` on `.frame`, alignment vars) do not have utility equivalents — for those, use `style="--var: ..."` or a project class.
Example: tighten and center a cluster
```html
DocsAPIGuides
```
Example: remove vertical spacing in a single flow container
```html
Compact panel
No gap between direct children.
```
Example: make grid items wider (no utility for `--grid-min-size`)
```html
OneTwoThree
```
Example: reduce card padding (no utility for `--card-padding`)
```html
Compact card
Same component, denser interior spacing.
```
Example: custom avatar size (no utility for `--avatar-size`)
```html
KC
```
Example: tune the sidebar split (no utility for `--sidebar-target-width`)
```html
AB
Alex Brown
Profile summary text.
```
## Project-specific CSS in `project.css`
Minium CSS is intentionally not meant to contain every possible app block or marketing pattern. When a UI need is specific to one product or repeats as a product-level pattern, put it in a project stylesheet such as `project.css`. Wrap all project.css code in `@layer project {...}`.
Use `project.css` for:
1. App-specific blocks like `.hero`, `.pricing-comparison`, `.dashboard-stat`, `.product-card`, or `.site-header`.
2. Small wrappers around Minium primitives where your project needs a named pattern.
3. Repeated utility stacks that should become a reusable project-level class.
4. Brand-specific presentation that should not become part of the shared Minium API.
Do not use `project.css` for:
1. Rewriting core Minium element defaults unless you truly want to replace the library behavior.
2. Creating a second utility framework.
3. Forking shared primitives when a token change or a utility class would solve the problem.
Recommended approach:
1. Start with semantic HTML and Minium defaults.
2. Add one or two Minium layout/component classes as needed.
3. Use token-bounded utilities for one-off adjustments.
4. Use `style="--var: ..."` only for component-scoped escape valves with no utility equivalent.
5. When the pattern becomes project-specific or reusable, promote it into `project.css`.
Example: project-level card variation
```css
.team-card {
--card-padding: var(--space-s);
}
```
```html
KC
Kim Carter
Design systems engineer
```
Example: project hero built from Minium primitives
```css
.hero {
--flow-space: var(--flow-space-loose);
}
```
```html
New release
Build semantic interfaces faster
Minium CSS provides semantic defaults, layouts, and lightweight components.
```
## Integrations
1. Integrations are opt-in stylesheets that target markup produced by third-party tools (for example, Prism.js syntax tokens, Django form widgets). They ship alongside the core stylesheet, not inside it.
2. Each integration is its own file under `dist/integrations/`. Include only the ones you use, after `dist/minium.css`.
3. The core library styles HTML the user authors. Integrations style HTML produced by external tools. Anything tied to a specific JS library or framework belongs in the integration layer, not in core.
4. Integrations may consume core tokens (for example `--color-success` for diff insertions), but core never depends on an integration.
5. Integrations define their own tokens where they need colors that do not map onto Minium's semantic palette (for example syntax categories: `--keyword`, `--string`, `--comment`, `--function`, `--number`, `--constant`, `--operator`, `--tag`, `--punctuation`). They ship with light and dark variants of their own, independent of the main theme palette.
6. Available today: Django forms and Prism syntax highlighting. The Prism integration provides CSS only; the Prism.js library is a separate dependency the user installs.
7. The Django integration supports Django-rendered forms using the standard `{{ form }}` output or `{{ form.as_div }}`, which is Django's default div-based rendering style. It styles `.helptext`, `.errorlist`, and compact spacing inside unclassed field wrapper `div` elements.
## Semantic defaults
1. Plain text content is styled by default. Headings, paragraphs, lists, blockquotes, `hr`, inline text semantics, code, keyboard keys, sample output, captions, and tables all have built-in presentation.
2. Classless `main`, `article`, and `section` receive automatic vertical flow between direct children.
3. A top-level `header` and `footer` as direct children of `body` receive automatic page-shell styling, including sticky-footer behavior.
4. Navigation patterns are identified by context: a `nav` that is a direct child of `header` becomes a navbar, `aside > nav` becomes a side menu, and `aria-label="Breadcrumb"` / `aria-label="Pagination"` style those patterns.
5. Forms and fieldsets already provide consistent vertical rhythm for labels, controls, helper text, and actions.
6. Adding any class to a semantic section opts it out of default classless flow behavior, so you manage spacing manually (with `.flow` or utilities).
## Layout primitives
Layout primitives are small, composable structural classes. They share spacing tokens and nest freely. They are based on Every Layout and CUBE CSS Boilerplate.
### `.flow`
Use `.flow` on a parent to create consistent vertical spacing between direct children.
Default implementation: `.flow > * + * {margin-block-start: 1em}`
Rules:
- Adjust spacing with the `--flow-space` custom property, or use the utilities `.flow-tight`, `.flow-loose`, `.flow-none`.
- Built-in flow already exists on classless `main`, `article`, and `section`, and in all components such as cards, alerts, modals, and menus.
Example:
```html
Title
Intro paragraph.
```
### `.cluster`
Use `.cluster` for horizontal groups that wrap naturally.
Default implementation uses horizontal flex and flex-wrap.
Rules:
- Good for tag rows, button toolbars, filters, compact metadata, and mixed inline controls.
- Children stay in a horizontal row until wrapping is needed.
- Tune gap with `gap-*` utilities.
- Tune alignment with `--cluster-horizontal-alignment` and `--cluster-vertical-alignment` (no utility equivalents).
Example:
```html
```
### `.container`
Use `.container` to center content and apply horizontal gutters and a maximum width.
Rules:
- `.container` is the default page-width wrapper.
- `.container.slim` is for narrower reading width.
- `.container.full` spans the available width without the standard max-width cap.
- Width behavior is driven by `--main-width` and `--content-width`.
Example:
```html
Documentation
Readable long-form content.
```
### `.grid`
Use `.grid` for responsive columns that wrap based on available space.
Default implementation uses `grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr))`.
Rules:
- Good for cards, feature lists, galleries, and evenly distributed blocks.
- Tune gap with `gap-*` utilities.
- Tune item width with `--grid-min-size` and `--grid-placement` (`auto-fill` or `auto-fit`).
- `.halves` and `.thirds` are preset variants for common column patterns. Halves give two columns and thirds give three when there is enough space.
Example:
```html
OneTwoThree
```
### `.repel`
Use `.repel` when content should push to opposite sides of a row.
Default implementation is horizontal flex with `justify-content: space-between`.
Rules:
- Good for action bars, list item controls, and summary rows.
- For page header navigation rows, prefer the semantic navbar pattern: `header > nav > ul`. A `nav` that is a direct child of `header` already behaves like a repelling row.
- Wrapping is supported by default. Add `.nowrap` to prevent wrapping.
- Tune gap with `gap-*` utilities.
- Use `--repel-vertical-alignment` for cross-axis alignment.
Example:
```html
```
### `.switcher`
Use `.switcher` for item groups that sit in a row when there is space and stack vertically when there is not.
Rules:
- Good for pricing tiers, summaries, comparison blocks, and mixed promo cards.
- Tune gap with `gap-*` utilities.
- Tune the stack threshold with `--switcher-breakpoint` (no utility equivalent).
- Tune cross-axis alignment with `--switcher-vertical-alignment`.
Example:
```html
StarterTeamEnterprise
```
### `.sidebar`
Use `.sidebar` when one item should act like a narrow side column and the other like flexible content.
Rules:
- Good for media-object rows, profile summaries, avatar/content layouts, and documentation sidebars.
- Place exactly two children: the first is the sidebar, the second is the main content.
- Tune gap with `gap-*` utilities.
- Tune the side column with `--sidebar-target-width` and the stack threshold with `--sidebar-content-min-width` (no utility equivalents).
- Modifiers:
- `.reversed` — place the sidebar on the right.
- `.media` — lock the first child to its content size (avatar, icon, thumbnail beside text). This creates the typical media object layout.
- `.no-stretch` — do not stretch children to the same height.
Example:
```html
AB
Alex Brown
Design systems engineer.
```
### `.frame`
Use `.frame` to keep media inside a fixed aspect ratio while cropping overflow cleanly.
Rules:
- Wrap a single `` or `