Learn HTML and CSS: A soft change with transition
Transition
When you put the mouse on the button, it jumps from red to blue in one go. "That makes you jump," says Walter. A soft change feels calmer, and the site looks finished at once.
A soft change
With transition a change happens gradually instead of in one go. transition: background-color 0.2s lets the background colour change over 0.2 seconds. Put the transition on the element itself, not on :hover, so the colour also returns softly when the mouse leaves. Keep it short: between 0.15 and 0.3 seconds feels quick.
A small shift can be soft too: transform: translateY(-4px) lifts a bench 4px, without moving the rest of the page.
For anyone who asks their device for less motion, @media (prefers-reduced-motion: reduce) is the place to switch the transition off. Put the mouse on the button and on the benches.
.button { transition: background-color 0.2s;}.button:hover { background-color: #1f4e5f;}.bench { transition: transform 0.2s;}.bench:hover { transform: translateY(-4px);}@media (prefers-reduced-motion: reduce) { .button, .bench { transition: none; }}Try it yourself
Make the button turn dark blue softly on hover, #1f4e5f, over 0.2 seconds, and return softly too.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"><head> <title>Broken? Not Today!</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"></head><body> <header> <img src="sleutel.svg" alt="" width="40" height="40"> <h1>Broken? Not Today!</h1> <nav> <a href="index.html">Home</a> <a href="benches.html">Benches</a> <a href="dates.html">Dates</a> <a href="sign-up.html">Sign up</a> </nav> </header> <main> <p class="slogan">Every first Saturday of the month at the parish hall in Dorchester. Bring your broken things: we fix them together.</p> <a class="button" href="sign-up.html">Sign up your device</a> <section class="benches"> <article class="bench bike"> <span class="tag">Full</span> <h2>Bikes</h2> <p>A flat tyre or a weak brake? Jeff and Mark will help you.</p> </article> <article class="bench electrics"> <h2>Electrics</h2> <p>Lamps, toasters and coffee machines.</p> </article> <article class="bench sewing"> <span class="tag">New</span> <h2>Sewing corner</h2> <p>A loose seam or a broken zip.</p> </article> <article class="bench computer"> <h2>Computers</h2> <p>A slow laptop or a cracked screen.</p> </article> </section> </main> <footer> <p>Parish hall, 12 Church Street, Dorchester DT1 1JG</p> </footer></body></html>body { margin: 0; font-family: system-ui, sans-serif; background: #f4f0e8; color: #2a2622;}header { padding: 12px 16px; background: #1f4e5f; color: #ffffff;}header h1 { margin: 0; font-size: 1.5rem;}nav a { padding: 6px 10px; border-radius: 999px; color: #ffffff; text-decoration: none;}main { padding: 0 16px 24px;}.slogan { margin: 16px 0 0; max-width: 40rem;}.benches { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 16px 0;}.button { display: inline-block; margin-top: 12px; padding: 10px 18px; border-radius: 999px; background: #d1495b; color: #ffffff; font-weight: 700; text-decoration: none;}/* A coloured edge per bench and a tag with a hole: only for the look. */.bench { padding: 14px 16px 16px; border-top: 4px solid #f2a541; border-radius: 14px; background: #ffffff; box-shadow: 0 1px 2px rgb(42 38 34 / 0.08), 0 8px 18px -12px rgb(42 38 34 / 0.35);}.bench h2 { margin: 0 0 6px; font-size: 1.1rem;}.bench p { margin: 0; color: #5b544c;}.bike { border-top-color: #2a9d8f;}.electrics { border-top-color: #f2a541;}.sewing { border-top-color: #d1495b;}.computer { border-top-color: #5b6cae;}.tag { display: inline-block; margin-bottom: 8px; padding: 3px 10px 3px 16px; border-radius: 4px 999px 999px 4px; background: radial-gradient(circle at 7px 50%, #ffffff 0 2.5px, transparent 3px), #ffd166; color: #3d2c00; font-size: 0.75rem; font-weight: 700;}form { display: grid; gap: 6px; max-width: 28rem; margin: 16px 0;}label { margin-top: 8px; font-weight: 600;}input,select,textarea { padding: 8px 10px; border: 1px solid #b9b0a3; border-radius: 8px; background: #ffffff; color: #2a2622; font: inherit;}button { justify-self: start; margin-top: 12px; padding: 10px 18px; border: 0; border-radius: 999px; background: #1f4e5f; color: #ffffff; font: inherit; font-weight: 700;}footer { padding: 12px 16px; background: #1f4e5f; color: #ffffff;}Ready for more?
The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson