Responsive CSS Content Cards
This example demonstrates how to create reusable content cards using HTML and CSS. Each card includes a visual header, category label, heading, description, and action link. The cards automatically adjust to different screen sizes using CSS Grid.
HTML
Web Development
HTML Basics
Learn how to structure webpages using HTML elements, headings, paragraphs, links, and other essential markup.
Learn More
CSS
Web Design
CSS Styling
Discover how to style webpages with colors, typography, backgrounds, borders, spacing, and modern layout techniques.
CSS allows you to create consistent designs across multiple pages.
Learn More
Responsive
Responsive Design
Mobile-Friendly Layouts
Create flexible layouts that adapt to desktops, tablets, and mobile devices.
Learn More
Flexbox
CSS Layouts
Flexbox Layouts
Use CSS Flexbox to arrange elements in rows or columns with flexible sizing, spacing, and alignment.
Learn More
Grid
CSS Layouts
CSS Grid Layouts
Build organized two-dimensional layouts using CSS Grid. Control rows, columns, spacing, and element placement with flexible grid properties.
CSS Grid is particularly useful for galleries, dashboards, and content collections.
Learn More
Effects
CSS Effects
Transitions and Effects
Enhance webpage components with hover effects, transitions, transforms, and other visual styling techniques.
Learn More
Try It: Resize the browser window to see the cards automatically rearrange into fewer columns. Move your mouse over each card to see the lift and shadow effects. Select a Learn More link to jump to its corresponding information section.
How Content Cards Work
Content cards organize related information into reusable visual components.
Each card uses an HTML article element containing a visual header, category label, heading, description, and action link.
The content-card class defines the card's appearance, including its background, border, rounded corners, and shadow.
Using a consistent structure makes it easier to add, remove, or rearrange cards without changing the overall design.
Creating the Card Grid
The card container uses CSS Grid to arrange cards into responsive columns.
The following CSS creates the flexible layout:
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
gap: 25px;
The display: grid declaration establishes a CSS Grid container.
The repeat() function generates the columns, while auto-fit allows the number of columns to adjust according to the available space.
The minmax() function defines the minimum and maximum column sizes.
The nested min() function prevents a column from exceeding the container width on narrow screens.
The gap property creates consistent spacing between cards.
Creating Equal-Height Cards
Each content card uses display: flex and flex-direction: column to arrange its internal content vertically.
The flex-grow: 1 declaration allows the card content area to expand and occupy the available height.
The action link uses margin-top: auto to push it toward the bottom of the card.
This keeps the Learn More links aligned at the bottom of cards in the same row, even when their descriptions contain different amounts of text.
Adding Card Hover Effects
The :hover pseudo-class applies visual changes when the pointer moves over a card.
The following CSS moves the card upward and increases its shadow:
.content-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}
The transform property changes the card's visual position without affecting the surrounding layout.
The box-shadow property creates a sense of depth.
The transition property makes the changes appear smooth.
Responsive Card Design
The CSS Grid layout automatically adjusts the number of columns as the available width changes.
Wider screens can display several cards per row, while narrower screens display fewer columns.
On small screens, the cards eventually appear in a single column.
A media query at 600 pixels or less reduces spacing, padding, and visual header height to improve the mobile layout.
Content Card Accessibility
Use descriptive headings and meaningful link text so visitors can understand the purpose of each card.
When cards represent independent pieces of content, the HTML article element provides an appropriate semantic structure.
Keyboard users can navigate to the Learn More links using the Tab key.
The :focus-visible pseudo-class provides a visible focus indicator for keyboard navigation.
The prefers-reduced-motion media query disables the card movement and transitions for visitors who request reduced motion.
Ensure that text and background colors provide sufficient contrast for readability.
Customizing Content Cards
You can change the card backgrounds, borders, shadows, and rounded corners to match your website's design.
Modify the 280px value in the grid declaration to control the preferred minimum width of each card.
Increase or decrease the gap property to adjust the spacing between cards.
You can replace the colored visual headers with images, icons, or other content.
To add another card, duplicate an existing article element with the content-card class and update its content.
For a production website, replace the demonstration fragment links with appropriate destinations.
Card Information Sections
The following sections provide working destinations for the Learn More links in the example cards.
HTML Basics
HTML provides the structure of a webpage. Elements such as headings, paragraphs, links, images, and lists organize content into meaningful sections.
CSS Styling
CSS controls the visual presentation of HTML elements, including colors, typography, spacing, borders, backgrounds, and layout.
Mobile-Friendly Layouts
Responsive design uses flexible layouts, relative sizing, and media queries to create webpages that work across different screen sizes.
Flexbox Layouts
CSS Flexbox provides a flexible way to arrange and align elements along a single main axis, making it useful for navigation, cards, and interface components.
CSS Grid Layouts
CSS Grid provides a two-dimensional layout system that controls rows and columns, making it suitable for complex webpage layouts and responsive content collections.
Transitions and Effects
CSS transitions, transforms, and shadows can enhance visual feedback and improve the appearance of interactive webpage components.