Build a card with CSS
Task
Create a product card (image, title, price, button) and link an external styles.css file in the <head>.
Requirements
- The <head> contains <link rel="stylesheet" href="styles.css">
- The card is wrapped in <div class="card">
- Inside the card there's an img, a heading, a price, and a button
- No inline styling via the style attribute
Starter code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Product card</title>
</head>
<body>
</body>
</html>
▶ Open in HTML Editor Hints
- A link in head loads CSS before the browser starts painting body — that's the right place for it.
- The card class is then styled in styles.css, not through style="..." on the element itself.
Show solution
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Product card</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="card">
<img src="product.jpg" alt="Wireless headphones">
<h2>Wireless headphones</h2>
<p class="price">$59</p>
<button>Buy now</button>
</div>
</body>
</html>
Related tools
Flexbox: header menu and a row of cards
Flexbox practice exercise: put the logo and menu side by side in the header and line course cards up in an equal-height row that wraps on narrow screens.
HTML Editor Online
Write HTML with syntax highlighting and line numbers, see a live preview, format or minify it, and open or save .html files — all in your browser.
Linking CSS
Lesson 11: three ways to add CSS — an external file via <link rel="stylesheet">, a <style> block in head and the style attribute. Example and task.
CSS Minifier
Minify a CSS file online, see the before/after size and the percentage saved. No server.
CSS Flexbox Playground
Change flex-direction, justify-content, align-items, flex-wrap and gap and see how flexbox works right away. Copy the ready CSS code in one click.