Boundary
Know what belongs inside the component.
Component CSS packages reusable interface behavior, structure and states without leaking random styles across the whole site.
.alert {}
.alert__title {}
.alert--success {}
.alert[data-state="hidden"] { display: none; }
Architecture mental model
Component CSS describes a reusable UI piece: a button, card, nav item, alert, modal, form field or lesson tile.
Good component CSS knows its own parts and states. It does not depend on a specific page location unless that dependency is part of the component contract.
The goal is to make a component portable enough to reuse and strict enough to remain visually consistent.
Know what belongs inside the component.
Name inner elements that need styling hooks.
Define supported visual versions.
Style active, disabled, open, selected and error states intentionally.
Visual model
The reusable component wrapper.
Internal structure belongs to the component.
Supported visual version.
Runtime condition changes styling.
Good CSS versus fragile CSS
.alert {}
.alert__title {}
.alert--success {}
.alert[data-state="dismissed"] { display: none; }
.homepage main div:nth-child(3) .box h2 {
color: green;
}
Rules of thumb
Know what the component owns and what the parent layout owns.
Component selectors should not depend on deep page structure.
Hover is not enough. Think disabled, selected, error, open and loading.
A component should not accept infinite random visual changes.
The parent layout decides where a component sits. The component decides how it looks internally.
Long titles, missing images and extra buttons reveal weak component CSS.
Production thinking
Component CSS is what turns a one-page design into a reusable product interface.
Component states should match accessible state attributes where possible, such as aria-expanded, aria-current or disabled.
Every reusable component should have a content stress test and a state checklist.
Reusable components still need semantic HTML inside. CSS should not force headings, links or buttons into the wrong elements.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If you cannot find, name or move a rule safely, the architecture still needs work.
Senior audit upgrade
Component CSS should own inner structure, variants and states. Outer grid placement and page spacing should usually belong outside the component.
Internal spacing, states, variants and child layout.
Page grid columns, outer section margins and one-off page exceptions.
A component should be usable in more than one layout context.