Styling with CSS
Add color, fonts and spacing to your page.
CSS describes how HTML should look. A CSS rule has a selector (what to style) and declarations (how to style it).
h1 {
color: #1d3fb8;
font-size: 48px;
}
This rule says: make every <h1> blue and 48 pixels tall.
Connect CSS to your page
- In your
my-sitefolder, create a file calledstyles.css. - Inside the
<head>ofindex.html, add this line:
<link rel="stylesheet" href="styles.css">
Style your page
Paste this into styles.css, save, and refresh the browser:
body {
font-family: system-ui, sans-serif;
max-width: 640px;
margin: 40px auto;
padding: 0 16px;
line-height: 1.6;
background: #f3f5fa;
color: #121a33;
}
h1 { color: #1d3fb8; }
a {
color: #121a33;
background: #f2a516;
padding: 4px 8px;
border-radius: 6px;
}
The box model
Every element on a page is a box with four layers, from inside to outside: content, padding (space inside the border), border, and margin (space outside the border). Open the developer tools, select an element, and look at the Computed tab to see its box.
Your turn
Pick two colors that mean something to you, maybe from a flag, a sports team or a favorite place, and restyle your page with them.