The 7-1 Pattern
As a stylesheet grows past a few hundred lines, where to put things becomes the hardest problem. The 7-1 pattern is a popular folder structure for Sass projects: 7 folders of partials and 1 main file that loads them all.
The structure
scss/
├── abstracts/ ← variables, functions, mixins (output NO CSS)
│ ├── _index.scss
│ ├── _tokens.scss
│ ├── _functions.scss
│ └── _mixins.scss
├── base/ ← reset, typography, element defaults
│ ├── _reset.scss
│ └── _typography.scss
├── components/ ← buttons, cards, badges, modals (one block per file)
│ ├── _button.scss
│ └── _card.scss
├── layout/ ← header, footer, grid, sidebar
│ ├── _header.scss
│ └── _grid.scss
├── pages/ ← page-specific styles
│ └── _home.scss
├── themes/ ← theme variations (dark, brand themes)
│ └── _dark.scss
├── vendors/ ← third-party CSS
│ └── _normalize.scss
└── main.scss ← the 1 file that is compiled| Folder | Contains | Outputs CSS? |
|---|---|---|
abstracts/ |
Tokens, functions, mixins, placeholders | No |
vendors/ |
External libraries | Yes |
base/ |
Resets, html/body, headings, links |
Yes |
layout/ |
Big structural regions | Yes |
components/ |
Small reusable widgets (BEM blocks) | Yes |
pages/ |
Styles for a single page | Yes |
themes/ |
Alternate looks | Yes |
The main file
With the module system, main.scss only loads modules — it contains no styles itself. Order matters: generic first, specific last.
// main.scss
@use "vendors/normalize";
@use "base/reset";
@use "base/typography";
@use "layout/header";
@use "layout/grid";
@use "components/button";
@use "components/card";
@use "pages/home";
@use "themes/dark";Sharing abstracts with @forward
Every partial that needs tokens or mixins loads the abstracts folder. An _index.scss forwards everything, so one line is enough:
// abstracts/_index.scss
@forward "tokens";
@forward "functions";
@forward "mixins";// components/_button.scss
@use "../abstracts" as *;
.button {
padding: space(2) space(4);
background: $color-brand;
border-radius: $radius;
@include focus-ring;
}Because abstracts contains no CSS output, loading it in fifty partials costs nothing. Sass evaluates each module only once anyway.
Note:
@use "../abstracts" as *removes the namespace for convenience. That's fine for your own small set of tokens; for third-party modules keep the namespace to avoid name clashes.
Simulating it in one file
The playground can't hold several files, but here's what the compiled result of a tiny 7-1 project looks like. Each comment marks where a partial's content would come from:
// ---- abstracts/_tokens.scss (no output) ----
$color-brand: #cc6699;
$color-ink: #2d2a32;
$radius: 8px;
// ---- abstracts/_mixins.scss (no output) ----
@mixin focus-ring {
&:focus-visible { outline: 3px solid rgb(204 102 153 / 0.4); outline-offset: 2px; }
}
// ---- base/_typography.scss ----
body {
font-family: system-ui, sans-serif;
color: $color-ink;
}
// ---- components/_button.scss ----
.button {
background: $color-brand;
color: white;
border: 0;
padding: 8px 16px;
border-radius: $radius;
@include focus-ring;
}body {
font-family: system-ui, sans-serif;
color: #2d2a32;
}
.button {
background: #cc6699;
color: white;
border: 0;
padding: 8px 16px;
border-radius: 8px;
}
.button:focus-visible {
outline: 3px solid rgba(204, 102, 153, 0.4);
outline-offset: 2px;
}
Scaling up or down
7-1 is a guideline, not a law:
- Small project:
abstracts/,base/,components/andmain.scssare often enough. - Component frameworks (Vue, React, Svelte): component styles may live next to the component file; keep only
abstracts/andbase/global. - Design systems: add a
utilities/folder for generated helper classes like.mt-2.
Tip: Whatever structure you choose, write it down in the project README and keep
abstracts/free of CSS output. That single rule prevents most duplication problems.
Test yourself
Which 7-1 folder should never output CSS on its own?
- base
- components
- abstracts
- layout
What does main.scss contain in the 7-1 pattern?
- All the styles in one file
- Only @use rules that load the partials
- Only variables
- The vendor CSS
Where would a .card BEM block go?
- abstracts/
- layout/
- components/
- vendors/