Layered Components
In this assignment you will take the architecture concepts from this unit and apply them to a real project. You will style a multi-component page using a layered file structure with @layer, simplify selectors using modern pseudo-class functions, and add accessible focus states to every interactive element. The HTML is provided so you can focus entirely on the CSS.
Preparation
Download the Layered Components starter files and extract them into a new directory in your portfolio at unit-2/layered-components/. The zip contains an index.html file and a css/ directory with the full file structure already in place. Your Unit 2 directory tree should look like this after extraction:
[portfolio]
├── unit-2/
│ └── layered-components/
│ ├── index.html
│ └── css/
│ ├── base/
│ │ ├── elements.css # Update
│ │ └── reset.css # Update
│ ├── components/
│ │ ├── buttons.css # Update
│ │ ├── cards.css # Update
│ │ ├── forms.css # Update
│ │ ├── nav.css # Update
│ │ └── temples.css # Update
│ ├── layout/
│ │ └── primary.css
│ ├── tokens/
│ │ ├── colors.css # Update
│ │ └── variables.css # Update
│ ├── utilities/
│ │ └── utilities.css # Update
│ └── main.css
├── index.html # Update: Add Link
└── README.md # Update: Pages Links
Open css/main.css and review it. The layer declaration and all @import statements are already wired up for you. Your job is to fill in the individual CSS files. Do not modify main.css or the HTML.
The css/layout/primary.css file is also pre-written. It handles the overall page structure so you can focus on tokens, base elements, components, and utilities.
Assignment Instructions
1. Define Your Tokens
Open css/tokens/colors.css and css/tokens/variables.css. Define custom properties on :root for all of your design decisions. Your token set must include at least:
- Four color tokens covering primary, background, text, and accent
- Three spacing tokens at different scales (small, medium, large)
- A font family token
- A border radius token
Name every token by purpose rather than appearance. Use --color-primary, not --blue. Every style you write in other files should reference these tokens with var(). Hardcoded values should be rare and intentional.
2. Style Base Elements
Open css/base/elements.css and style the bare HTML elements: body, headings, links, and lists. Use only element selectors in this file, no classes. This layer sets the foundation so that the page looks reasonable even before any component styles load. Use native nesting where it makes sense, such as nesting link hover states inside a link rule.
3. Build Your Components
This is where most of your work will happen. Each component has its own file inside css/components/. Open each file and style the corresponding part of the page. A few specific requirements:
-
Use
:is()or:where()at least once to group selectors that share the same styles. For example, you might use:is()to style all form inputs (text, textarea, select) with a single rule. -
Use
:not()at least once. For example, you might style all buttons that are not disabled, or all nav links that are not the current page. -
Add
:focus-visiblestyles to every interactive element: links, buttons, and form inputs. The focus ring should be clearly visible on keyboard navigation but should not appear on mouse click. -
The cards should display in a responsive grid or flex layout. Use
clamp()orcalc()with your tokens for at least one fluid value (card padding, heading size, or grid gap). -
Use native CSS nesting throughout. Follow the nesting conventions from Unit 1: do not use
&for descendant selectors, only for pseudo-classes, compound selectors, or reversing context.
4. Add Utilities
Open css/utilities/utilities.css and add at least two utility classes. These should be small, single-purpose helpers. Because they live in the last declared layer, they will override component styles by layer order without needing !important.
5. Update Your Homepage and README
Add a link to this assignment on your portfolio homepage and in your README.md under the Pages section, following the same pattern from previous assignments.
6. Commit, Push, and Verify
Stage your changes, commit with a descriptive message, and push to GitHub. Verify the deployment succeeds and your page loads with styles applied on your live site. Test keyboard navigation to confirm your :focus-visible styles work. Check the page at different browser widths to confirm your responsive layout adapts.
Submission
Complete the report below with your site details and reflections. When you are finished, click the download button to generate a PDF and submit it to Canvas.
My live layered components page is at and the source code is at .
You are starting a new project that uses a third party CSS library. Write a layer declaration with no more than four layers and include a vendor layer. For each layer, explain what kind of CSS belongs in it and why that layer needs to be in that position relative to the others.
In this assignment you used :is(), :where(), or both to simplify selectors in your component files. Explain the difference between them. In a project where you are writing base element styles that other developers will override with component classes later, which would you choose and why?
After working through this layered file structure, what is one thing you would change about how you organized your CSS in the Unit 1 custom properties assignment? Be specific about what you would move, split, or rename and why.