CSS basics: give your page colors and style
HTML builds your page. CSS dresses it up — colors, spacing, fonts, rounded corners. It's how a plain page becomes one that looks great.
The big idea
CSS is a set of style rules that change how your HTML looks, like its colors and spacing.
See it in code
CSS rules live inside a <style> tag. Each rule picks a tag and gives it a new look. This one picks h1 and paints it indigo:
<style>
h1 { color: #4f46e5; }
</style>
<h1>My Space Page</h1>h1 { color: #4f46e5; } means 'make headings this color'. That's the whole shape of a rule: pick a tag, then set a look.
Add more rules to style more of the page. Here body gets a soft background and a clean font, while the heading keeps its color:
<style>
body { background: #f0f4ff; font-family: sans-serif; }
h1 { color: #4f46e5; }
</style>
<h1>My Space Page</h1>
<p>Welcome! A page about planets and stars.</p>Each rule targets one tag. Stack up a few rules and the whole page starts to come to life.
Now style the paragraph too. Give p some padding (space inside), a white background, and rounded corners:
<style>
body { background: #f0f4ff; font-family: sans-serif; }
h1 { color: #4f46e5; }
p {
color: #333;
padding: 12px;
background: white;
border-radius: 10px;
}
</style>
<h1>My Space Page</h1>
<p>Welcome! This paragraph has its own color, padding, and rounded corners.</p>Each rule says what to style and how. h1 { color: #4f46e5; } means 'make headings indigo'. Change a color or a number, and the look updates right away.
CSS styles every website you see. The colors of your favorite app, the spacing between buttons, the rounded photo corners — all CSS. HTML says what's on the page; CSS says how it looks.
Try it yourself
Change the background color to #fff0f0 for a soft pink page. Then make the heading bigger by adding font-size: 40px; to the h1 rule.
The common mistake
Forgetting the semicolon ; at the end of a style, or the curly braces { }. Each rule needs its braces, and each line inside ends with a semicolon. Miss one, and that style quietly won't work.
What it unlocks
CSS styles the tags you learned in HTML, and grows into full layouts with responsive design.