Groups and exports
Groups apply one scope or state to several declarations. Exports turn a class list into one named class, defined right in your markup.
Groups
Put several declarations in […] to give them all the same prefix:
@md[d-flex,g-16px]
--hover[c-red,bgc-blue]Generated CSS
@layer md {
@media (min-width: 768px) {
.\@md\[d-flex\,g-16px\] {
display: flex;
gap: 16px;
}
}
}
.--hover\[c-red\,bgc-blue\]:hover {
color: red;
background-color: blue;
}States and attribute selectors can go inside a group too:
[d-block,--hover-bgc-slateTheme3,[aria-current=true]-fw-600]
@components--before[cont,position-absolute,inset-0]
A group styles one element in all its states. Two things don’t go inside one:
- Other elements:
[_th[fw-600]]isn’t supported. Use a combinator on each class (_th-fw-600) or a statement. - Scopes and components: no
@md-…and nox-…inside the brackets. Anx-name inside a group is read as a property calledx.
Exports: --as-name
When the same class list appears three or more times, export it once and use the name everywhere else. The export can sit on any element in your source, usually a hidden one:
<div hidden class="[d-inline-flex,aic,p-6px-12px,br-999px,fs-13px,bgc-slateTheme3,c-slateTheme12,--hover-bgc-slateTheme4]--as-chip"></div>
<div class="d-flex g-8px">
<a class="chip">Layout</a>
<a class="chip">Colors</a>
<a class="chip">Motion</a>
</div>Generated CSS
.chip {
display: inline-flex;
align-items: center;
padding: 6px 12px;
border-radius: 999px;
font-size: 13px;
background-color: light-dark(#f0f0f3,#212225);
color: light-dark(#1c2024,#edeef0);
}
.chip:hover {
background-color: light-dark(#e8e8ec,#272a2d);
}
.d-flex {
display: flex;
}
.g-8px {
gap: 8px;
}- Export several names at once with
--as-[chip,tag]. Names can contain/:--as-card/header. - States, attributes and ancestor selectors work inside:
[…,--hover-bgc-slateTheme3,[aria-current=page]-fw-600]--as-nav-item. - Only atomic classes can be exported: no
x-components and no scoped classes (@md-…,@motion-reduce-…). Put those on the element next to the exported name. - Pick names that don’t start with a property alias followed by a value.
c3-cardcompiles ascolor: 3-card. A component prefix avoids this:nav-item,deck-card.
In React, render the export inside the component, so it travels with it:
<div hidden className="[d-flex,aic,g-8px]--as-row"></div>
<li className="row">…</li>
This site’s sidebar links are an export: one hidden element in the layout defines side-link, and the desktop sidebar and the phone menu both use it.
Named groups: class-name
A class-name attribute defines the class name from the classes in its value. Put a scope in brackets after the name to give every item the same prefix:
<div class-card="p-24px br-12px --hover-bgc-slateTheme3"></div>
<div class-panel[@md]="p-32px d-grid"></div> <!-- .panel inside @media (min-width: 768px) -->
<div class-btn[--hover]="bgc-accentRA1100 c-white"></div> <!-- .btn:hover -->
class_cardworks the same way.class:card, with a colon, needsuseColon: truein the config, for the CLI and the browser script alike.- The element doesn’t need a
classattribute of its own. - In JSX, scopes aren’t possible here (
[isn’t allowed in a JSX attribute name, andclass:is namespace syntax React rejects). Use an export instead:@md[p-32px,d-grid]--as-panel.
Raw CSS
For the rare rule that’s easier to write as CSS, put it in a data-raw-css attribute. It’s passed through as is:
<style data-raw-css="h1{letter-spacing:-0.02em}"></style>