CSS Organization & Architecture Ideas for Projects
CSS Organization Strategies
1. By Cascade Order (Foundation → Components → States)
1. :root variables
2. Base elements (body, ul, li, a)
3. Layout components (header, project-item, project-name)
4. UI components (icons, status indicators, warnings)
5. Status modifiers (status-in-progress, status-complete, etc.)
6. Special cases (reference folder, root directory)
7. Media queries
2. By Component Hierarchy (Parent → Child)
1. :root variables
2. Base/reset styles
3. Header (header, h1, h2)
4. Project item (project-item → project-name → project-files)
5. Status system (status-indicator, status-label, status-message)
6. Icons (folder-icon, warning-icon)
7. Utilities (unavailable, txt-warning)
8. Media queries
3. By Concern (Layout → Typography → Colors → Interactions)
1. :root variables (grouped by type)
2. Layout (body, header, project-item, flex/grid)
3. Typography (font-family, font-size, font-weight)
4. Colors (all color declarations together)
5. Interactions (hover states, all together)
6. Media queries
4. By Specificity (Low → High)
1. :root, body, element selectors
2. Single class selectors
3. Compound selectors (.project-item.status-*)
4. Pseudo-elements (::before, ::after)
5. Pseudo-classes (:hover)
6. Attribute selectors (:has, [class*])
Strategic Architecture Feedback
Current Approach Assessment
Strengths:
- ✅ CSS variables for maintainability
- ✅ Semantic class names (
status-in-progress,project-item) - ✅ Good consolidation of shared styles
- ✅ Lightweight, no framework overhead
Potential Brittleness:
- Tight coupling to HTML structure: Selectors like
.project-item.status-in-progress .project-name aassume specific DOM structure - Status system coupling: Status colors are hardcoded in multiple places
- No component boundaries: Everything is in one file, harder to extract components
Recommendations for Reusability
Option 1: Component-Based CSS Architecture
Break into logical components that can be reused:
/* components/project-tracker.css */
.project-tracker { /* base styles */ }
.project-tracker__item { /* project-item */ }
.project-tracker__name { /* project-name */ }
.project-tracker__status { /* status system */ }
Pros: Clear boundaries, easier to extract
Cons: More verbose, requires HTML changes
Option 2: Utility-First with Semantic Base (Recommended)
Keep semantic classes but add utility classes for common patterns:
/* Keep your current semantic classes */
.project-item { }
/* Add reusable utilities */
.text-bold { font-weight: bold; }
.text-normal { font-weight: normal; }
.color-inactive { color: var(--gray-dark); }
.bg-hover-orange:hover { background: var(--orange); }
Pros: Flexible, can mix semantic + utility
Cons: Can lead to class soup if overused
Option 3: CSS Custom Properties for Theming
Make the status system themeable:
:root {
--status-in-progress-color: var(--orange);
--status-complete-color: var(--text-color);
--status-inactive-color: var(--gray-dark);
}
.project-item[data-status="in-progress"] {
--status-color: var(--status-in-progress-color);
color: var(--status-color);
}
Pros: Very flexible, easy to theme
Cons: Requires HTML data attributes
For Markdown/Todo Reuse
-
Extract a “status-tracker” component
- Create a reusable status system that works with any list
- Use data attributes:
data-status="in-progress"
-
Create a design system file
/* design-system.css - reusable across projects */ :root { /* All your variables */ } /* Base styles that work for any tracker */ .tracker-item { } .tracker-status { } -
Use CSS Layers (modern browsers)
@layer base, components, utilities; @layer base { /* Reset, variables */ } @layer components { /* Your project-specific components */ } -
Consider a naming convention
- Current: Semantic but flat (
.project-item.status-in-progress) - Alternative: BEM-like but simpler (
.project-item--in-progress) - Or: Data-driven (
.project-item[data-status])
- Current: Semantic but flat (
Specific Recommendations
- Group status rules together: All status-related CSS in one section
- Extract hover pattern: Create a reusable hover utility or mixin pattern
- Document the status system: Add comments explaining the status hierarchy
- Consider CSS nesting (when widely supported): Reduces repetition
- Create a “tracker” base class: Make it work for projects, todos, or any list