I'm now diving deeper into ITCSS, clarifying the specific layers and their best practices for managing specificity and cascading. I'm evaluating how best to map the typical design system components into each ITCSS layer to ensure a clean, maintainable, and scalable CSS architecture. I'm considering variations on the ITCSS model and how to tailor its layers to optimize developer experience on this particular large-scale project.
Exploring ITCSS Layers
I'm now fully immersed in ITCSS, and the inverted triangle methodology is becoming clearer. I'm focusing on those critical layers, like settings and tools, as well as the important separation of concerns. The layers I have started to define are Settings, Tools, Generic, Elements, Objects, Components, and Utilities. I'm focusing on the implementation details and best practices, as the goal is a very practical and usable guide. I'm now drafting the guide content for each layer and the file structure. I'm ready to move into the content creation phase with the guide.
Defining ITCSS Structure
I'm solidifying the ITCSS structure now, laying out the specific content for each layer. I'm focusing on Settings, Tools, Generic, Elements, and Objects. I've broken each layer down into its concept, examples, and file names, as shown. I'm focusing on a clean structure for readability and maintainability.
Advancing the Component Layer
I'm now detailing the Components layer, focusing on clear examples like buttons, cards, and navigation. I'm also outlining the Trumps layer, emphasizing its role in utility classes for overriding styles, and including important examples like spacing and text alignment. I'm preparing to solidify how to organize these files for large projects, using @import or @forward strategies, and including the value of ITCSS and BEM together.
Constructing ITCSS Guide
I'm now integrating the final pieces of the ITCSS guide. I'm focusing on the visual analogy of the inverted triangle, along with a comprehensive file tree to illustrate the structure. I'm also including detailed explanations for each layer and incorporating best practices like BEM, namespacing, and preprocessor integration. I've reviewed the guide against the project requirements to ensure scalability and suitability for large projects. Finally, I'm polishing the content for clarity and emphasizing the critical distinction between Objects and Components.
Finalizing Implementation Details
I'm solidifying the final implementation details, focusing on file structure. It's adaptable beyond Sass/SCSS, but I'm primarily explaining using Sass. I have finalized my example approach.
This serves as a blueprint for a scalable Sass/SCSS architecture based on the ITCSS (Inverted Triangle CSS) methodology created by Harry Roberts.
This architecture is designed to manage the Cascade, control Specificity, and handle project growth without creating "append-only" stylesheets.
The Core Philosophy
ITCSS organizes CSS from broad (low specificity) to specific (high specificity).
Generic to Explicit: broad variables → specific widgets.
Low Specificity to High: preventing specificity wars.
Far reaching to Localized: styles that affect the whole DOM → styles that affect one div.
1. The Directory Structure
For a large project, you should avoid a flat file structure. Group files into folders corresponding to the ITCSS layers.
Purpose: Layout patterns and structural skeletons.
Specifics:This is strictly OOCSS. Use classes. No cosmetics (colors, borders, shadows). These are reusable layouts like grids, wrappers, or the "media object."
Note: It is common practice to prefix Objects with .o-.
Layer 6: Components
Purpose: Specific UI design pieces.
Specifics: This is where 80% of your code lives. Highly styled, specific widgets.
Naming: Use BEM (Block Element Modifier) here.
Note: It is common practice to prefix Components with .c-.
Layer 7: Trumps (Utilities)
Purpose: High-specificity overrides and helper classes.
Specifics: These win over everything else. They are immutable. !important is acceptable here because you want them to force a style change.
Pair with BEM: ITCSS handles architecture; BEM handles naming. Together they make styles predictable and safe to delete.
Namespacing: As seen in the examples above, use prefixes to identify which layer a class belongs to immediately:
.o- for Objects
.c- for Components
.u- for Utilities (Trumps)
.is- / .has- for State (e.g., .is-active)
Strict Containment:
Never write a @media query in 1-settings.
Never write a class selector in 4-elements.
Never set a color in 5-objects.
Automate Imports: In very large projects, manually updating main.scss can be tedious. You can use sass-globbing or Webpack importers to pull in whole folders, provided you ensure the alphabetical order creates the correct cascade within the folder. (However, manual importing is safer for strict cascade control).