Skip to content

Design Principles

The parent decides the child’s layout; the child only styles its internals.

SpiraCSS is a CSS architecture based on this single principle.

Unlike utility-first approaches like Tailwind CSS, it follows the lineage of BEM / SMACSS / RSCSS, but Stylelint validates not only naming, but also structure and property responsibilities.

SpiraCSS Stylelint rules include what’s wrong and how to fix it in error messages, enabling AI agents to apply corrections. No need to memorize detailed rules.

Here’s the overview.

CSS Layers

Split project-wide CSS into three layers.

LayerRole
GlobalSite-wide values, functions, mixins, utilities
PagePer-page entry CSS (component placement)
ComponentComponent design with Block/Element + Variant/State

See CSS Layers for details.

Components

Build all structures by repeating Block > child (Block | Element).

Naming

TypeRule (default)Examples
BlockTwo words.hero-container, .card-list
ElementOne word.title, .body
Utilityu- prefix.u-hidden, .u-sr-only

Structure rules

  • Allowed: Block > Block, Block > Element
  • Disallowed: Element > Block, Element > Element (exception: decorative purposes only)

Variant / State (default: data attributes)

TypeHTMLSCSS
Variantdata-variant="primary"&[data-variant="primary"]
Statedata-state="active"&[data-state="active"]
ARIAaria-expanded="true"&[aria-expanded="true"]

File management

  • One Block per file: each Block maps to one SCSS file
  • Child Blocks: place under scss/ and load with meta.load-css("scss")
  • Link comments: use @rel to navigate between related files

See Components for details.

SCSS sections

Organize each Block’s SCSS into three sections:

  1. Base structure: Block layout + Variant
  2. —shared: shared classes scoped to this Block (only when needed)
  3. —interaction: State / hover / ARIA / transitions (only when needed)

See SCSS Sections for details.

Tooling

  • Generate: CLIs / VS Code extensions automate @rel comments and SCSS
  • Validate: Stylelint detects violations with the same criteria for humans and AI
  • Configure: adjust naming, Variant/State expression mode, validation strength in spiracss.config.js

See Tooling for details.