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.

01

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:

TERMINAL
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.

Default inputEntire project directory
Source files.smcss
Default output./output
Configurationsmcss.config

Use the generated configuration file to adjust these settings.

Listen for changes

TERMINAL
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.

Your configuration controls the watch workflow.

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:

COMMAND FORMAT
smcss --build <input-directory> <output-directory>

Build the entire current project into its output folder:

PROJECT BUILD
smcss --build . ./output

Or choose specific source and destination folders:

CUSTOM FOLDERS
smcss --build ./styles ./public/css

You can also use . for the output directory. This uses the current working directory for both input and output:

CURRENT DIRECTORY
smcss --build . .
A typical workflow

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.

02

Syntax quick start

Start with a named media query and a responsive rule. A context starts with $ and sits before your selector.

layout.smcss
$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.

Download the example stylesheet
03

Media contexts

Use $media, followed by a name and a media query. End the definition with a semicolon.

DEFINE YOUR CONTEXTS
$media mobile (max-width: 768px);
$media desktop (min-width: 769px);

$mobile .site-nav {
  flex-direction: column;
}

$desktop .site-nav {
  flex-direction: row;
}
Choose breakpoints for your layout.

768px and 769px are example values, not required defaults. The names make the intent searchable while the query defines when a rule applies.

04

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:

SIMPLE CLASSES & BEM
.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.

Normal CSS specificity still applies.

A context adds a media condition. It doesn’t change the specificity of the selector inside it.

05

Selector aliases

Use $alias to give a selector a reusable name. Reference it with $ wherever you want that selector prefix.

REUSE A SELECTOR
$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.

06

Plain CSS output

Named contexts become media queries. Selector aliases become the selectors they represent. Your declarations remain CSS.

OUTPUT FOR THE ALIAS EXAMPLE
@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.

07

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.

V1 BETA

The repository
is coming soon.

Explore the syntax with a starter stylesheet while the first release is being prepared.