ui8px is a framework-agnostic CLI for keeping utility-class projects aligned to a strict 8px design grid. It is intended for Tailwind-style workflows where classes remain explicit in source code, while a policy layer prevents drift, raw palette usage, accidental 4px layout spacing, and repeated unreviewed patterns.
Run without installing:
npx ui8px@latest lint ./...For a full onboarding path, read the docs:
- 101: 8px Grid Design
- Why Tailwind
- CLI API Reference
- Policy Files
- Examples And Use Cases
- Testing, CI, And Publishing
npx ui8px init
npx ui8px init --preset go
npx ui8px lint ./...
npx ui8px lint ./... --ignore .manual .project
npx ui8px lint ./... --learn
npx ui8px validate aria ./...
npx ui8px validate grid --input class-map.json --output class-map.backlog.json
npx ui8px validate patterns ./...
npx ui8px policy reviewLegacy class-map validation is still supported:
npx ui8px --design grid --input class-map.json --output class-map.backlog.jsonui8px init creates:
.ui8px/
policy/
allowed.json
denied.json
scopes.json
groups.json
patterns.json
telemetry/
reports/
If .ui8px is missing, ui8px lint uses bundled defaults. For Go component libraries, use npx ui8px init --preset go to make ui/**, components/**, and utils/**/*.go control scope while examples and views remain strict layout scope.
ui8px reads the current working directory's .gitignore automatically during file scanning, including negation lines (!pattern) that re-include a previously ignored path. Use --ignore to add extra ignored files or folders for a single run:
npx ui8px lint ./... --ignore .manual .project snapshots
npx ui8px validate patterns ./... --ignore fixtures/reference
npx ui8px validate aria ./... --ignore .manualPlace scan paths before --ignore; every non-option value after --ignore is treated as an ignore entry.
Layout scope is strict 8px:
{
"spacing": {
"layout": ["0", "2", "4", "6", "8", "10", "12", "16", "20", "24"],
"control": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "10", "12"]
}
}Examples:
px-2= 8px, allowed in layout.px-4= 16px, allowed in layout.px-3= 12px, denied in layout as fine tuning.px-3is allowed in control scope for buttons, fields, badges, tabs, and other compact primitives.
Scopes are file/folder based:
{
"defaultScope": "layout",
"scopes": [
{
"name": "controls",
"files": ["src/ui/**", "src/components/**", "ui/**", "components/**"],
"spacing": "control"
},
{
"name": "layout",
"files": ["src/views/**", "src/pages/**", "examples/**", "internal/site/views/**"],
"spacing": "layout"
}
]
}npx ui8px lint ./...
npx ui8px lint ./... --ignore .manual .projectSupported source types:
.templand.html: staticclass="..."values..html,.j2,.jinjaand.twigtemplates (Jinja2, MiniJinja, Twig):{# comments #}are skipped; in a class value with{{ … }}/{% … %}the static text and the string literals of the expressions are linted ({{ 'p-4' if x else 'p-2' }}), variables, subscripts (p['Class']) and mapping literals are not..templfiles also go through the Go extractor, soClass: "...",cn(...)/Cn(...), andtempl.Attributes{"class": "..."}are recognised..css:@apply ...;utility lists..go: statictempl.Attributes{"class": "..."}style values, struct fieldsClass: "..."(quoted or backtick strings),utils.Cn(...)/utils.cn(...),Cn(...)/cn(...), mixed literal/dynamiccncalls, staticreturn "..."helper strings, andconst/varstring declarations (including groupedconst ( ... )/var ( ... )blocks) whose values look like utility lists.
Go examples:
return utils.Cn(base, "px-3", props.Class)
return cn("inline-flex items-center", props.Class)return CardProps{Class: "h-8 px-3 text-sm"}const ButtonBase = "inline-flex items-center"
var ButtonPad = `px-3 py-1`
const (
ButtonRow = "flex items-center gap-2"
)return "h-8 px-3 text-sm"The extractor reads only static string literals. It does not execute Go code and ignores dynamic arguments. Each string literal argument to cn / Cn is linted as its own class list, so mutually exclusive conditional branches do not report a false UI8PX004 conflict.
Checked files is the number of supported source files scanned, including files that contained no class lists.
Tailwind v4 inset-ring, inset-ring-*, and inset-shadow-* are ring/shadow utilities, not positional inset-* spacing, so they are not checked against the spacing scale and are not grouped with inset-0. Positional inset-x-* and inset-y-* are treated as their own spacing prefixes.
By default, lint scanning skips built-in transient folders (.git, .ui8px, node_modules, dist, coverage/cache folders) and entries from the local .gitignore.
Example diagnostic:
src/views/landing.templ:24:16 UI8PX001 disallowed utility class "px-3"
Scope: layout
Reason: px-3 is not allowed in layout scope.
Suggestion: use px-2 or px-4
| Code | Command | Meaning | Typical fix |
|---|---|---|---|
UI8PX001 |
lint |
Spacing or size step off the scope's grid (px-3, h-3, size-3, space-y-3, ms-3, p-[13px] in layout scope) |
An even step (px-2, px-4), or move the class into a control |
UI8PX002 |
lint |
Utility not in the allowed policy (leading-5, text-[13px], an unknown modifier) |
Use an allowed utility, or add it to allowed.json on purpose |
UI8PX003 |
lint |
Utility explicitly denied (denied.json), with the reason and a suggestion |
Use the suggested utility |
UI8PX004 |
lint |
Two utilities of one conflict group in one class list (p-2 p-4, text-left text-center) |
Keep one |
UI8PX005 |
lint |
Unknown ui-* semantic class (not in patterns.json) |
Register the pattern or use utilities |
GRID |
validate grid |
A spacing declaration (padding, margin, gap, width, height, inset, …) that does not resolve to the scope's unit: 8px in layout, 4px in control | Fix the class or the CSS value |
Which codes block is the consumer's choice (a gate file such as .ui8px/gate.json); UI8Kit repos block all of UI8PX001–UI8PX005 except UI8PX004, plus GRID.
Spacing prefixes checked by UI8PX001: p* m* gap* space-x/y size w h min-/max-w/h top right bottom left start end inset* ps pe ms me.
z-* is a stacking order, not spacing. Modifiers: hover focus focus-visible active disabled visited dark rtl ltr sm md lg xl 2xl group-hover.
npx ui8px lint ./... --learnLearn mode writes:
.ui8px/telemetry/observed.jsonl
.ui8px/telemetry/proposals.json
Plain lint does not mutate files. --learn records unknown, denied, and disallowed classes so a developer or LLM-assisted workflow can review recurring issues later.
npx ui8px validate patterns ./...This command finds repeated class-list compositions. It normalizes class order, removes internal duplicates, resolves simple conflict groups, and writes:
.ui8px/reports/patterns.json
Example:
Repeated pattern found 14 times:
flex items-center justify-between gap-4 px-6 py-4
Suggested semantic class:
ui-section-header
ui8px does not automatically generate @apply CSS. It reports candidates so semantic ui-* patterns can be reviewed intentionally.
npx ui8px validate aria ./...This command scans source files for static data-ui8kit="..." hooks and common UI8Kit component calls such as @ui8layout.Shell(...), @ui.Accordion(...), and @ui.Tabs(...). It checks that the matching @ui8kit/aria pattern is included in the site bundle. It reads the generated web/static/js/manifest.json when present, otherwise it falls back to package.json ui8kit.aria.
Examples:
data-ui8kit="dialog"requires thedialogpattern.data-ui8kit="sheet"anddata-ui8kit="alertdialog"also requiredialog.data-ui8kit="tabs"requirestabs.@ui8layout.Shell(...)requiresdialogbecause the shell owns a mobile sheet.
Use --package <path> or --manifest <path> when the files live outside the current working directory.
npx ui8px validate grid --input class-map.json --output class-map.backlog.json
npx ui8px validate grid --input dist/app.css --output grid.backlog.json # a compiled stylesheet
npx ui8px validate grid --input class-map.json --output b.json --scope controlIt resolves every spacing declaration to px (calc(var(--spacing) * N) with --spacing-base, rem with --root-font-size,
var(--x, fallback) from the stylesheet's own custom properties or the fallback) and reports values off the scope's unit:
- layout scope: multiples of 8px only;
- control scope: multiples of 4px.
The scope of a class-map entry or a CSS rule is the first scope in scopes.json whose selectors (regular expressions)
match the class or the selector, otherwise the default scope; --scope forces one. A stylesheet input walks nested rules
and at-rules (@media, @layer), so the compiled Tailwind output is checked as the browser gets it, hand-written CSS
values (height: var(--h-button, 40px)) included. Utilities listed in allowed.json (hairlines such as w-px, sr-only)
are policy decisions and are not re-checked.
A policy file can extend a bundled preset and keep only its local deltas:
{ "extends": "ui8kit", "utilities": ["aspect-3/4"] }ui8px init --preset ui8kit writes extends-only files. The ui8kit preset is the one UI8Kit policy:
- spacing: layout = even steps
0–160(multiples of 8px), control =0–16and even steps to160(multiples of 4px); - utilities: the default allowlist plus hairlines (
gap-px,gap-x-px,gap-y-px,p-px,w-px,h-px), fractionsw-1/4…w-3/4,min-h-screen,aspect-4/3,aspect-21/9and the logicaltext-start/text-end(without the physicaltext-left/text-right) andself-start/self-center/self-end/self-stretch, the keyword sizessize-full/max-w-full, and what the kit primitives draw:inset-ringin the semantic colours (border,input,ring,primary,transparent),bg-primary/90/bg-secondary/80(hover of the filled variants),transition-colors,list-none; - denied: raw palette colors, gradients, and
text-left/text-right(UI8PX003, suggestiontext-start/text-end: physical alignment breaks right-to-left pages). A denied utility is denied under any modifier (md:text-left), and the suggestion keeps the modifiers (md:text-start); - conflict groups: the defaults,
textAlignwithtext-start/text-end.
Merge rules: spacing and scopes replace the preset's when given; utilities are added (deny one in denied.json to
remove it); denied utilities, conflict groups and patterns merge by key.
0— no blocking violations.1— lint, grid, or pattern violations found.2— invalid usage or runtime error.
Before publishing:
npm run preflight
npm publish --access public --provenance