JavaScript Curriculum
Introducing CSS
easyThe coffee shop's HTML is solid but it looks like a 1995 government website. Time to add your first stylesheet and bring it to life with color, spacing, and typography.
Introducing CSS
HTML gives your page structure. CSS gives it style — color, spacing, typography, layout. Every visual decision on the web is made in CSS.
Anatomy of a CSS Rule
A CSS rule has three parts:
- Selector — which HTML element(s) to style
- Property — what aspect to change (color, font-size, margin…)
- Value — what to change it to
Multiple declarations go inside the same rule block:
Selectors — Targeting Elements
CSS has five selector types you'll use every day:
Targets every instance of that HTML element on the page.
p {
color: #333;
font-size: 16px;
}Properties and Values — Live Sandbox
CSS has hundreds of properties, but ~20 cover 80% of everyday styling. Try them here:
.coffee-label {
color: #adbac7;
font-size: 16px;
font-weight: 400;
text-align: left;
}Linking CSS to HTML
There are three ways to add CSS — and one clear winner:
<!-- In <head> -->
<link rel="stylesheet" href="styles.css">
<!-- styles.css -->
body {
font-family: sans-serif;
margin: 0;
}- +One file styles the whole site
- +Browser caches it — fast repeat visits
- +Clean separation of HTML and CSS
- +Easy to maintain and share
- −Extra HTTP request on first load
Your Challenge
Create a styles.css file, link it to your HTML, and write CSS rules using element, class, and pseudo-class selectors to style the coffee shop page.
Challenge
Create a styles.css file and link it to your HTML. Write rules that: set a font-family on body, style h1 with a color and font-size, give p elements a line-height, style all nav a links to remove underline and change color on hover, and give .card elements a background and border-radius.
Introducing CSS
easyThe coffee shop's HTML is solid but it looks like a 1995 government website. Time to add your first stylesheet and bring it to life with color, spacing, and typography.
Introducing CSS
HTML gives your page structure. CSS gives it style — color, spacing, typography, layout. Every visual decision on the web is made in CSS.
Anatomy of a CSS Rule
A CSS rule has three parts:
- Selector — which HTML element(s) to style
- Property — what aspect to change (color, font-size, margin…)
- Value — what to change it to
Multiple declarations go inside the same rule block:
Selectors — Targeting Elements
CSS has five selector types you'll use every day:
Targets every instance of that HTML element on the page.
p {
color: #333;
font-size: 16px;
}Properties and Values — Live Sandbox
CSS has hundreds of properties, but ~20 cover 80% of everyday styling. Try them here:
.coffee-label {
color: #adbac7;
font-size: 16px;
font-weight: 400;
text-align: left;
}Linking CSS to HTML
There are three ways to add CSS — and one clear winner:
<!-- In <head> -->
<link rel="stylesheet" href="styles.css">
<!-- styles.css -->
body {
font-family: sans-serif;
margin: 0;
}- +One file styles the whole site
- +Browser caches it — fast repeat visits
- +Clean separation of HTML and CSS
- +Easy to maintain and share
- −Extra HTTP request on first load
Your Challenge
Create a styles.css file, link it to your HTML, and write CSS rules using element, class, and pseudo-class selectors to style the coffee shop page.
Challenge
Create a styles.css file and link it to your HTML. Write rules that: set a font-family on body, style h1 with a color and font-size, give p elements a line-height, style all nav a links to remove underline and change color on hover, and give .card elements a background and border-radius.