Skip to content

Utilities

NightCSS utilities are small, single-purpose classes. Each one sets one property, reads a --nc-* token for its value, and lives in the nightcss.utilities layer. Because the layer comes last in the cascade order, utilities beat the reset and the base styles, while your own unlayered CSS still beats both.

Built from utilitiesflex · gap-4 · rounded-lg
/* The value lives in the token layer. */
--nc-space-4: 1rem;
/* The class is a thin reference with a per-element knob. */
.p-4 { padding: var(--p, var(--nc-space-4)); }

That gives you three levels of control:

  1. Theme — override --nc-space-4 once on :root or a theme.
  2. One element — set --p inline or in component CSS.
  3. Class — choose a different step, such as p-6.
<div class="p-4">Token value</div>
<div class="p-4" style="--p: 37px">One-off value</div>

The class is only one way to reach a value. The class, the plain CSS token, and the Sass accessor all resolve to the same --nc-* scale, so a style can live in markup or in a stylesheet without being redefined.

Class Plain CSS Sass
p-4 padding: var(--nc-space-4) padding: nc.nc-space(4)
rounded-lg border-radius: var(--nc-radius-lg) border-radius: nc.nc-radius("lg")
shadow-md box-shadow: var(--nc-shadow-md) box-shadow: nc.nc-shadow("md")
bg-accent background-color: var(--nc-accent) background-color: nc.nc-color("accent")
text-lg font-size: var(--nc-text-lg) font-size: nc.nc-text("lg")
/* Plain CSS: no Sass, no build step. */
.card {
padding: var(--nc-space-4);
border-radius: var(--nc-radius-lg);
box-shadow: var(--nc-shadow-md);
background-color: var(--nc-accent);
}
/* SCSS: the optional accessors add a literal fallback and stay themeable. */
@use "nightcss/scss" as nc;
.card {
padding: nc.nc-space(4);
border-radius: nc.nc-radius("lg");
box-shadow: nc.nc-shadow("md");
background-color: nc.nc-color("accent");
}

Choose a class when the style is local to markup, and a plain token or Sass accessor when the rule belongs in a component stylesheet, a media query, or a state selector. The accessors cover the token-backed value scales; behavioral families such as display, flex, and overflow stay class-only by design. See the Sass subpackage for the full function list. Token-backed families below end with a short Use in CSS example for their own properties.

Most families read one short property. The property overrides the whole family on the element where it is set.

Family Knob
Padding, margin, offset --p, --m, --inset
Gap --gap
Width, height, min/max --w, --h, --min-w, --max-w, --min-h, --max-h
Type --text-size, --font-size, --font-weight, --line-height, --spacing
Color --bg, --clr, --fill
Surfaces --radius, --shadow, --gradient
Opacity --opacity
Motion --speed, --timing
Stacking and rotation --z, --rotate

Generated families accept a breakpoint between the prefix and the value:

Suffix Min width
sm 640px
md 768px
lg 1024px
xl 1280px
2xl 1536px
<div class="d-none d-md-block opacity-8 opacity-lg-10 p-2 p-lg-6">…</div>

Breakpoint rules sit later in the stylesheet than the base rules, in the same layer, so they win without !important. A breakpoint class always uses the scale value; the short knob applies to the base class. Families whose Breakpoints column is No are base-only — write a media query when you need one.

Breakpoint variants are not in the lean default bundle. In the family map below, a Yes in the Breakpoints column means at least some classes in that family live in the responsive file. To use them, add the import after the base stylesheet:

/* npm */
@import "nightcss";
@import "nightcss/utilities/responsive";
<!-- CDN: two links, in this order -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nightcss@2/dist/nightcss.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nightcss@2/dist/utilities.responsive.min.css">

Or take nightcss/full for the one-import build. If you compose per-family modules, import the family’s responsive companion after the family itself, for example nightcss/utilities/spacing then nightcss/utilities/spacing/responsive. Only the display, flex, grid, opacity, position, radius, sizing, spacing, typography, and z families have breakpoint companions; the rest are base-only.

Every utility has its own page. The pages are grouped by theme — layout, type, colour, surface, effects — but each one documents a single family, with the full class list, the matching tokens, and working examples.

Utility Page Also written as Breakpoints
Display Display d-* Yes
Flex direction, wrap, grow Flex flex-* Yes
Main and cross-axis alignment Alignment justify-*, items-*, align-* Yes
Gap Gap gap-* No
Native and row/col grid Grid grid, grid-cols-*, col-span-* Row/col only
Padding Padding p-*, px-*, py-* Shorthands
Margin Margin m-*, mx-auto Shorthands and auto
Vertical rhythm Space Between space-y-* No
Width, height, min/max Sizing w-full, h-screen Percent and viewport
Position Position relative, absolute Yes
Inset and offsets Inset inset-0, top-* No
Z-index Z-index z-plus-*, z-minus-* Yes
Utility Page Also written as Breakpoints
Type scale and headings Type Scale text-lg, h1–h6, display-* No
Weight Weight font-weight-* Yes
Line height Line Height leading-* Yes
Letter spacing Tracking tracking-* Yes
Text alignment Text Alignment text-center, text-end Yes
Text transform Text Transform text-uppercase Yes
Text decoration Text Decoration text-underline Yes
White space White Space white-space-* Yes
Word break Word Break word-break-* Yes
Truncation Truncation text-truncate, truncate No
Font style Font Style font-italic Yes
Font family Font Family font-sans, font-mono No
Lists Lists list-unstyled No
Utility Page Also written as Breakpoints
Semantic and named colour Color bg-surface, clr-*, fill-* No
Gradients Gradients gradient-* No
Utility Page Also written as Breakpoints
Border Border border, border-2 No
Radius Radius rounded-*, radius-* Radius sides
Shadow Shadow shadow-* No
Utility Page Also written as Breakpoints
Opacity Opacity opacity-* Yes
Rotation Rotation rotate-* No
Transitions and easing Motion speed-*, timing-* No

Many families offer two spellings for the same job. The compact spelling is shorter in markup; the long spelling mirrors the CSS property and is the one that usually ships breakpoint variants. Both are stable, and both can be mixed in one project.

Compact Long
flex d-flex
flex-col flex-column
items-center align-items-center
justify-between justify-content-between
leading-tight line-height-25
font-semibold font-weight-600

The two spellings do not always share a scale. rounded-lg is 1rem while radius-large is 20px; shadow-md and shadow-level-3 are different elevations. Both ladders are documented on their own pages, so choose the one that matches the design.

  • Spacing steps run 0 through 24 on a 4px scale.
  • Sizing uses logical properties: inline-size and block-size, not width and height. In horizontal writing modes they map to the same thing.
  • A bare border is 1px solid var(--nc-border).
  • Nothing uses !important. Specificity comes from the layer order.