SMACSS: A Naming Convention for CSS Scalability

SMACSS organizes CSS into five categories to prevent spaghetti code. It's a naming convention and thought process, not a library you install. It's used in large codebases where teams need a shared vocabulary for styling components.
Why it exists
CSS in large projects often becomes a tangled mess of overrides and specificity wars. Without a system, developers can't safely add or change styles without causing unintended side effects. SMACSS was created to provide a consistent approach for structuring CSS to improve maintainability and scalability on projects with long lifespans and multiple contributors.
The mental model
Think of SMACSS as creating labeled buckets for your CSS rules. Instead of one giant, unpredictable stylesheet, you categorize every rule based on its purpose. Is it a default style for a basic HTML element (Base)? Does it define a major page section (Layout)? Is it a reusable, self-contained component (Module)? This categorization prevents styles from bleeding into each other unexpectedly.
How it works
SMACSS proposes five distinct categories. First, Base rules are element selectors setting application-wide defaults (like body, a, input). Second, Layout rules divide the page into major sections (like .l-header, .l-sidebar). Third, Module rules are for reusable, discrete UI components (like .card, .button). Fourth, State rules modify a module or layout's appearance (like .is-hidden, .is-active). Fifth, Theme rules are optional overrides for changing the visual look. A common convention is to prefix class names, such as l- for Layout and is- for State, to make the rule's purpose obvious from the HTML.
When to use it
Use SMACSS principles on large, long-lived projects with multiple developers, especially when you are not using a component-based JavaScript framework with scoped styles (like React with CSS Modules). It provides a shared vocabulary and structure that prevents CSS decay over time.
When not to use it
For small, single-page projects, the organizational overhead of SMACSS might be unnecessary. Modern component frameworks with built-in style scoping (like Vue's Single-File Components or styled-components) solve many of the same global namespace problems that SMACSS was designed to address, making a strict SMACSS methodology less critical in those environments.
One canonical example
A login form could be a Module named .form-login. The major page regions it sits in, like a header and a main content area, would be defined by Layout rules like .l-header and .l-main. The default styles for the input and button elements are set by Base rules. When the user types an incorrect password, a State class like .is-error is added to the form to show a red border.
Interview question
What is the fundamental mechanism by which SMACSS helps manage CSS scalability in large projects?
- a.It provides a set of pre-defined CSS classes for common UI elements, reducing custom code.
- b.It automatically scopes CSS rules to individual components, preventing global style conflicts.
- c.It dictates a specific file structure and build process to optimize CSS delivery and performance.
- d.It introduces a system of categorizing CSS rules based on their purpose, using specific naming conventions.Correct
Why? this is the answer
SMACSS's core approach is to categorize CSS rules into five distinct types (Base, Layout, Module, State, Theme) and use naming conventions (like prefixes) to clarify their purpose, preventing styles from bleeding into each other. Option B describes automatic scoping, which is a feature of modern JavaScript frameworks, not SMACSS itself, which relies on convention.
Just read this? Test yourself on what you have been reading.
Read the original → smacss.com
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.
See open roles