Frame
The outer surface separates one item from the page.
Cards group related content and actions. Good card CSS creates structure without turning every section into a decorative box.
.card {
display: grid;
gap: 1rem;
padding: 1rem;
border: 1px solid var(--line);
}
Component mental model
A card should package a piece of content so it can be scanned, compared or selected. It might hold a lesson, product, article, feature or dashboard item.
Strong card design depends on spacing, hierarchy, media treatment and clear actions. Weak cards become visual clutter.
Cards are useful for repeated items. They should not be used as a default page section style for everything.
The outer surface separates one item from the page.
Title, metadata, text and actions need a clear order.
Images need stable aspect ratio and cropping rules.
A card should make the next step obvious when needed.
Visual model
The image area reserves predictable space.
Headings and copy have calm spacing.
Labels support scanning.
The card points to a clear action.
Good CSS versus fragile CSS
.card {
display: grid;
gap: 1rem;
padding: 1rem;
border: 1px solid var(--line);
border-radius: 1rem;
}
.card__media { aspect-ratio: 16 / 9; object-fit: cover; }
section, header, footer, main, article {
padding: 30px;
border-radius: 30px;
box-shadow: 0 20px 80px #000;
}
Rules of thumb
Cards work best when users compare similar pieces of content.
A card should not contain five unrelated ideas.
Images should not make grids jump while loading.
Cards inside cards usually create visual noise.
Long titles and descriptions should still look intentional.
If the whole card is clickable, focus and hover states must make that clear.
Production thinking
Cards are powerful when they help scanning. They are weak when they become decoration without information structure.
Avoid wrapping a card in a link when it contains multiple interactive controls. Keep focus order clear.
Test cards with short, long and missing content. Real data always finds weak spacing.
Cards can expose clear headings and links for repeated content, but the semantic HTML still matters.
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
Making an entire card clickable can be convenient, but nested links and hidden focus traps create bad interaction.
Use when the card has one primary destination and no competing interactive controls.
Use a clear action link when the card contains more than one possible action.
Make the focused clickable area visually obvious.