How classes work
The whole grammar on one page. A class is [@scope-][selector-]property-value, read from right to left.
The rule
property-value display-flex display: flex
alias-value d-flex display: flex
@scope-property-value @md-d-flex inside @media (min-width: 768px)
--state-property-value --hover-c-red on :hover
@scope--state-property-value @md--hover-c-red both
The declaration (property-value) is always last. Everything before it is optional and narrows down where it applies:
- Scope starts with
@: a breakpoint, media feature, container query or cascade layer. See Responsive and scopes. - Selector starts with
-,_or[: a state, pseudo-element, attribute or another element. See States and selectors.
Full names and aliases
Every CSS property works with its full name. Common ones also have a short alias. When you’re unsure, write the full name: it always works.
background-color-red
bgc-red
justify-content-space-between
jcsbGenerated CSS
.background-color-red {
background-color: red;
}
.bgc-red {
background-color: red;
}
.justify-content-space-between {
justify-content: space-between;
}
.jcsb {
justify-content: space-between;
}| Alias | Property | Example |
|---|---|---|
d |
display | d-flex, d-grid, d-none |
p, m |
padding, margin | p-16px, m-0, p-8px-16px |
px, py, mx, my |
left + right, top + bottom padding and margin | px-24px, mx-auto |
w, h |
width, height | w-100%, h-40px |
mw, xw, xh |
min-width, max-width, max-height | xw-680px |
g |
gap | g-12px |
aic, jcc, jcsb |
align-items: center, justify-content: center / space-between | |
c, bgc |
color, background-color | c-red, bgc-slateTheme1 |
fs, fw, lh, ff |
font-size, -weight, line-height, font-family | fs-14px, fw-600 |
b, br |
border, border-radius | b-1px-solid-red, br-8px |
t, r, btm, l |
top, right, bottom, left | t-0 |
gtc, gc |
grid-template-columns, grid-column | gc-span-2 |
o, zi, tf |
opacity, z-index, transform | o-0.5, tf-scale-0.98 |
cont |
content: "" |
--before-cont |
The cheat sheet has the full list of the common ones. Note that mw is min-width and xw is max-width.
Values
A value is written as CSS writes it, with - in place of each space:
b-1px-solid-red
p-8px-16px
m--8px
o-0.5
w-100%Generated CSS
.b-1px-solid-red {
border: 1px solid red;
}
.p-8px-16px {
padding: 8px 16px;
}
.m--8px {
margin: -8px;
}
.o-0\.5 {
opacity: 0.5;
}
.w-100\% {
width: 100%;
}When a value has commas, functions or anything a dash can’t express, use the property’s function form, property(value). Inside it, _ is a space:
padding(8px_16px)
gtc(repeat(3,1fr))
w(calc(100%_-_32px))Generated CSS
.padding\(8px_16px\) {
padding: 8px 16px;
}
.gtc\(repeat\(3\,1fr\)\) {
grid-template-columns: repeat(3, 1fr);
}
.w\(calc\(100\%_-_32px\)\) {
width: calc(100% - 32px);
}The Values and units page covers negatives, decimals, colors with alpha, !important and CSS variables.
What the compiler writes
Each class becomes one rule with that exact class name as its selector. Using the same class twice costs nothing: it’s compiled once. Classes you never use are never written.
Breakpoint classes go into cascade layers, which has one consequence worth learning early: a plain class always beats a breakpoint class. The fix is on the Responsive page.
When a class doesn’t work
The browser script prints a warning for every class it can’t compile:
AliasCSS: can't compile "-bad-thing" (nothing is output)
AliasCSS: "border-bottom-0": couldn't compile the value "0", used it as written
The second kind is only a hint: the CSS is still correct. Values aren’t checked against CSS, so bgc-notacolor outputs background-color: notacolor and the browser ignores it. Some mistakes compile without any warning (calc(100%-32px), --before--hover-…), so when something looks wrong, check the generated CSS and the common mistakes.