The 7-1 SCSS structure is a popular file organization pattern for structuring SCSS in a scalable way. It helps manage larger projects by separating styles into clear categories, making it easier to find, maintain, and collaborate on styling code. The “7-1” part refers to seven folders and one main SCSS file that imports them.
Here’s how the structure typically looks:
1. Structure Overview
The scss/
folder usually contains these subfolders:
scss/ |– abstracts/ |– base/ |– components/ |– layout/ |– pages/ |– themes/ |– vendors/ |– main.scss
Each folder has a specific purpose:
- abstracts/ – Stores global variables, mixins, functions, and other helpers that don’t output CSS on their own but are used by other SCSS files.
_variables.scss
- _mixins.scss
- _functions.scss
- base/ – Contains base styles, such as resets and typography rules, that apply to the entire site.
- _reset.scss
_typography.scss
- _base.scss
- _animations.scss
- _utilities.scss
- components/ – Holds small, reusable components like buttons, sliders, or form elements, which are modular and used across the site.
- _button.scss
- _form.scss
- _card.scss
- layout/ – Defines the main layout of the site, including the header, footer, grid systems, and sections of the layout.
- _header.scss
- _footer.scss
- _grid.scss
- _sidebar.scss
- pages/ – Contains styles for individual pages or specific templates. For example, unique styling for the homepage or contact page.
- _home.scss
- _about.scss
- _contact.scss
- themes/ – Includes styles for different themes or design variations (e.g., light mode and dark mode).
- _light-theme.scss
- _dark-theme.scss
- vendors/ – Stores styles for any external libraries or frameworks, such as Bootstrap or Normalize.css.
- _normalize.scss
- _bootstrap.scss
2. main.scss
This file imports all the other SCSS files, ensuring they compile into a single CSS output. The order of imports is generally:
// main.scss @import 'abstracts/variables'; @import 'abstracts/mixins'; @import 'abstracts/functions'; @import 'vendors/bootstrap'; @import 'vendors/normalize'; @import 'base/reset'; @import 'base/typography'; @import 'base/base'; @import 'layout/grid'; @import 'layout/header'; @import 'layout/footer'; @import 'components/button'; @import 'components/form'; @import 'components/card'; @import 'pages/home'; @import 'pages/about'; @import 'pages/contact'; @import 'themes/light-theme'; @import 'themes/dark-theme';
Benefits of the 7-1 SCSS Structure
- Organization: Styles are organized by purpose, making them easy to locate.
- Scalability: Adding new features or sections is straightforward.
- Reusability: Encourages modular design, allowing styles to be reused across projects.
- Collaboration: Other developers can navigate the structure easily, which helps teams collaborate effectively.
This structure serves as a strong foundation but can be customized to fit the needs of your project.