CSS Theming System Implementation
In this assignment, you will implement a complete theming system for a product showcase website. You will apply the CSS architecture patterns and theming techniques you learned this week, creating a professional-looking site that supports both light and dark modes with smooth transitions and proper color organization.
This assignment synthesizes everything you have learned: CSS custom properties, color functions including color-mix(), modern selectors, CSS nesting, and component-based organization following CUBE CSS or BEM principles. You will work with provided HTML and JavaScript, focusing entirely on creating maintainable, well-organized CSS.
Assignment Overview
You are provided with HTML structure for a product showcase page and complete JavaScript for theme management. Your task is to create all CSS from scratch, implementing a theming system that supports light and dark modes, uses modern CSS features, and follows proper architectural patterns.
Learning Objectives
- Implement a complete theming system using CSS custom properties
-
Use
color-mix()to generate color variations programmatically -
Apply
prefers-color-schemefor automatic theme detection - Organize CSS using CUBE CSS or BEM architectural patterns
- Use CSS nesting to create maintainable, well-structured stylesheets
- Create responsive layouts using modern CSS techniques
Setup Instructions
1. Download Starter Files
Download the starter files from theming-system.zip. Extract the files and you will find:
-
index.html— Complete HTML structure (do not modify) -
theme.js— Complete theme management JavaScript (do not modify) -
styles.css— Empty stylesheet where you will write all CSS
2. Add to Your Portfolio
Create a new directory in your portfolio for this assignment:
portfolio/
└── unit-2/
└── theming-system/
├── index.html
├── theme.js
└── styles.css
3. Understand the HTML Structure
Open index.html in your browser. The page will appear unstyled initially. Review the HTML structure to understand the components you need to style:
- Header with site title and theme toggle button
- Hero section with welcome message and description
- Filter buttons for product categories
- Product grid with multiple product cards
- Footer with copyright information
You will be warned several times during this assignment and in the code comments not to modify the HTML structure but there is one exception. If you choose to use BEM, you may modify the class names in the HTML to match the BEM naming convention.
4. Review the JavaScript
The provided theme.js file handles all theme management functionality. It detects system preferences, manages the theme toggle, and persists user choices to localStorage. Your CSS needs to work with the .dark-theme class that JavaScript adds to the document root.
Requirements
Your CSS implementation must meet all of the following requirements. Each requirement demonstrates your understanding of modern CSS architecture and theming techniques.
1. Theme System with Custom Properties
- Define a complete color system using CSS custom properties
-
Create semantic color names (e.g.,
--color-background,--color-text,--color-primary) - Implement light theme as the default
-
Implement dark theme using the
.dark-themeclass -
Support
prefers-color-schemefor automatic theme detection
2. Use color-mix() for Theme Variations
-
Generate at least one color scale using
color-mix() - Create lighter and darker variations of your primary color
-
Use
color-mix()to create hover and active states - Demonstrate understanding of color space selection (use oklch)
3. Follow CSS Architecture Patterns
- Choose either CUBE CSS or BEM for organizing your CSS
- Clearly separate concerns (base styles, layout, components, utilities)
- Use composition classes for layout patterns if following CUBE CSS
- Use consistent naming conventions throughout
- Document your architectural choice in comments
4. Use Modern CSS Features
- Use CSS nesting throughout your stylesheet
-
Apply modern selectors (
:is(),:where(),:has()) where appropriate -
Use logical properties (e.g.,
margin-inline,padding-block) - Implement smooth transitions between themes
5. Create Responsive Layout
- Product grid must be responsive (use CSS Grid or Flexbox)
- Layout should work on mobile, tablet, and desktop screens
- Images must scale appropriately
- Navigation and buttons must be usable on all screen sizes
6. Ensure Accessibility
- Maintain sufficient color contrast in both themes (test with browser DevTools)
- Provide visible focus indicators for keyboard navigation
-
Respect
prefers-reduced-motionfor theme transitions - Ensure all interactive elements are clearly distinguishable
7. Polish and Details
- Style the theme toggle button to indicate current state
- Add hover and active states for interactive elements
- Create visual hierarchy with typography and spacing
- Make the design cohesive and professional-looking
Implementation Strategy
1. Plan Your Color System
Before writing any CSS, plan your color palette. Choose a primary brand color and decide how it will work in both light and dark themes. Sketch out your semantic color variables and think about which colors need variations.
2. Set Up Your Architecture
Decide whether you will use CUBE CSS or BEM. Structure your CSS file with clear sections and comments. If you choose to create multiple CSS files for better organization, that is acceptable and even encouraged.
3. Define Custom Properties
Start by defining all your custom properties in the :root selector. Create your base color palette, then define semantic colors that reference the base colors. Set up the dark theme overrides in the .dark-theme selector.
4. Build Base Styles
Create your reset or normalize styles, set up typography, and establish base element styles. This is your foundation layer that everything else builds upon.
5. Create Layout Patterns
Build your layout system. If using CUBE CSS, create composition classes like .flow and .grid. Style the main structural elements: header, main content area, and footer.
6. Style Components
Style individual components: buttons, cards, navigation, filter buttons, and the theme toggle. Ensure each component works in both themes and includes all necessary states (hover, focus, active).
7. Add Responsive Behavior
Implement media queries to make the layout responsive. Test at multiple screen sizes and adjust as needed.
8. Test and Refine
Test both themes thoroughly. Check color contrast, verify all interactive states work, and ensure the layout responds properly at all screen sizes. Use browser DevTools to validate your implementation.
Example Patterns
Here are some patterns you should implement in your CSS:
Theme Variable Structure
:root {
/* Base palette */
--blue-50: oklch(0.5 0.15 250);
/* Semantic colors - light theme */
--color-background: oklch(0.98 0 0);
--color-text: oklch(0.2 0 0);
--color-primary: var(--blue-50);
}
.dark-theme {
/* Semantic colors - dark theme */
--color-background: oklch(0.15 0 0);
--color-text: oklch(0.95 0 0);
}
/* Support system preference */
@media (prefers-color-scheme: dark) {
:root:not(.dark-theme):not(.light-theme) {
--color-background: oklch(0.15 0 0);
--color-text: oklch(0.95 0 0);
}
}
Using color-mix()
:root {
--color-primary: oklch(0.5 0.15 250);
/* Generate variations */
--color-primary-light: color-mix(in oklch, var(--color-primary) 60%, white);
--color-primary-dark: color-mix(in oklch, var(--color-primary) 80%, black);
/* Hover states */
--color-primary-hover: color-mix(in oklch, var(--color-primary) 90%, black);
}
Component with Nesting
.card {
background: var(--color-surface);
border-radius: 0.5rem;
padding: 1.5rem;
h3 {
color: var(--color-heading);
margin: 0 0 0.5rem 0;
}
p {
color: var(--color-text-secondary);
line-height: 1.6;
}
&:hover {
box-shadow: 0 0.25rem 1rem var(--color-shadow);
}
}
Composition Classes (CUBE CSS)
.flow > * + * {
margin-block-start: var(--flow-space, 1rem);
}
.grid {
display: grid;
gap: var(--grid-gap, 2rem);
grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
}
Testing Checklist
Before submitting, verify that your implementation meets these criteria:
- Light theme looks professional and polished
- Dark theme looks professional and polished
- Theme toggle button works correctly
- System theme preference is respected on first load
- Theme preference persists across page reloads
- Color contrast meets accessibility standards (use browser DevTools)
- Focus indicators are visible for keyboard navigation
- Layout is responsive at mobile, tablet, and desktop sizes
- All interactive elements have hover and active states
- Product grid displays properly with consistent image sizes
- Filter buttons provide visual feedback when active
- Typography creates clear visual hierarchy
- Transitions between themes are smooth (if motion not reduced)
Submission
Once you have completed your implementation and tested thoroughly, document your work and submit it for evaluation. Complete the form below with your implementation details and design decisions, then download the PDF and submit it to Canvas.
Evaluation Criteria
Your theming system will be evaluated on how effectively it demonstrates modern CSS techniques and creates a polished, accessible user experience:
- Theme Implementation: Does your theming system work correctly in both light and dark modes? Does it respect system preferences and persist user choices?
-
Color System: Have you effectively used custom properties and
color-mix()to create a maintainable color system? - Architecture: Is your CSS well-organized following CUBE CSS or BEM principles? Is the code maintainable and easy to understand?
- Modern CSS: Have you used CSS nesting, modern selectors, and logical properties appropriately?
- Responsive Design: Does the layout work well on all screen sizes? Are images and components properly responsive?
- Accessibility: Does the site meet color contrast requirements? Are focus indicators visible? Is reduced motion respected?
- Code Quality: Is your CSS clean, well-commented, and following best practices?
- Visual Design: Does the site look professional and polished? Is there clear visual hierarchy?
Tips for Success
- Start with color planning: Choose your colors carefully and test them in both themes before writing extensive CSS
- Test themes early and often: Switch between themes frequently while developing to catch issues early
- Use browser DevTools: The contrast checker and color picker in DevTools are invaluable for accessibility
- Keep it simple: You have 2 hours. Focus on a clean, functional implementation rather than excessive decoration
- Comment your code: Document your architectural decisions and any complex patterns you use
- Test responsive behavior: Use browser DevTools device mode to test at multiple screen sizes
- Check your contrast: Use browser DevTools Lighthouse audit or the contrast checker to verify accessibility
- Respect the time limit: This is about demonstrating understanding, not creating pixel-perfect artwork