Inline
A style attribute on one element. Quick, but hard to maintain.
<p style="color: teal;">Hi</p>Turn plain HTML into a designed page that looks right on any screen, from a phone to a wide monitor.
This lesson is hands-on. Look for the sliders, menus, and editors. Changing a value and watching what happens is the fastest way to learn CSS.
Part 1
HTML describes what is on a page. CSS (Cascading Style Sheets) describes how it looks: colors, fonts, spacing, and layout. The browser reads both, then draws the styled result.
page.htmlstyle.cssstyled pageAn HTML page connects to a CSS file with a link element in the head:
<head>
<link rel="stylesheet" href="style.css">
</head>Part 2
A CSS rule says: pick these elements, and apply these styles.
h1Selector: which elementscolorProperty: what to change#92D1C3Value: how to change itcolor: #92D1C3;Declaration: property + value + semicolon/* selector { declarations } */
h1 {
color: #92D1C3;
font-size: 2rem;
}
p {
line-height: 1.6;
}Common selectors: p (all paragraphs), .card (class), #menu (id), nav a (links inside a nav), and a:hover (links being hovered).
Part 3
A style attribute on one element. Quick, but hard to maintain.
<p style="color: teal;">Hi</p>A style element in the head. Fine for one page.
<style>
p { color: teal; }
</style>A separate .css file linked from every page. Best for real sites.
<link rel="stylesheet" href="style.css">Use external CSS by default. One file styles the whole site, and changing it once updates every page.
Part 4
.card {
background: #FFFFFF;
color: #222222;
font-family: "Outfit", sans-serif;
font-size: 1rem;
line-height: 1.6;
padding: 24px;
margin: 16px 0;
border: 1px solid #d5dcdc;
border-radius: 16px;
box-shadow: 0 4px 16px rgba(15, 31, 33, 0.12);
}Part 5
Every element is a box made of four layers, from the inside out: content, padding, border, and margin. Move the sliders to see each layer change.
Tip: add box-sizing: border-box; to make width include padding and border. It makes sizing far more predictable.
Part 6
A class (.note) can be reused on many elements. An ID (#msg) must be unique on a page. When several rules target the same element, the most specific one wins: inline style, then ID, then class, then plain element. If specificity ties, the later rule wins.
Switch the rules on and off. The paragraph below has class="note" id="msg".
This paragraph changes color.
Some properties pass down from parent to child. Set font-family and color on body once, and everything inside inherits them. Layout properties such as margin and border do not inherit.
body {
font-family: "Outfit", sans-serif; /* inherited by all text */
color: #222222; /* inherited too */
}Part 7
Flexbox lays items out along one line (a row or a column). It is ideal for navbars and button groups. CSS Grid lays items out in rows and columns together. It is ideal for card layouts and page sections.
Part 8
People view your page on phones, tablets, and desktops. Mobile-first means you write the small-screen layout first, then use min-width media queries to add changes as the screen grows. Always include the viewport meta tag from Module 03, or phones will shrink the page instead.
Drag the slider. The preview below is a real page using the CSS shown, so its media queries respond to the width you choose.
Part 9
Hover and focus states tell people an element is interactive. A transition makes the change smooth. Try it: hover the button, then press Tab to focus it.
.btn {
background: #0F1F21;
color: #92D1C3;
transition: background 0.25s, transform 0.25s;
}
.btn:hover {
background: #92D1C3;
color: #0F1F21;
transform: translateY(-3px);
}
.btn:focus-visible {
outline: 3px solid #24494A;
outline-offset: 4px;
}
@media (prefers-reduced-motion: reduce) {
.btn { transition: none; }
}:focus-visible shows it for keyboard use.prefers-reduced-motion for people who are sensitive to animation.rem for text sizes so it scales when users change their browser font size.Part 10
When styles do not work, open your browser's developer tools (right-click, then Inspect). It shows which rules apply to an element and which are crossed out.
Mistake: color: red then another line.
Fix: End every declaration with ;.
Mistake: backgroud: teal;
Fix: background: teal;. Browsers ignore unknown properties silently.
Mistake: card { } for class="card".
Fix: Classes start with a dot: .card { }. IDs start with #.
Mistake: A style is crossed out in dev tools.
Fix: Check specificity and order. Avoid fixing it with !important.
Mistake: Wrong path in href.
Fix: Check the file name and folder. Look for a 404 in the Network tab.
Mistake: Media queries seem ignored on a phone.
Fix: Add <meta name="viewport" content="width=device-width, initial-scale=1">.
Mistake: width: 800px; causes sideways scrolling.
Fix: Use max-width: 800px; width: 100%;.
Mistake: Padding makes boxes wider than expected.
Fix: * { box-sizing: border-box; }
Practice
Edit the HTML or the CSS and the preview updates as you type. The preview is sandboxed, so scripts are blocked.
Live preview
Challenge
The HTML below has a navbar, hero, cards, and footer, but no styles. Write the CSS in the second box. Fill in each empty rule, design it mobile-first, and use the width buttons to test it on different screens. The checklist ticks as your CSS meets each goal.
Preview width
Checklist
Knowledge check
Tried the demos, styled your page, and passed the quiz? Mark the lesson complete. Progress is saved in this browser only.
Module 04 complete. You can now style pages and make them work on any screen.