WHAT IS SMCSS? · FOR VANILLA CSS LOVERS
Your CSS.
Just easier to find.
SMCSS works alongside vanilla CSS. It isn’t meant to replace it.
Keep your selectors, declarations, and the way you build layouts. Add readable names for responsive contexts, then compile to ordinary CSS.
$mobile .head .top .left { … }WHY I CREATED SMCSS
My CSS is a little
unconventional.
A note from JØSH
I write selectors that follow the structure of my HTML. They can get long, but I type fast, so I don’t really mind. That way of writing CSS feels natural to me.
Media queries were the part that slowed down my workflow. I’d jump between blocks, search for breakpoints, and then search again for the selector I actually wanted.
I created SMCSS to make that part easier. A name like $mobile puts the context right next to the selector, so I can keep writing CSS my way and find the responsive rules faster.
01 / FOLLOW THE HTML
I write CSS
like an anatomy tree.
I use structural names like .hat, .head, .body, and .foot. Then I follow the HTML deeper with .top, .bottom, .left, and .right.
The selector tells me where I am. It’s quick to write, easy to search, and familiar when I come back later.
.hatAbove the main content.headThe top of the component.bodyThe main content.footThe bottom of the component.head
.head .top
.head .top .left02 / KEEP YOUR CONVENTION
The selector grows
with the structure.
A component’s head contains a top row, and that row has a left side. My CSS mirrors those relationships.
I reuse the structural names and scope them under the component, like .product .head .top .left. SMCSS supports this approach, as well as BEM and other naming conventions.
.product .head {
padding: 24px;
}
.product .head .top {
display: flex;
justify-content: space-between;
}
.product .head .top .left {
display: flex;
gap: 12px;
}03 / ADD THE CONTEXT
So naturally,
$mobile .head …
The responsive version starts the same way. Put a named context in front of the selector and keep writing CSS.
Search $mobile for mobile rules, or .head .top .left for that part of the layout. You don’t have to remember the breakpoint to find the styles.
$media mobile (max-width: 768px);
$mobile .product .head .top .left {
flex-direction: column;
gap: 8px;
}@media (max-width: 768px) {
.product .head .top .left {
flex-direction: column;
gap: 8px;
}
}04 / SHORTEN THE REPETITION
A name for a selector
you use all the time.
Aliases let you reuse a long selector without changing your HTML. Combine an alias with a media context when you need it.
$alias sidebar .dashboard .arm .left;
$mobile $sidebar .nav {
display: none;
}V1 BETA
Love vanilla CSS?
Make it more searchable.
Readable contexts in your source. Plain CSS for the browser.