
HTML and CSS Projects for Beginners (With Source Code)
Start with a profile card or a recipe page, then build layouts with Flexbox and Grid, a signup form, and dark mode. 11 projects in plain HTML and CSS, with tested code.
The best first HTML and CSS projects are small single pages you can finish in an afternoon, like a profile card, a recipe page, or a one-page résumé. Next, build layouts with Flexbox and Grid, then responsive pages and CSS-only polish such as a loading spinner and dark mode. All 11 projects below use only HTML and CSS, with no JavaScript. Each one is a single file you open in your browser, and we tested every sample at phone and desktop widths.
We build Mimo, and our HTML course and CSS course teach the skills behind these projects, from semantic HTML and forms to Flexbox and Grid.
| # | Project | Skill |
|---|---|---|
| 1 | Profile card | Spacing and shadows |
| 2 | Recipe page | Semantic HTML |
| 3 | Résumé | Print styles |
| 4 | Navbar | Flexbox |
| 5 | Pricing table | Flexbox cards |
| 6 | Photo gallery | CSS Grid |
| 7 | Landing page | Media queries |
| 8 | Signup form | Form validation |
| 9 | FAQ page | Show and hide |
| 10 | Loading spinner | Animation |
| 11 | Dark mode | CSS variables |
What you need
All you need is a browser and a plain-text editor, such as Notepad or TextEdit in plain-text mode (Format → Make Plain Text). If you’d rather not set anything up, use our free HTML compiler: sign up for a free Mimo account, write HTML and CSS together, and see the result in a live preview.
To run a project on your computer:
- Create a file called
index.html(how to create an HTML file). - Type or paste in the code and save.
- Open the file in your browser. Change something, save, and reload the page.
Each example is a complete page. The CSS sits in a <style> tag in the <head>, so everything stays in one file. Tags directly inside <head> and <body> start at the left edge instead of being indented, and some lines break earlier than you’d usually write them, so the code fits on a phone screen. For other ways to open a page, see how to run HTML code.
Structure and semantic HTML
These three pages are mostly text. They teach you to pick the right HTML element first and then style it.
1. Profile card
A card with your initials, name, a short bio, and a link, centered on the page.
What you’ll practice: padding, rounded corners, box shadows, and centering an element vertically.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Profile card</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #e0e7ff;
font-family: system-ui;
color: #1f2937;
}
.card {
max-width: 18rem;
margin: 1rem;
padding: 2rem;
text-align: center;
background: #fff;
border-radius: 1rem;
box-shadow:
0 8px 24px #0003;
}
.avatar {
width: 6rem;
height: 6rem;
margin: 0 auto;
border-radius: 50%;
background: #4338ca;
color: #fff;
font-size: 2rem;
line-height: 6rem;
}
.role {
color: #4b5563;
}
a {
color: #4338ca;
font-weight: bold;
}
</style>
</head>
<body>
<main class="card">
<div class="avatar"
aria-hidden="true">
AK
</div>
<h1>Alex Kim</h1>
<p class="role">
Aspiring web designer
</p>
<p>I build small websites
with HTML and CSS.</p>
<a href=
"https://example.com">
See my work
</a>
</main>
</body>
</html>
display: grid and place-items: center on the <body> center the card in both directions, and min-height: 100vh makes the body as tall as the window. border-radius: 50% turns the square avatar into a circle, and a line-height equal to its height centers the initials. aria-hidden="true" hides the initials from screen readers, because the heading already says the name.
Done when: the card stays in the middle of the window, with the initials in a circle, at any window size.
Common mistake: leaving out margin: 0 on the body. Browsers add 8px of margin by default, so min-height: 100vh plus that margin makes the page taller than the window, and you get a scrollbar you didn’t ask for.
Make it yours: swap the initials for a photo with <img src="me.jpg" alt="Alex smiling">, then give it the same size, border-radius: 50%, and object-fit: cover.
2. Recipe page with semantic HTML
A recipe with a title, an ingredient list, numbered steps, and a cook’s tip.
What you’ll practice: semantic elements like <article>, <header>, and <aside>, bullet lists and numbered lists, and styling list markers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>
Banana pancakes
</title>
<style>
body {
max-width: 38rem;
margin: 0 auto;
padding: 1rem;
font-family:
Georgia, serif;
line-height: 1.6;
color: #292524;
background: #fffbeb;
}
header {
border-bottom:
2px solid #f59e0b;
}
h2 {
color: #9a3412;
}
li::marker {
color: #b45309;
font-weight: bold;
}
aside {
margin: 1.5rem 0;
padding: 1rem;
border-left:
4px solid #f59e0b;
background: #fef3c7;
}
</style>
</head>
<body>
<main>
<article>
<header>
<h1>Banana pancakes</h1>
<p>Serves 2 ·
15 minutes</p>
</header>
<h2>Ingredients</h2>
<ul>
<li>1 ripe banana</li>
<li>2 eggs</li>
<li>4 tbsp oat
flour</li>
<li>A pinch of salt</li>
</ul>
<h2>Steps</h2>
<ol>
<li>Mash the
banana.</li>
<li>Whisk in the eggs,
flour, and salt.</li>
<li>Fry small pancakes
for 2 minutes per
side.</li>
</ol>
<aside>
<p><strong>Cook's tip:
</strong> Keep the
heat medium so they
cook through.</p>
</aside>
</article>
</main>
</body>
</html>
<article> marks the recipe as one self-contained piece, and <header> holds its title and summary. <main> wraps the page’s main content, so screen reader users can jump straight to the recipe. The ingredients use <ul> because their order doesn’t matter, while the steps use <ol> because it does. li::marker colors only the bullets and numbers, not the text. <aside> holds the tip, which belongs with the recipe but isn’t one of the steps.
Done when: you delete the whole <style> tag and the page still reads correctly from top to bottom.
Common mistake: picking a heading level for its size, like jumping from <h1> to <h4>. Choose the level that fits the outline and change the size in CSS.
Make it yours: add a photo of the dish in a <figure> with a <figcaption> and descriptive alt text, or a nutrition table (how to make a table in HTML).
3. One-page résumé you can print
A résumé that looks good on screen and prints cleanly on one page.
What you’ll practice: <section> elements with headings, @media print, hiding elements on paper, and printing each link’s URL with attr() (see how to create a link in HTML).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Sam Rivera</title>
<style>
body {
max-width: 40rem;
margin: 0 auto;
padding: 1rem;
font-family: system-ui;
line-height: 1.5;
color: #1f2937;
}
h2 {
color: #0f766e;
border-bottom: 1px solid;
}
.tip {
padding: 0.5rem;
background: #ccfbf1;
}
@media print {
h2 {
color: #000;
}
.tip {
display: none;
}
a::after {
content:
" (" attr(href) ")";
}
}
</style>
</head>
<body>
<p class="tip">
Press Ctrl+P
(Cmd+P on Mac) to save
this page as a PDF.
</p>
<header>
<h1>Sam Rivera</h1>
<p>Junior web developer,
sam@example.com</p>
<a href=
"https://example.com">
Portfolio</a>
</header>
<main>
<section>
<h2>Experience</h2>
<h3>Web volunteer</h3>
<p>Library,
2025-2026</p>
<ul>
<li>Rebuilt the events
calendar page.</li>
<li>Made the site
easy to read on
phones.</li>
</ul>
</section>
<section>
<h2>Skills</h2>
<p>HTML, CSS, Flexbox,
Grid, and
accessibility.</p>
</section>
</main>
</body>
</html>
Everything inside @media print only applies when you print or save as PDF. On paper, the tip disappears, the headings turn black to save colored ink, and a::after prints the link’s address after its text, since nobody can click paper. border-bottom: 1px solid without a color uses the heading’s text color, so the line turns black too.
Done when: the print preview (Ctrl+P, or Cmd+P on Mac) shows no tip box, black headings, and the portfolio URL in parentheses.
Common mistake: putting @media print above the normal rules. When two rules match equally, the later one wins, so the screen styles can undo your print styles.
Make it yours: add an Education section, or put the contact details and skills in a narrow column next to the experience on wide screens.
Layout with Flexbox and Grid
These projects place boxes next to each other and let them wrap or stack when the screen gets narrow.
4. Responsive navbar with Flexbox
A dark navigation bar with a logo on the left and links on the right. On a phone, the links wrap onto a second row instead of hiding behind a menu button.
What you’ll practice: Flexbox, flex-wrap, removing list bullets, and :hover and :focus-visible pseudo-classes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Navbar</title>
<style>
body {
margin: 0;
font-family: system-ui;
}
.bar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content:
space-between;
gap: 0.5rem;
padding: 0.75rem 1rem;
background: #111827;
}
.links {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
margin: 0;
padding: 0;
list-style: none;
}
.bar a {
display: block;
padding: 0.5rem 0.75rem;
border-radius: 0.375rem;
color: #f9fafb;
text-decoration: none;
}
.bar a:hover,
.bar a:focus-visible {
background: #374151;
}
.logo {
font-weight: bold;
}
main {
padding: 1rem;
}
</style>
</head>
<body>
<header class="bar">
<a class="logo" href="#">
Pixel Café
</a>
<nav aria-label="Main">
<ul class="links">
<li>
<a href="#">
Menu
</a>
</li>
<li>
<a href="#">
About
</a>
</li>
<li>
<a href="#">
Events
</a>
</li>
<li>
<a href="#">
Contact
</a>
</li>
</ul>
</nav>
</header>
<main>
<h1>Welcome</h1>
<p>Make the window
narrow to see the
links wrap.</p>
</main>
</body>
</html>
display: flex puts the logo and the <nav> in one row, and justify-content: space-between pushes them to opposite ends. flex-wrap: wrap on both the bar and the list lets items move to a new row when there’s no room, so nothing gets squeezed or cut off. The :focus-visible style shows keyboard users which link they’re on.
Done when: at full width, everything sits in one row, and on a phone the links move under the logo without a horizontal scrollbar.
Common mistake: leaving flex-wrap: wrap off the list. On a narrow phone, or once you add more links, they can’t move to a new row, and the page gets a horizontal scrollbar.
Make it yours: mark the current page with aria-current="page" and style it with [aria-current], or keep the bar at the top while you scroll by adding position: sticky and top: 0 to .bar (how to position elements in CSS).
5. Pricing table with three plans
Three plan cards with a highlighted middle plan. They sit side by side on a laptop and stack on a phone.
What you’ll practice: flex: 1 1 15rem for cards that wrap, combining classes like .plan.best (see specificity), sizes in rem, and links styled as buttons.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Pricing</title>
<style>
body {
margin: 0;
padding: 1rem;
font-family: system-ui;
color: #1f2937;
background: #f3f4f6;
}
.plans {
display: flex;
flex-wrap: wrap;
gap: 1rem;
max-width: 60rem;
margin: 0 auto;
}
.plan {
flex: 1 1 15rem;
padding: 1.5rem;
border: 2px solid #d1d5db;
border-radius: 0.75rem;
background: #fff;
}
.plan.best {
border-color: #7c3aed;
}
.price {
font-size: 2rem;
font-weight: bold;
}
.btn {
display: block;
padding: 0.75rem;
border-radius: 0.5rem;
background: #7c3aed;
color: #fff;
text-align: center;
text-decoration: none;
}
</style>
</head>
<body>
<h1>Choose a plan</h1>
<div class="plans">
<section class="plan">
<h2>Hobby</h2>
<p class="price">$0</p>
<p>1 project</p>
<a class="btn" href="#">
Start free</a>
</section>
<section
class="plan best">
<h2>Studio</h2>
<p>Most popular</p>
<p class="price">$12</p>
<p>10 projects</p>
<a class="btn" href="#">
Choose Studio</a>
</section>
<section class="plan">
<h2>Team</h2>
<p class="price">$29</p>
<p>
Unlimited projects
</p>
<a class="btn" href="#">
Choose Team</a>
</section>
</div>
</body>
</html>
flex: 1 1 15rem tells each card to start at 15rem wide, grow to fill extra space, and shrink if needed. Three cards fit in a row on a laptop, but not on a phone, so flex-wrap: wrap stacks them. .plan.best only matches an element that has both classes, which is how the middle card gets its purple border.
Done when: the three cards sit in one row on a wide screen and stack on a phone, and the middle one stands out. At in-between widths, two cards share a row and the third stretches across the next one. That’s flex-wrap at work.
Common mistake: giving each card a fixed width in pixels. It looks right on your screen but breaks on others, while flex: 1 1 15rem plus flex-wrap adapts to any width.
Make it yours: add a feature list to each card with check marks as the list markers, or give the buttons a darker :hover color.
6. Photo gallery with CSS Grid
A gallery that shows two columns on a phone and up to six on a wide screen, without a single media query. Colored boxes stand in for photos, so the page works offline.
What you’ll practice: CSS Grid, repeat(auto-fit, minmax()), aspect-ratio, and <figure> with <figcaption>.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Photo gallery</title>
<style>
body {
max-width: 60rem;
margin: 0 auto;
padding: 1rem;
font-family: system-ui;
}
.gallery {
display: grid;
grid-template-columns:
repeat(auto-fit,
minmax(9rem, 1fr));
gap: 0.75rem;
}
figure {
margin: 0;
}
figure div {
aspect-ratio: 4 / 3;
border-radius: 0.5rem;
}
.sea {
background: #0284c7;
}
.wood {
background: #15803d;
}
.dune {
background: #d97706;
}
.city {
background: #6b7280;
}
.dusk {
background: #e11d48;
}
.lake {
background: #0e7490;
}
</style>
</head>
<body>
<h1>Trip photos</h1>
<div class="gallery">
<figure>
<div class="sea"></div>
<figcaption>
Sea
</figcaption>
</figure>
<figure>
<div class="wood"></div>
<figcaption>
Forest
</figcaption>
</figure>
<figure>
<div class="dune"></div>
<figcaption>
Desert
</figcaption>
</figure>
<figure>
<div class="city"></div>
<figcaption>
City
</figcaption>
</figure>
<figure>
<div class="dusk"></div>
<figcaption>
Sunset
</figcaption>
</figure>
<figure>
<div class="lake"></div>
<figcaption>
Lake
</figcaption>
</figure>
</div>
</body>
</html>
minmax(9rem, 1fr) says each column is at least 9rem wide and shares any extra space equally. auto-fit fits as many of those columns as the width allows, so the grid picks its own column count. aspect-ratio: 4 / 3 keeps every tile the same shape at any width.
Done when: as you make the window narrower, the columns drop from six to two and the tiles keep their shape.
Common mistake: mixing up auto-fill and auto-fit. With only a few photos on a wide screen, auto-fill keeps empty columns, so the tiles stay small instead of stretching.
Make it yours: swap each colored <div> for a photo like <img src="sea.jpg" alt="Waves on a sandy beach">, and replace the figure div rule with the one below so every photo gets the same shape. To make the first photo bigger, add grid-column: span 2 to its <figure>.
figure img {
display: block;
width: 100%;
aspect-ratio: 4 / 3;
object-fit: cover;
border-radius: 0.5rem;
}
Responsive pages and forms
These projects start with the phone layout and add to it for bigger screens, then collect input with nothing but HTML.
7. Product landing page
A landing page for a made-up plant app, with a hero section, a call-to-action button, and three feature boxes.
What you’ll practice: mobile-first media queries, anchor links to a section of the page, Grid columns, and centering text.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Sprout</title>
<style>
body {
margin: 0;
font-family: system-ui;
line-height: 1.5;
color: #1f2937;
}
.hero {
padding: 3rem 1rem;
text-align: center;
background: #14532d;
color: #fff;
}
.cta {
display: inline-block;
padding: 0.75rem 1.5rem;
border-radius: 2rem;
background: #facc15;
color: #1f2937;
font-weight: bold;
text-decoration: none;
}
.features {
display: grid;
gap: 1rem;
max-width: 60rem;
margin: 0 auto;
padding: 2rem 1rem;
}
.feature {
padding: 1rem;
border-radius: 0.5rem;
background: #f0fdf4;
}
@media (min-width: 48rem) {
.hero {
padding: 6rem 2rem;
}
.features {
grid-template-columns:
repeat(3, 1fr);
}
}
</style>
</head>
<body>
<header class="hero">
<h1>Sprout</h1>
<p>Reminders that keep
your houseplants
alive.</p>
<a class="cta"
href="#features">
See how it works</a>
</header>
<main id="features"
class="features">
<section class="feature">
<h2>Smart reminders</h2>
<p>Get a nudge when a
plant needs water.</p>
</section>
<section class="feature">
<h2>Plant library</h2>
<p>Care tips for common
houseplants.</p>
</section>
<section class="feature">
<h2>Shared care</h2>
<p>Split watering
duty with your
roommates.</p>
</section>
</main>
</body>
</html>
The styles outside the media query are the phone layout: one column and a compact hero. @media (min-width: 48rem) only kicks in at 768px and wider, where it adds more space to the hero and puts the features in three columns. The button links to #features, the id of the <main> element, so a click jumps down the page.
Done when: the features stack on a phone, sit in three columns on a laptop, and the button jumps to them.
Common mistake: leaving out <meta name="viewport">. Phones then lay the page out at desktop width and shrink it, so your mobile styles look tiny.
Make it yours: add a footer with contact links, or a "How it works" section with three numbered steps.
8. Signup form with built-in validation
A book club signup form that won’t submit until every field is valid. The browser does the checking, so there’s no JavaScript. A real site also checks the data on its server, because browser checks are easy to skip.
What you’ll practice: <label>, <fieldset>, and <legend>, validation attributes like required, type="email", min, max, and pattern, a required checkbox, and the :user-invalid pseudo-class.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>
Book club signup
</title>
<style>
body {
max-width: 24rem;
margin: 0 auto;
padding: 1rem;
font-family: system-ui;
}
label {
display: block;
margin-top: 0.75rem;
}
input {
box-sizing: border-box;
width: 100%;
padding: 0.5rem;
border: 2px solid #6b7280;
border-radius: 0.25rem;
font: inherit;
}
input:user-invalid {
border-color: #b91c1c;
}
.tip {
margin: 0.25rem 0 0;
color: #4b5563;
}
input:user-invalid + .tip {
color: #b91c1c;
}
.check input {
width: auto;
}
button {
margin-top: 1rem;
padding: 0.75rem 1.5rem;
font: inherit;
}
</style>
</head>
<body>
<h1>Join the book club</h1>
<form>
<fieldset>
<legend>Account</legend>
<label for="email">
Email</label>
<input id="email"
name="email"
type="email"
autocomplete="email"
required>
<label for="user">
Username</label>
<input id="user"
name="user"
autocomplete=
"username"
pattern=
"[a-z0-9]{3,12}"
aria-describedby="tip"
required>
<p id="tip" class="tip">
3-12 lowercase letters
or numbers</p>
<label for="books">
Books per year</label>
<input id="books"
name="books"
type="number"
min="1" max="365">
</fieldset>
<label class="check">
<input type="checkbox"
name="rules" required>
I accept the club rules
</label>
<button>Sign up</button>
</form>
</body>
</html>
required, type="email", pattern, and min/max tell the browser what counts as valid, and it blocks the submit and shows a message until every field passes. :user-invalid only turns a border red after someone has changed a field and moved on, or tried to submit, unlike :invalid, which marks empty required fields red as soon as the page loads. input:user-invalid + .tip turns the hint under the username red too, because + selects the element that comes right after the field. Browsers that don’t support :user-invalid skip the rule, and their built-in messages still stop an invalid submit.
Done when: clicking Sign up with empty fields shows a message and red borders on the email and username fields, and valid values (for example, the username sam42) plus the checked box submit the form. With no action attribute, the form reloads the same page with your values in the address bar.
Common mistake: using placeholder instead of a <label>. The placeholder disappears as soon as someone types, so people forget what the field asks for, and screen readers don’t treat it as a reliable label.
Make it yours: add a second <fieldset> of radio buttons for favorite genre, with the same name on each button so only one can be picked.
Want your own error messages next to each field? The form validator in our JavaScript projects for beginners does that with JavaScript.
CSS-only interactions and polish
These projects add things that often get built with JavaScript, using only HTML elements and CSS the browser already understands.
9. FAQ page with details and summary
A question and answer page where each answer opens when you click its question. It uses the native HTML <details> element, so the browser handles opening and closing.
What you’ll practice: <details> and <summary>, the [open] attribute selector, and styling the ::marker arrow.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>
Pottery class FAQ
</title>
<style>
body {
max-width: 40rem;
margin: 0 auto;
padding: 1rem;
font-family: system-ui;
color: #1f2937;
}
details {
margin-bottom: 0.5rem;
border: 1px solid #d1d5db;
border-radius: 0.5rem;
}
summary {
padding: 1rem;
font-weight: bold;
cursor: pointer;
}
summary::marker {
color: #c2410c;
}
details[open] summary {
border-bottom:
1px solid #d1d5db;
}
details p {
margin: 0;
padding: 1rem;
}
</style>
</head>
<body>
<h1>Pottery class FAQ</h1>
<details>
<summary>
Do I need any
experience?
</summary>
<p>Not at all. The first
class covers the
basics.</p>
</details>
<details>
<summary>
What should I bring?
</summary>
<p>Clothes that can get
muddy. We supply the
clay and tools.</p>
</details>
<details>
<summary>
Can I cancel a class?
</summary>
<p>Yes, up to 24 hours
before it starts.</p>
</details>
</body>
</html>
Everything inside <details> except the <summary> stays hidden until someone clicks the summary or presses Enter on it. The browser adds the open attribute when it’s expanded, so details[open] summary styles only the open questions. Screen readers announce each question as expanded or collapsed without any extra code.
Done when: each question opens and closes with a click and with the keyboard (Tab, then Enter).
Common mistake: putting the question in a heading above <summary>. Only the summary is clickable, so keep the whole question inside it.
Make it yours: give every <details> the same name attribute, so opening one closes the others in current browsers, or add open to the first one so it starts expanded.
10. CSS-only loading spinner
A spinning ring with a "Loading" label that stops moving for people who turn on reduced motion in their system settings.
What you’ll practice: @keyframes and the animation property, border-radius and border colors, and the prefers-reduced-motion media query.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>
Loading spinner
</title>
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
font-family: system-ui;
}
.spinner {
width: 3rem;
height: 3rem;
margin: 0 auto;
border:
0.4rem solid #dbeafe;
border-top-color: #1d4ed8;
border-radius: 50%;
animation:
spin 1s linear infinite;
}
@keyframes spin {
to {
transform:
rotate(1turn);
}
}
@media (
prefers-reduced-motion:
reduce
) {
.spinner {
animation: none;
}
}
</style>
</head>
<body>
<div role="status">
<div class="spinner">
</div>
<p>Loading…</p>
</div>
</body>
</html>
The spinner is a circle with a light border and one dark side, border-top-color, so you see the rotation. @keyframes spin rotates it one full turn, and infinite repeats that forever. role="status" marks the area as a status message, so when a real app swaps "Loading…" for the result, screen readers announce the change. The visible text also tells everyone what the ring means. The prefers-reduced-motion query turns the animation off for people who asked their system for less motion.
Done when: the ring spins smoothly, and it stops when you turn on reduced motion (on Windows, turn off "Animation effects"; on a Mac, turn on "Reduce motion").
Common mistake: animating width, margin, or top to make something move. The browser has to recalculate the layout on every frame, which can stutter, while transform animates smoothly.
Make it yours: replace the ring with three dots that fade in turn, using animation-delay, or give the reduced-motion version a slow fade instead of no animation.
11. Dark mode with prefers-color-scheme
A page that switches to dark colors when your device uses a dark theme. All colors live in a few CSS variables, so the switch takes one small block of code.
What you’ll practice: CSS variables, the prefers-color-scheme media query, color-scheme, and text colors with enough contrast in both themes.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport"
content=
"width=device-width">
<title>Night notes</title>
<style>
:root {
color-scheme: light dark;
--bg: #ffffff;
--text: #1f2937;
--card: #f3f4f6;
--accent: #1d4ed8;
}
@media (
prefers-color-scheme: dark
) {
:root {
--bg: #111827;
--text: #f3f4f6;
--card: #1f2937;
--accent: #93c5fd;
}
}
body {
max-width: 40rem;
margin: 0 auto;
padding: 1rem;
font-family: system-ui;
background: var(--bg);
color: var(--text);
}
.card {
padding: 1rem;
border-radius: 0.5rem;
background: var(--card);
}
a {
color: var(--accent);
}
</style>
</head>
<body>
<h1>Night notes</h1>
<article class="card">
<h2>Why dark mode?</h2>
<p>Many people prefer
it at night, and this
page follows your
system.</p>
<a href="#">Read more</a>
</article>
</body>
</html>
The rest of the CSS only uses var(--bg) and the other variables, so the media query just swaps their values. color-scheme: light dark tells the browser that the page supports both themes, so scrollbars and form controls switch too. The lighter blue for links in dark mode keeps them readable on the dark background.
Done when: switching your system between light and dark changes the page colors without a reload. In Chrome DevTools, you can also open the Rendering tab and use "Emulate CSS media feature prefers-color-scheme".
Common mistake: writing colors directly in some rules instead of using the variables. Those parts stay light when the rest of the page turns dark.
Make it yours: add a labeled checkbox with id="dark" for a manual theme switch. Move the dark variables out of the media query into a :root:has(#dark:checked) rule, so the checkbox picks the theme instead of your system setting. Set color-scheme: light in the base :root rule and color-scheme: dark in the checked rule.
Tips for finishing your projects
- Type the code instead of pasting it, then change one thing at a time and reload to see what it does.
- Check every page at phone width. In Chrome, open DevTools (F12) and turn on the device toolbar.
- Run your HTML through the W3C validator to catch missing closing tags and typos.
- When the CSS gets long, move it into its own file (how to link CSS to HTML).
- Keep the HTML cheat sheet and the CSS cheat sheet open while you build.
Next step: when you want pages that count, calculate, or save data, add JavaScript with these JavaScript projects for beginners.
Learn HTML and CSS with Mimo
Mimo takes you from your first tag to pages like the ones above. Our HTML course covers HTML basics, semantic HTML, accessibility basics, and forms, the skills behind the recipe page, the résumé, and the signup form. Our CSS course goes from intro and intermediate CSS to Flexbox and Grid, which power the navbar, the pricing table, and the gallery.
Every lesson is interactive and bite-sized. You write code from day one, get instant feedback, and build real projects with AI-generated hints and explanations. Learn at your own pace on the web or on your phone, and earn a certificate when you finish a course.
Ready to go further? The Front-End Development career path adds JavaScript and React to HTML and CSS, with 85 coding challenges and 13 guided projects for your portfolio.
Join more than 40 million learners. Sign up for free and start your first HTML lesson today.

