This is a great question about ITCSS (Inverted Triangle CSS) architecture. Let me provide a comprehensive explanation with practical implementation, covering where different types of CSS belong in the hierarchy and why.
ITCSS stands for Inverted Triangle CSS and is a methodology created by Harry Roberts. The triangle is inverted (upside down) because it goes from:
- Low specificity, broad influence (top)
- To high specificity, targeted effects (bottom)
The layers from top to bottom are:
- Settings - Global variables, config, Sass variables
- Tools - Mixins, functions, helpers (no CSS output)
- Generic - Ground-zero styles, resets, normalize
- Elements - Bare HTML element styling
- Objects - Layout patterns, OOCSS classes
- Components - Specific UI components
- Trumps - Overrides, utilities, !important rules
Let me create a comprehensive implementation with explanations.
ITCSS Architecture - Complete Implementation Guide
1. Directory Structure
styles/
├── settings/
│ └── _settings.variables.scss
├── tools/
│ ├── _tools.functions.scss
│ └── _tools.mixins.scss
├── generic/
│ ├── _generic.normalize.scss
│ ├── _generic.reset.scss
│ └── _generic.box-sizing.scss
├── elements/
│ ├── _elements.html.scss
│ ├── _elements.body.scss
│ └── _elements.typography.scss
├── objects/
│ ├── _objects.grid.scss
│ ├── _objects.container.scss
│ ├── _objects.media.scss
│ └── _objects.layout.scss
├── components/
│ ├── _components.card.scss
│ ├── _components.button.scss
│ ├── _components.navbar.scss
│ └── _components.modal.scss
├── trumps/
│ ├── _trumps.utilities.scss
│ └── _trumps.overrides.scss
└── main.scss
2. Main Import File (Strictly Ordered)
// main.scss - THE SOURCE OF TRUTH FOR CASCADE ORDER
// ============================================================================
// SETTINGS
// ============================================================================
// Variables only. No CSS output.
// Global configuration, color palettes, typography scales
@import "settings/settings.variables";
// ============================================================================
// TOOLS
// ============================================================================
// Mixins and functions only. No CSS output.
// Reusable code snippets that use settings
@import "tools/tools.functions";
@import "tools/tools.mixins";
// ============================================================================
// GENERIC
// ============================================================================
// Normalize, resets, box-sizing. Affects all elements.
// Lowest specificity, broadest reach
@import "generic/generic.normalize";
@import "generic/generic.reset";
@import "generic/generic.box-sizing";
// ============================================================================
// ELEMENTS
// ============================================================================
// Bare HTML element styling. No classes, minimal specificity.
// Only element selectors (a, p, h1, etc.)
@import "elements/elements.html";
@import "elements/elements.body";
@import "elements/elements.typography";
// ============================================================================
// OBJECTS
// ============================================================================
// Layout patterns, OOCSS classes. Abstractable, reusable patterns.
// Classes like .o-grid, .o-container, .o-media
@import "objects/objects.container";
@import "objects/objects.grid";
@import "objects/objects.media";
@import "objects/objects.layout";
// ============================================================================
// COMPONENTS
// ============================================================================
// Specific UI components. Designed pieces of UI.
// Classes like .c-card, .c-button, .c-navbar
@import "components/components.card";
@import "components/components.button";
@import "components/components.navbar";
@import "components/components.modal";
// ============================================================================
// TRUMPS
// ============================================================================
// Overrides, utilities with !important. Highest specificity.
// Last resort for modifications
@import "trumps/trumps.utilities";
@import "trumps/trumps.overrides";
3. Detailed Layer Examples
Settings Layer
// settings/_settings.variables.scss
// NO CSS OUTPUT - Variables and configuration only
// ============================================================================
// BREAKPOINTS
// ============================================================================
$breakpoint-small: 480px;
$breakpoint-medium: 768px;
$breakpoint-large: 1024px;
$breakpoint-xlarge: 1440px;
// ============================================================================
// COLOR PALETTE
// ============================================================================
$color-primary: #0066cc;
$color-secondary: #f7931e;
$color-neutral-dark: #1a1a1a;
$color-neutral-light: #f5f5f5;
$color-text: #333;
$color-border: #ddd;
// ============================================================================
// TYPOGRAPHY SCALE
// ============================================================================
$font-base: 16px;
$font-scale: 1.25; // Perfect fifth ratio
$font-size-xs: #{$font-base / ($font-scale * $font-scale)}; // 10.24px
$font-size-sm: #{$font-base / $font-scale}; // 12.8px
$font-size-md: $font-base; // 16px
$font-size-lg: #{$font-base * $font-scale}; // 20px
$font-size-xl: #{$font-base * $font-scale * $font-scale}; // 25px
// ============================================================================
// SPACING SCALE
// ============================================================================
$spacing-unit: 0.5rem;
$spacing-xs: $spacing-unit; // 8px
$spacing-sm: $spacing-unit * 2; // 16px
$spacing-md: $spacing-unit * 3; // 24px
$spacing-lg: $spacing-unit * 4; // 32px
$spacing-xl: $spacing-unit * 5; // 40px
// ============================================================================
// TYPOGRAPHY
// ============================================================================
$font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto;
$font-family-heading: "Georgia", serif;
$font-weight-regular: 400;
$font-weight-semibold: 600;
$font-weight-bold: 700;
// ============================================================================
// LAYOUT
// ============================================================================
$container-width: 1200px;
$grid-columns: 12;
$grid-gutter: $spacing-md;
// ============================================================================
// TRANSITIONS
// ============================================================================
$transition-base: 0.2s ease-in-out;
$transition-slow: 0.4s ease-in-out;
// ============================================================================
// SHADOWS
// ============================================================================
$shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
$shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
$shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
Tools Layer
// tools/_tools.mixins.scss
// NO CSS OUTPUT - Mixins and helpers only
// ============================================================================
// RESPONSIVE DESIGN MIXIN
// ============================================================================
@mixin respond-to($breakpoint) {
@if $breakpoint == "small" {
@media (min-width: $breakpoint-small) {
@content;
}
}
@else if $breakpoint == "medium" {
@media (min-width: $breakpoint-medium) {
@content;
}
}
@else if $breakpoint == "large" {
@media (min-width: $breakpoint-large) {
@content;
}
}
@else if $breakpoint == "xlarge" {
@media (min-width: $breakpoint-xlarge) {
@content;
}
}
}
// ============================================================================
// FLEXBOX CENTERING
// ============================================================================
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
// ============================================================================
// CLEARFIX
// ============================================================================
@mixin clearfix {
&::after {
content: "";
display: table;
clear: both;
}
}
// ============================================================================
// TRUNCATE TEXT
// ============================================================================
@mixin truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
// ============================================================================
// SMOOTH TRANSITIONS
// ============================================================================
@mixin transition($property: all) {
transition: $property $transition-base;
}
// ============================================================================
// ACCESSIBLE FOCUS
// ============================================================================
@mixin focus-ring {
outline: 2px solid $color-primary;
outline-offset: 2px;
}
// tools/_tools.functions.scss
// ============================================================================
// SPACING FUNCTION
// ============================================================================
@function space($multiplier: 1) {
@return $spacing-unit * $multiplier;
}
// ============================================================================
// Z-INDEX MAP
// ============================================================================
$z-index-map: (
"dropdown": 1000,
"sticky": 1020,
"fixed": 1030,
"modal-backdrop": 1040,
"modal": 1050,
"popover": 1060,
"tooltip": 1070
);
@function z($layer) {
@return map-get($z-index-map, $layer);
}
Generic Layer
// generic/_generic.normalize.scss
// Ground-zero styles. Should apply to ALL elements.
// Normalize HTML5 display definitions
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section {
display: block;
}
// Prevent audio/video and progress elements from stretching
audio,
canvas,
progress,
video {
display: inline-block;
}
// generic/_generic.reset.scss
// Opinionated reset for consistency
* {
margin: 0;
padding: 0;
}
html {
font-size: $font-size-md;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
margin: 0;
padding: 0;
}
// generic/_generic.box-sizing.scss
// Universal box-sizing model
*,
*::before,
*::after {
box-sizing: border-box;
}
Elements Layer
// elements/_elements.body.scss
// Bare element styling. Only element selectors.
body {
font-family: $font-family-base;
font-size: $font-size-md;
line-height: 1.5;
color: $color-text;
background-color: white;
}
// elements/_elements.typography.scss
h1,
h2,
h3,
h4,
h5,
h6 {
font-family: $font-family-heading;
font-weight: $font-weight-bold;
line-height: 1.2;
margin-top: $spacing-lg;
margin-bottom: $spacing-sm;
}
h1 {
font-size: $font-size-xl;
}
h2 {
font-size: #{$font-size-xl * 0.875};
}
h3 {
font-size: $font-size-lg;
}
p {
margin-bottom: $spacing-sm;
}
a {
color: $color-primary;
text-decoration: none;
@include transition(color);
&:hover {
color: darken($color-primary, 10%);
text-decoration: underline;
}
&:focus {
@include focus-ring;
}
}
button {
font-family: inherit;
cursor: pointer;
}
input,
textarea,
select {
font-family: inherit;
font-size: inherit;
}
4. Objects Layer - Grid System
// objects/_objects.grid.scss
// WHY HERE? Grids are layout patterns, highly reusable, framework-like
// They solve layout problems abstractly, not specific UI
// ============================================================================
// GRID OBJECT
// ============================================================================
// Usage:
// <div class="o-grid">
// <div class="o-grid__item o-grid__item--1-of-3">Content</div>
// <div class="o-grid__item o-grid__item--1-of-3">Content</div>
// <div class="o-grid__item o-grid__item--1-of-3">Content</div>
// </div>
.o-grid {
display: grid;
grid-template-columns: repeat($grid-columns, 1fr);
gap: $grid-gutter;
/* Alternative: display: flex; */
/* flex-wrap: wrap; */
}
// Column sizing utilities
.o-grid__item {
&--auto {
grid-column: auto;
}
&--full {
grid-column: 1 / -1;
}
&--1-of-2 {
grid-column: span 6;
}
&--1-of-3 {
grid-column: span 4;
}
&--2-of-3 {
grid-column: span 8;
}
&--1-of-4 {
grid-column: span 3;
}
&--3-of-4 {
grid-column: span 9;
}
}
// Responsive grid
@include respond-to("medium") {
.o-grid {
gap: $grid-gutter;
&--tight {
gap: $spacing-sm;
}
&--loose {
gap: $spacing-lg;
}
}
.o-grid__item {
&--md-1-of-2 {
grid-column: span 6;
}
&--md-1-of-3 {
grid-column: span 4;
}
&--md-full {
grid-column: 1 / -1;
}
}
}
@include respond-to("small") {
.o-grid {
grid-template-columns: repeat(6, 1fr);
}
.o-grid__item {
&--sm-full {
grid-column: 1 / -1;
}
&--sm-1-of-2 {
grid-column: span 3;
}
}
}
// ============================================================================
// CONTAINER OBJECT
// ============================================================================
.o-container {
max-width: $container-width;
margin-left: auto;
margin-right: auto;
padding-left: $spacing-md;
padding-right: $spacing-md;
@include respond-to("large") {
padding-left: $spacing-lg;
padding-right: $spacing-lg;
}
}
// ============================================================================
// WHY NOT IN COMPONENTS?
// ============================================================================
// ✓ Grids are abstract layout patterns
// ✓ They have no specific visual design (no colors, borders, etc.)
// ✓ They exist in multiple projects unchanged
// ✓ They're framework-like, solving fundamental layout problems
// ✓ Low specificity, no component-specific styling
5. Components Layer - Card Component
// components/_components.card.scss
// WHY HERE? Cards are concrete UI pieces with specific design and purpose
// They combine styling, decoration, and component-specific behavior
// ============================================================================
// CARD COMPONENT
// ============================================================================
// Usage:
// <article class="c-card c-card--featured">
// <img class="c-card__image" src="..." alt="...">
// <div class="c-card__content">
// <h3 class="c-card__title">Title</h3>
// <p class="c-card__description">Description</p>
// </div>
// <footer class="c-card__footer">
// <a href="#" class="c-card__link">Read more</a>
// </footer>
// </article>
.c-card {
display: flex;
flex-direction: column;
height: 100%;
background: white;
border: 1px solid $color-border;
border-radius: 8px;
overflow: hidden;
@include transition(box-shadow);
box-shadow: $shadow-sm;
&:hover {
box-shadow: $shadow-md;
}
&:focus-within {
box-shadow: $shadow-md;
}
}
// ============================================================================
// CARD IMAGE
// ============================================================================
.c-card__image {
display: block;
width: 100%;
height: auto;
aspect-ratio: 16 / 9;
object-fit: cover;
@include transition(transform);
}
.c-card:hover .c-card__image {
transform: scale(1.05);
}
// ============================================================================
// CARD CONTENT
// ============================================================================
.c-card__content {
flex: 1;
padding: $spacing-md;
}
.c-card__title {
font-size: $font-size-lg;
font-weight: $font-weight-bold;
margin: 0 0 $spacing-sm 0;
color: $color-neutral-dark;
}
.c-card__description {
font-size: $font-size-sm;
color: #666;
line-height: 1.6;
margin: 0;
}
// ============================================================================
// CARD FOOTER
// ============================================================================
.c-card__footer {
padding: $spacing-sm $spacing-md;
border-top: 1px solid $color-border;
background: $color-neutral-light;
}
.c-card__link {
font-size: $font-size-sm;
font-weight: $font-weight-semibold;
color: $color-primary;
&:hover {
text-decoration: underline;
}
&:focus {
@include focus-ring;
}
}
// ============================================================================
// CARD MODIFIERS
// ============================================================================
// Featured card variant
.c-card--featured {
border-width: 2px;
border-color: $color-primary;
.c-card__title {
color: $color-primary;
}
}
// Minimal card variant
.c-card--minimal {
border: none;
box-shadow: none;
&:hover {
box-shadow: $shadow-sm;
}
}
// Compact card variant
.c-card--compact {
.c-card__content {
padding: $spacing-sm;
}
.c-card__title {
font-size: $font-size-md;
}
}
// ============================================================================
// RESPONSIVE BEHAVIOR
// ============================================================================
@include respond-to("small") {
.c-card__content {
padding: $spacing-sm;
}
.c-card__title {
font-size: $font-size-md;
}
}
// ============================================================================
// WHY NOT IN OBJECTS?
// ============================================================================
// ✗ Cards have specific visual design (shadows, borders, colors)
// ✗ Cards are self-contained UI pieces, not reusable patterns
// ✗ Cards include component-specific interactions (hover states)
// ✗ Cards aren't about layout, they're about a specific module
// ✗ Multiple card-specific classes with high specificity
6. Trumps Layer - Utilities & Overrides
// trumps/_trumps.utilities.scss
// WHY HERE? Utilities have highest specificity with !important
// They're last-resort modifications, applying single concerns
// ============================================================================
// DISPLAY UTILITIES
// ============================================================================
.u-hidden {
display: none !important;
}
.u-visually-hidden {
position: absolute !important;
width: 1px !important;
height: 1px !important;
padding: 0 !important;
margin: -1px !important;
overflow: hidden !important;
clip: rect(0, 0, 0, 0) !important;
white-space: nowrap !important;
border-width: 0 !important;
}
.u-block {
display: block !important;
}
.u-inline {
display: inline !important;
}
.u-inline-block {
display: inline-block !important;
}
.u-flex {
display: flex !important;
}
// ============================================================================
// SPACING UTILITIES
// ============================================================================
@each $size, $value in (
"xs": $spacing-xs,
"sm": $spacing-sm,
"md": $spacing-md,
"lg": $spacing-lg,
"xl": $spacing-xl
) {
.u-margin-#{$size} {
margin: $value !important;
}
.u-margin-top-#{$size} {
margin-top: $value !important;
}
.u-margin-bottom-#{$size} {
margin-bottom: $value !important;
}
.u-padding-#{$size} {
padding: $value !important;
}
.u-padding-top-#{$size} {
padding-top: $value !important;
}
.u-gap-#{$size} {
gap: $value !important;
}
}
// ============================================================================
// TEXT UTILITIES
// ============================================================================
.u-text-primary {
color: $color-primary !important;
}
.u-text-center {
text-align: center !important;
}
.u-text-right {
text-align: right !important;
}
.u-text-left {
text-align: left !important;
}
.u-font-bold {
font-weight: $font-weight-bold !important;
}
.u-truncate {
@include truncate;
}
// ============================================================================
// RESPONSIVE UTILITIES
// ============================================================================
@include respond-to("medium") {
.u-md-hidden {
display: none !important;
}
.u-md-block {
display: block !important;
}
}
// trumps/_trumps.overrides.scss
// Last resort for style fixes (shouldn't be needed often)
// Temporary override until component is refactored
.c-card--special-case {
border-color: purple !important;
}
// Third-party library fix
.third-party-component {
padding: 0 !important;
}
7. Complete Hierarchy Decision Tree
CSS PROPERTY OR PATTERN
|
__________|__________
| |
No CSS Output? Has CSS Output?
| |
________|_________ ______|_______
| | | |
Is it a Is it a Element
Variable/ Mixin/ Selector
Function? Helper? Default?
| | |
YES YES YES
| | |
SETTINGS TOOLS ELEMENTS
| |
| |___________________
|___________________|
|
No variable
|
____________________
| |
Abstract Layout Specific UI
Pattern? (grid, Piece?
media, (card, button,
container) modal)
| |
YES YES
| |
OBJECTS COMPONENTS
|
|
Single-concern
Override with
!important?
|
YES
|
TRUMPS
════════════════════════════════════════════════════
QUICK REFERENCE:
Settings → Variables, config, color palette
Tools → Mixins, functions, no output
Generic → Normalize, reset, box-sizing
Elements → h1, p, a, button (bare elements)
Objects → .o-grid, .o-container (abstract patterns)
Components → .c-card, .c-button (concrete UI)
Trumps → .u-margin-md, .u-hidden (last resort)
8. Key Principles Summary
| Layer | Specificity | Reach | Output | Examples |
|---|
| Settings | N/A | Global config | No | Colors, fonts, breakpoints |
| Tools | N/A | Mixins/functions | No | @mixin respond-to() |
| Generic | Very Low | All elements | Yes | Normalize, reset |
| Elements | Low | HTML tags | Yes | h1 { }, a { } |
| Objects | Low-Medium | Reusable patterns | Yes | .o-grid, .o-container |
| Components | Medium | Specific UI | Yes | .c-card, .c-button |
| Trumps | Very High | Single fixes | Yes | .u-hidden, .u-margin-top |
9. When to Add New Files
// New Grid Layout? → objects/_objects.new-layout.scss
// Why? Abstract, reusable, layout-focused
// New Button Variant? → components/_components.button.scss
// Why? Designed UI piece, specific styling
// New Color Needed? → settings/_settings.variables.scss
// Why? Applies globally, used by other layers
// New Helper Mixin? → tools/_tools.mixins.scss
// Why? Provides abstraction for other code
// Wider spacing needed? → settings/_settings.variables.scss
// Add to $spacing scale, reuse in components
// One-off margin fix? → trumps/_trumps.utilities.scss
// Create .u-margin-custom, or better: refactor component
This architecture ensures styles cascade predictably, specificity never surprises, and your codebase scales beautifully.