A single stylesheet that holds everything works fine until it doesn’t. At a few hundred lines it is manageable. At a few thousand, finding the rule you need becomes a scrolling exercise, and merge conflicts pile up whenever more than one person edits it. SCSS partials solve this by letting you split your styles across many small files, each focused on one concern, then stitch them back together at compile time. The compiled output is still a single CSS file, but the source is organised in a way a human can actually navigate.
What a Partial Is
A partial is an SCSS file that holds a piece of your styles rather than the whole thing. Variables live in one, mixins in another, the header in a third, and so on. The defining characteristic is the file name: a partial starts with a leading underscore, like _variables.scss or _header.scss. That underscore is a signal to the Sass compiler that the file is not meant to be compiled into its own CSS file. It exists only to be pulled into another file.
This matters because without the underscore, the compiler would generate a separate CSS file for every SCSS file in your project. The underscore says “this is a building block, not a finished output,” and the compiler skips it when producing standalone CSS.
The purpose of all this is modularity. Related styles stay together in their own file, which makes them easy to find and update. Common pieces like a variables file or a mixins file can be reused across projects. And because each file is small and focused, working in one rarely interferes with work happening in another.
Naming and Importing
The naming convention is straightforward: prefix every partial with an underscore and give it a descriptive name that says what it contains.
_variables.scss_mixins.scss_header.scss_footer.scss
You then bring these into a main stylesheet. Historically this was done with the @import directive, and you reference each partial without the leading underscore and without the file extension:
// main.scss@import 'variables';@import 'mixins';@import 'header';@import 'footer';
When you compile main.scss, the compiler pulls in each referenced partial in order and combines them into one CSS file. The underscores and extensions are omitted in the import statement because Sass knows to look for the partial version of the file automatically.
A note worth including here: while @import still works and appears in a great deal of existing code, the Sass team has been phasing it out in favour of @use and @forward, which handle namespacing more cleanly and avoid some of the global-scope problems @import had. If you are starting a new project, it is worth learning @use. If you are reading or maintaining older stylesheets, you will see @import everywhere, so it is important to understand both. The organising principle, splitting code into partials, is identical either way.
How to Structure Partials Well
Group related styles into their own files. Keep all your variables in _variables.scss, all your mixins in _mixins.scss, and give each major component or section its own partial like _navbar.scss or _footer.scss. The goal is that when you need to change something, you know immediately which file to open.
Name files for what they hold. A partial called _navbar.scss tells you exactly what is inside. A partial called _styles2.scss tells you nothing and guarantees someone will eventually open it just to find out.
Keep one main file as the single entry point. Everything gets imported into one place, conventionally main.scss, and that is the only file compiled into final CSS. This gives you a single, readable index of your entire stylesheet structure. Reading the list of imports at the top of main.scss should give a newcomer a clear map of how the styles are organised.
Import each partial once, from that central file, rather than importing partials into other partials in a tangle. Duplicate imports lead to duplicated rules in the output and, with the older @import, can cause genuine conflicts. A clean structure has partials that define styles and one main file that assembles them.
The Takeaway
Partials are about turning one unmanageable stylesheet into many manageable ones without changing what gets shipped. The leading underscore marks a file as a building block, the main entry file assembles everything in order, and the compiled result is still a single CSS file. Organised well, with descriptive names, logical grouping, and a single point of assembly, partials make a large codebase feel navigable. And while @import is the directive most of this pattern grew up around, the same thinking carries directly into the newer @use and @forward that are gradually replacing it.
See you soon.
[…] Partials: https://datalad.co.uk/2024/04/06/organising-stylesheets-with-scss-partials/ […]