Your first CSS
A splash of style
Lesson 4 of 20 · 8 min · Module 2: A deliberate visual style
HTML is the structure. CSS is the personality. Give elements color, spacing, and style with a few rules.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Select a class in CSS
- Write property/value declarations
- Check visual spacing and color
The idea
Inside a <style> element, select an element and give it properties. A class selector like .card matches elements with class="card".
<style>
.card {
color: green;
padding: 20px;
}
</style>
<div class="card">Hello, style.</div>
01Connect a class to a selector
class="card" connects an HTML element to the .card CSS selector. The dot belongs in the CSS selector, not in the HTML class value.
02A declaration has two parts
The property names the aspect to change; the value supplies the choice. A colon separates them and a semicolon ends the declaration.
padding: 24px;
border-radius: 12px;
Your turn
.card with a background-color of #e8f5e9, padding: 24px, and border-radius: 12px.What the checks look for
- Card has a light green background
- Card has 24px of padding
- Corners have a 12px radius
Take this with you
Style changes are a series of small, valid declarations attached to a clear selector.