ITCSS helps organize CSS in a clear way so styles don't get messy. Using SASS with ITCSS makes writing and managing styles easier and faster.
ITCSS methodology with SASS
Start learning this pattern below
Jump into concepts and practice - no test required
// ITCSS folder structure example // 1. Settings: variables, colors, fonts // _settings.scss // 2. Tools: mixins, functions // _tools.scss // 3. Generic: resets, box-sizing // _generic.scss // 4. Elements: basic HTML elements styles // _elements.scss // 5. Objects: reusable components, layout // _objects.scss // 6. Components: specific UI parts // _components.scss // 7. Utilities: helpers, helper classes // _utilities.scss // main.scss @use 'settings'; @use 'tools'; @use 'generic'; @use 'elements'; @use 'objects'; @use 'components'; @use 'utilities';
Each layer builds on the previous one, from general to specific.
SASS partial files start with an underscore (_) and are imported into a main file.
// _settings.scss $primary-color: #3498db; $font-stack: 'Arial, sans-serif';
// _tools.scss @mixin center-flex { display: flex; justify-content: center; align-items: center; }
// _generic.scss * { box-sizing: border-box; margin: 0; padding: 0; }
// _components.scss .button { background-color: $primary-color; color: white; padding: 1rem 2rem; border-radius: 0.5rem; @include center-flex; }
This example shows a simple webpage with a styled button. The styles are organized using ITCSS layers in one SASS file. Variables and mixins make the code easy to read and reuse.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>ITCSS with SASS Example</title> <link rel="stylesheet" href="styles.css" /> </head> <body> <button class="button">Click Me</button> </body> </html> /* styles.scss */ // 1. Settings $primary-color: #3498db; $font-stack: 'Arial, sans-serif'; // 2. Tools @mixin center-flex { display: flex; justify-content: center; align-items: center; } // 3. Generic * { box-sizing: border-box; margin: 0; padding: 0; } // 4. Elements body { font-family: $font-stack; background-color: #f0f0f0; height: 100vh; display: flex; justify-content: center; align-items: center; } // 5. Objects // (empty for this example) // 6. Components .button { background-color: $primary-color; color: white; padding: 1rem 2rem; border-radius: 0.5rem; cursor: pointer; @include center-flex; font-size: 1.25rem; transition: background-color 0.3s ease; } .button:hover { background-color: darken($primary-color, 10%); } // 7. Utilities // (empty for this example)
ITCSS helps keep styles predictable and easy to find.
Use SASS features like variables and mixins to avoid repeating code.
Start with general styles and move to specific ones to avoid conflicts.
ITCSS organizes CSS into layers from general to specific.
SASS makes writing and managing these layers easier with variables and mixins.
Using ITCSS with SASS helps keep your styles clean, reusable, and easy to maintain.
Practice
Solution
Step 1: Understand ITCSS structure
ITCSS organizes CSS layers from very general styles to very specific ones.Step 2: Connect ITCSS with maintainability
This layering helps keep styles clean and easy to maintain by controlling specificity and order.Final Answer:
To arrange styles from general to specific for better maintainability -> Option CQuick Check:
ITCSS = organize styles general to specific [OK]
- Thinking ITCSS means one big file
- Believing ITCSS avoids variables
- Confusing ITCSS with inline styles
Solution
Step 1: Recall ITCSS layer order
The correct ITCSS order starts with Settings (variables), then Tools (mixins), Generic (resets), Elements, Objects, Components, and finally Utilities.Step 2: Match options with this order
Only Settings, Tools, Generic, Elements, Objects, Components, Utilities lists the layers in this exact order from general to specific.Final Answer:
Settings, Tools, Generic, Elements, Objects, Components, Utilities -> Option BQuick Check:
ITCSS order = Settings to Utilities [OK]
- Mixing up Utilities and Settings order
- Placing Components before Objects
- Confusing Generic with Settings
@import 'settings';
@import 'tools';
@import 'generic';
@import 'elements';
@import 'objects';
@import 'components';
@import 'utilities';What will be the color of a button if:
- Settings define $primary-color: blue;
- Components style button background as $primary-color;
- Utilities override button background to red;
Assuming no other styles affect the button, what color will it show?
Solution
Step 1: Understand import order and CSS cascade
ITCSS imports from general to specific. Utilities are last and have highest specificity.Step 2: Determine which style applies last
Utilities override Components because they come later, so button background becomes red.Final Answer:
Red -> Option DQuick Check:
Last imported style wins = Red [OK]
- Assuming Components override Utilities
- Ignoring import order effect
- Thinking variables change color directly
@import 'utilities';
@import 'components';
@import 'objects';
@import 'elements';
@import 'generic';
@import 'tools';
@import 'settings';What is the main problem with this order?
Solution
Step 1: Check ITCSS recommended import order
ITCSS requires importing from Settings to Utilities, not the reverse.Step 2: Identify consequence of reversed order
Importing Utilities first means general styles override specific ones, breaking intended cascade.Final Answer:
The layers are imported in reverse order, causing specificity issues -> Option AQuick Check:
Reverse import order breaks ITCSS layering [OK]
- Thinking missing variables cause import order errors
- Confusing mixins usage with import order
- Believing utilities come before settings
.card {
@include box-shadow($shadow-color);
background-color: $card-bg;
}Solution
Step 1: Identify what a card represents
A card is a reusable UI component with specific styles and structure.Step 2: Match card to ITCSS layer
Components layer holds reusable UI parts like buttons, cards, modals.Final Answer:
In the Components layer, because cards are reusable UI parts -> Option AQuick Check:
Reusable UI parts = Components layer [OK]
- Placing cards in Utilities or Settings layers
- Confusing Generic with Components
- Thinking cards are just variables
