Default
The ordinary resting state.
Component states describe how a component behaves across normal, hover, focus, active, disabled, loading, selected and error situations.
.tab[aria-selected="true"] { background: var(--green); }
.tab:focus-visible { outline: 3px solid var(--focus); }
.tab[data-loading="true"] { opacity: .55; }
Component mental model
The default state is only one version of a component. Real users hover, focus, press, wait, fail validation and encounter disabled actions.
Good component CSS plans states before launch. Otherwise every edge case becomes an emergency override.
States can come from pseudo-classes such as :hover and :focus-visible, attributes such as disabled and aria-selected, or data attributes from JavaScript.
The ordinary resting state.
Hover, focus and active communicate response.
Loading, disabled and selected communicate status.
Problem states need clear recovery paths.
Visual model
The component can be used.
Pointer users see feedback.
Keyboard users see position.
The action is in progress.
Good CSS versus fragile CSS
.tab[aria-selected="true"] { background: var(--green); color: #061018; }
.tab:focus-visible { outline: 3px solid var(--focus); }
.tab[disabled], .tab[data-loading="true"] { opacity: .55; cursor: not-allowed; }
.tab {
background: black;
color: white;
}
Rules of thumb
Write down every state before polishing visuals.
Focus is a required state, not browser decoration.
disabled, aria-selected and aria-invalid can drive CSS and meaning.
Prevent duplicate actions and communicate waiting.
Selected and hover should not look identical.
State changes should feel responsive, not slow.
Production thinking
States are where a design system proves whether it is real. Static components look fine in screenshots and fail in use.
State styling must match semantic state where possible. Visual selected state without aria-selected can confuse assistive technology.
Create state checklists for every reusable component before shipping.
Component states mainly affect usability, but usability affects whether users trust and complete tasks.
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 a state, long label or mobile width breaks the component, the component is not finished yet.
Senior audit upgrade
A component is not finished when the default state looks good. List every state and design the transitions between them.
Default, hover, focus, active and disabled.
Loading, error, success, selected and open.
Empty, long text, dense data and small screen.
Chapter project
Style buttons, cards, navigation, forms, tables, modals, badges and states as one coherent system.
an accessible component set with hover, focus, disabled, loading and error states
Can the component be reused on another page without rewriting its CSS?