CLI & LANGUAGE GUIDE · V1 BETA
A little more context.
The Same CSS.
Set up your project, watch your styles, and build CSS with the SMCSS CLI. Then explore media contexts and selector aliases with familiar CSS declarations.
CLI tutorial
Run these commands from your terminal once the smcss CLI is installed. In a directory argument, . means your current working directory.
Initialize your project
From your project’s root directory, run:
smcss --init .This creates smcss.config with the default configuration. The default input searches the entire project directory for .smcss files. Compiled CSS goes into an output folder in the project’s root directory.
Customize the configuration
Edit smcss.config to change the input folder, the output folder, or the output folder’s name. For example, you can keep source styles in styles and send compiled files to public/css.
Entire project directory.smcss./outputsmcss.configUse the generated configuration file to adjust these settings.
Listen for changes
smcss --listen .Without a configuration file, this listens for changes across the whole current directory. If smcss.config exists, SMCSS listens and outputs files according to its settings.
After changing your input or output settings, use the same smcss --listen . command to work with those configured folders.
Run a one-time build
Pass the input directory first and the output directory second:
smcss --build <input-directory> <output-directory>Build the entire current project into its output folder:
smcss --build . ./outputOr choose specific source and destination folders:
smcss --build ./styles ./public/cssYou can also use . for the output directory. This uses the current working directory for both input and output:
smcss --build . .Run smcss --init . once, adjust smcss.config to suit your project, then run smcss --listen . while you edit. Use --build when you want a single build with explicit input and output directories.
Syntax quick start
Start with a named media query and a responsive rule. A context starts with $ and sits before your selector.
$media mobile (max-width: 768px);
.card-list {
display: flex;
gap: 24px;
}
$mobile .card-list {
flex-direction: column;
padding: 16px;
}The first rule is ordinary CSS. The second applies the named $mobile context. Search that name to find your mobile styles.
Media contexts
Use $media, followed by a name and a media query. End the definition with a semicolon.
$media mobile (max-width: 768px);
$media desktop (min-width: 769px);
$mobile .site-nav {
flex-direction: column;
}
$desktop .site-nav {
flex-direction: row;
}768px and 769px are example values, not required defaults. The names make the intent searchable while the query defines when a rule applies.
Your selectors stay yours
SMCSS works with ordinary CSS selectors and BEM class names. Put a media context before the selector; write the declarations as usual.
For example, use .card for a component and .card__actions for its actions:
.card {
padding: 24px;
}
.card__actions {
display: flex;
gap: 12px;
}
$mobile .card__actions {
flex-direction: column;
gap: 8px;
}Here, $mobile .card__actions applies the media context to the same BEM class used in the base rule. SMCSS doesn’t change the class name or require different HTML.
A context adds a media condition. It doesn’t change the specificity of the selector inside it.
Selector aliases
Use $alias to give a selector a reusable name. Reference it with $ wherever you want that selector prefix.
$alias sidebar .dashboard .sidebar;
$mobile $sidebar .nav {
display: none;
}
$desktop $sidebar .nav {
width: 280px;
}Here, $sidebar .nav represents .dashboard .sidebar .nav. The alias saves repetition; your HTML classes stay the same.
Plain CSS output
Named contexts become media queries. Selector aliases become the selectors they represent. Your declarations remain CSS.
@media (max-width: 768px) {
.dashboard .sidebar .nav {
display: none;
}
}
@media (min-width: 769px) {
.dashboard .sidebar .nav {
width: 280px;
}
}The browser receives ordinary CSS and uses its normal cascade. There’s no SMCSS runtime in the browser.
Beta & downloads
SMCSS is in v1 beta. The CLI release is being prepared. Installation instructions will be added here when the release is available. The CLI workflow is documented above.
For now, download the starter stylesheet to explore the syntax in your editor.