What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
An image card in CSS is a reusable component that combines an image with a heading, supporting text, and optionally a footer. Use semantic HTML, CSS Grid for a responsive collection, and choose object-fit according to whether the image may be cropped. The pattern below keeps cards aligned across screen sizes without stretching images.
Start with semantic card markup
An image that communicates information belongs in an <img> element with useful alternative text. A heading gives each card a clear name, while a paragraph supplies context. Use an <article> when each card could stand alone, such as a product, story, profile, or project preview.
<section class="cards" aria-label="Featured projects">
<article class="card">
<header class="card__header">
<h2>Alpine cabin</h2>
</header>
<img
class="card__image"
src="images/alpine-cabin.jpg"
alt="A wooden cabin beside an alpine lake"
width="1200"
height="800"
loading="eager"
>
<div class="card__body">
<p>A compact retreat designed for four-season use.</p>
<a href="/projects/alpine-cabin">View project</a>
</div>
<footer class="card__footer">Updated June 2026</footer>
</article>
</section>
Replace the alternative text with the image’s meaningful subject. If an image is purely decorative and the surrounding text already communicates everything, use alt="" rather than repeating the caption. Width and height attributes let the browser reserve space before the file arrives, reducing layout movement. Add loading="lazy" to cards below the initial viewport; do not lazy-load the main above-the-fold image by default.
Build a responsive card collection with CSS Grid
* {
box-sizing: border-box;
}
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
gap: 1.25rem;
max-width: 72rem;
margin-inline: auto;
padding: 1rem;
}
.card {
display: grid;
grid-template-rows: max-content 12rem 1fr max-content;
overflow: hidden;
border: 1px solid #999;
border-radius: 0.5rem;
background: #fff;
color: #17202a;
}
.card__header,
.card__body,
.card__footer {
padding: 1rem;
}
.card__header h2 {
margin: 0;
font-size: 1.2rem;
}
.card__image {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
.card__body p {
margin-top: 0;
}
.card__footer {
border-top: 1px solid #ddd;
font-size: 0.875rem;
color: #566;
}
repeat(auto-fill, minmax(230px, 1fr)) is a practical starting point, not a browser requirement. Increase the minimum when cards need longer titles or controls; reduce it when a narrow mobile layout is acceptable. The 12rem image row likewise is a design value. The grid’s flexible third row lets descriptions grow, while the footer creates a final content-sized row when present.
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
For a single card, omit .cards and place the component wherever it belongs. Flexbox can also lay out card internals, but Grid is convenient when you want explicit rows and consistent image regions.
Choose the right image fitting rule
| Rule | What it does | Use it when | Trade-off |
|---|---|---|---|
cover |
Scales the image until the box is completely filled while preserving its aspect ratio. | Cards should have equal image heights and a crop is acceptable. | Edges can be cropped, especially on unusually wide or tall source images. |
contain |
Scales the complete image inside the box while preserving its aspect ratio. | The entire object, artwork, document, or product must remain visible. | Unused space can appear on two sides; set a deliberate background color. |
fill |
Fits both dimensions independently. | Almost never for photographic cards. | It can stretch and visibly distort the source. |
Use cover for consistent editorial cards
.card__image {
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}
Check the crop at the narrowest card width. If a face or product sits near an edge, adjust the focal point with values such as object-position: 65% center;. This moves the subject into view; it does not prevent cropping.
Use contain when nothing may be cut off
.product-card__image {
display: block;
width: 100%;
height: 12rem;
object-fit: contain;
background: #f2f4f7;
}
The background fills the bars left by different source ratios. Do not remove the fixed image height unless varying card heights are intentional.
Reserve a ratio with aspect-ratio
.card__media {
aspect-ratio: 4 / 3;
overflow: hidden;
background: #eef1f4;
}
.card__media img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
}
aspect-ratio establishes a predictable media box without hard-coding a height for every viewport. Pair it with object-fit when the source ratio differs. A 4:3 ratio is only an example; choose one that suits the content.
Rank #2
Background images versus content images
Use a CSS background when the visual is decorative or sits behind text. Use an <img> when the image itself conveys information, needs alternative text, can be opened or downloaded, or is part of the content hierarchy.
.hero-card {
min-height: 18rem;
padding: 1.5rem;
color: white;
background-image: linear-gradient(rgb(0 0 0 / 0.35), rgb(0 0 0 / 0.65)),
url("images/forest.jpg");
background-size: cover;
background-position: center 40%;
}
background-size: cover fills the box and may crop; contain shows the whole background but can leave gaps. background-position controls which part remains visible. Because a background has no useful alt attribute, do not use this technique for an informative image without providing its meaning in text.
Make cards robust on small screens
- Keep the grid minimum wide enough for the longest expected heading and link.
- Let body text wrap naturally; avoid fixed card heights that clip content.
- Use
overflow-wrap: anywhere;for untrusted long URLs or identifiers. - Test portrait and landscape source images, not just one perfectly matched file.
- Check keyboard focus, link contrast, and text at increased browser zoom.
.card {
min-width: 0;
}
.card a:focus-visible {
outline: 3px solid currentColor;
outline-offset: 3px;
}
@media (max-width: 30rem) {
.cards {
grid-template-columns: 1fr;
}
}
The explicit one-column breakpoint is optional because auto-fill already responds to available width. It is useful when you want a guaranteed single-column reading order below a known width.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Common problems and fixes
The image is stretched
Stretching usually comes from object-fit: fill, or from setting width and height without preserving the ratio. Use object-fit: cover or contain and make the image a block-level element.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
The subject is cut off
That is expected with cover. Change to contain when the whole image matters, or tune object-position to move the focal subject. Recheck every responsive width because one position cannot guarantee a perfect crop for every ratio.
Cards have uneven image heights
Give the media wrapper an explicit height or aspect-ratio, then set the image to fill that wrapper. Do not rely on each source file having identical dimensions.
There is unexpected whitespace below the image
Inline images align to the text baseline. Set display: block; also verify that a parent’s line-height or padding is not creating the gap.
Recommended Free Tools
The image appears blurry
A small source enlarged into a large card cannot regain detail through CSS. Provide an appropriately sized source, use responsive image attributes such as srcset where your delivery pipeline supports them, and avoid enlarging beyond the asset’s useful resolution.
Rank #4
The layout jumps while images load
Supply intrinsic width and height attributes or reserve space with aspect-ratio. This lets the browser calculate the media box before downloading the image.
Text is unreadable over a background
Add a contrast-tested overlay, move the focal point, or place the text in a solid panel instead. A background image does not guarantee readable text at every crop.
Testing checklist
- Resize from a wide desktop viewport to a narrow phone width and confirm that no heading, link, or image is clipped.
- Test at least one source image that is much wider and one that is much taller than the media box.
- Keyboard-tab through every interactive card and verify a visible focus indicator.
- Disable images or inspect with a screen reader to confirm that alternative text conveys the intended meaning.
- Use browser zoom and high-contrast settings where available; ensure card content remains readable.
- Inspect network behavior and choose lazy loading only for below-the-fold images.
Or skip the browser setup
If you need rendered card screenshots for documentation, visual regression, or social previews, ScreenshotNeo can capture the page with one request. It accepts the cookie or consent banner like a visitor, removes more than 60 known consent platforms plus newsletter popups and chat widgets before capture, and lets you turn each cleanup step off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; the response identifies the page verdict and billing status in headers.
Free tools Windows power users keep installed
One-click scans. No signup required.
For API details and all capture options, see the ScreenshotNeo documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Beyond a basic shot, ScreenshotNeo supports full-page and element capture, dark mode, device presets, custom viewports and retina scale, PDF output, custom CSS and JavaScript, clicks, selector or network-idle waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Create a free ScreenshotNeo account.
Best Value
FAQ
Should every card image use the same aspect ratio?
Use a consistent ratio when a uniform grid is important. Let the ratio vary when preserving the original composition matters more than alignment.
Can I put a link around the entire card?
Yes, when the whole card leads to one destination, but keep the heading structure and ensure the link has a clear accessible name. Avoid nesting separate interactive controls inside that link.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Is CSS Grid required?
No. Grid is a convenient choice for responsive collections; Flexbox or another layout method can work when it better matches the component’s structure.
Frequently Asked Questions
Which object-fit value prevents distortion?
Use cover or contain; both preserve the source aspect ratio. Choose based on whether cropping is acceptable.
How do I keep an image fully visible inside a card?
Set object-fit: contain on an image with a defined media box and provide a background color for any remaining space.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

