Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
Organize CSS logically and consistently
Use clear, descriptive class names
Write reusable, modular code
Optimize for performance
Make CSS accessible and maintainable
Follow industry standards
Group related styles together
base.css, layout.css, components.cssUse descriptive class names
.user-profile-card not .box2Don't repeat yourself
One .button class, not 10 versionsOptimize for performance
Minimize CSS, avoid expensive selectors/* ✅ GOOD: Organized by sections with clear comments */
/* ======================
Variables
====================== */
:root {
--color-primary: #3b82f6;
--spacing-unit: 8px;
}
/* ======================
Typography
====================== */
h1 { font-size: 32px; }
h2 { font-size: 24px; }
p { line-height: 1.6; }
/* ======================
Components
====================== */
.button {
padding: 12px 24px;
background: var(--color-primary);
}
.card {
padding: 20px;
border: 1px solid #e5e7eb;
}/* ❌ BAD: Everything mixed together, no structure */
.button { padding: 12px 24px; }
h1 { font-size: 32px; }
.card { padding: 20px; }
p { line-height: 1.6; }
h2 { font-size: 24px; }
.button { background: #3b82f6; } /* Duplicate! */
.card { border: 1px solid #e5e7eb; }/* ✅ GOOD: Descriptive, consistent naming */
.user-profile-card { }
.user-profile-card__avatar { }
.user-profile-card__name { }
.user-profile-card--featured { }
/* Use BEM (Block Element Modifier) */
.block { } /* Component */
.block__element { } /* Part of component */
.block--modifier { } /* Variation */
/* ❌ BAD: Unclear, inconsistent naming */
.box { }
.userCard { } /* Inconsistent casing */
.user_profile { } /* Mixed conventions */
.blue { } /* Style-based */
.new-final-v2 { } /* Meaningless *//* ✅ GOOD: One button class, modified with utilities */
.button {
padding: 12px 24px;
font-size: 16px;
border: none;
border-radius: 6px;
cursor: pointer;
}
.button--primary { background: #3b82f6; color: white; }
.button--secondary { background: #6b7280; color: white; }
.button--large { padding: 16px 32px; font-size: 18px; }
.button--small { padding: 8px 16px; font-size: 14px; }
/* Combine classes in HTML */
/* <button class="button button--primary button--large">Click Me</button> *//* ❌ BAD: Repeating the same styles everywhere */
.submit-button {
padding: 12px 24px;
font-size: 16px;
background: #3b82f6;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
.cancel-button {
padding: 12px 24px; /* Duplicated! */
font-size: 16px; /* Duplicated! */
background: #6b7280;
color: white;
border: none; /* Duplicated! */
border-radius: 6px; /* Duplicated! */
cursor: pointer; /* Duplicated! */
}
.big-submit-button {
padding: 16px 32px;
font-size: 18px;
background: #3b82f6;
color: white;
border: none; /* Still duplicating! */
border-radius: 6px;
cursor: pointer;
}.button { } /* Fast: class selector */
#header { } /* Fast: ID selector */
.nav .item { } /* Okay: 2 levels */div div div div { } /* Slow: too many levels */
* { } /* Slow: universal selector */
[class*="btn"] { } /* Slow: attribute selector with wildcard */
.nav > ul > li > a { } /* Slow: overly specific *//* ✅ GOOD: Performance-friendly CSS */
/* 1. Keep selectors shallow (max 3 levels) */
.card { }
.card__title { } /* Better than .card .container .title */
/* 2. Avoid expensive properties where possible */
.box {
/* Fast */
transform: translateX(10px);
opacity: 0.5;
/* Avoid if possible */
/* box-shadow: 0 0 50px 50px rgba(0,0,0,0.5); (expensive) */
/* filter: blur(10px); (expensive) */
}
/* 3. Use CSS variables for repeated values */
:root {
--primary-color: #3b82f6;
--spacing: 16px;
}
.button {
background: var(--primary-color);
padding: var(--spacing);
}
/* 4. Minimize and combine CSS files */
/* Use build tools to minify and combine CSS */<div class="container">
<header class="site-header">
<h1 class="site-header__title">My Website</h1>
<nav class="site-header__nav">
<a href="#" class="nav-link nav-link--active">Home</a>
<a href="#" class="nav-link">About</a>
<a href="#" class="nav-link">Contact</a>
</nav>
</header>
<main class="main-content">
<article class="card">
<h2 class="card__title">Article Title</h2>
<p class="card__text">This example demonstrates clean CSS with good organization,
clear naming (BEM), and reusable classes.</p>
<button class="button button--primary">Read More</button>
</article>
<article class="card card--featured">
<h2 class="card__title">Featured Article</h2>
<p class="card__text">This card uses the same base styles but has a "featured" modifier.</p>
<button class="button button--primary button--large">Learn More</button>
</article>
</main>
</div>Loading preview...
Define colors, spacing, and fonts once. Change everywhere instantly.
:root { --primary: #3b82f6; }Start with mobile styles, then add desktop styles with media queries.
@media (min-width: 768px) { ... }Explain complex CSS, mark sections, and note browser hacks.
/* Header Component - Used on all pages */If you need !important, your CSS structure probably needs improvement.
color: red !important; /* Try to avoid */Use tools like CSS Validator to catch errors and improve quality.
jigsaw.w3.org/css-validator/Don't just test in Chrome. Check Firefox, Safari, and Edge too.
Multiple developers need consistency
Thousands of lines of CSS
Code maintained for years
Performance matters