CSS Tutorial
Style and lay out the web: the box model, Flexbox, Grid, responsive design and animation.
- Topics
- 26
- Full lessons
- 26
- Est. hours
- ~5
- Interview Qs
- 29
Overview
CSS (Cascading Style Sheets) controls how HTML looks: colour, typography, spacing, layout and motion. Modern CSS includes powerful layout systems — Flexbox and Grid — that replace most old float-based hacks.
You will learn how the cascade, specificity and inheritance decide which rule wins, and how to build layouts that adapt from phones to wide screens.
What you will learn
- Understand the cascade, specificity and the box model
- Build one-dimensional layouts with Flexbox and two-dimensional layouts with Grid
- Write responsive, mobile-first styles
- Add transitions and animations that respect user preferences
Learning path
The recommended sequence, from beginner to advanced. Each stage builds on the one before.
- 1Fundamentals · 5 topics · BeginnerIntroduction to CSS · CSS Syntax · Selectors · Colors and Backgrounds · Typography
- 2Box Model · 5 topics · BeginnerBox Model · Margin and Padding · Borders and Shadows · Display Properties · Positioning
- 3Layout · 4 topics · Beginner → IntermediateFlexbox · CSS Grid · Responsive Design · Media Queries
- 4Selectors & Effects · 5 topics · IntermediatePseudo-Classes · Pseudo-Elements · Transitions · Animations · Transforms
- 5Architecture · 5 topics · Intermediate → AdvancedCSS Variables · Specificity and Inheritance · Z-Index · CSS Architecture · Accessibility
- 6Practice · 2 topics · AdvancedResponsive Website Project · CSS Interview Questions
Complete topic list
26 topicsFundamentals
5 topics- Introduction to CSSBeginner5m
- CSS SyntaxBeginner5m
- SelectorsBeginner5m
- Colors and BackgroundsBeginner5m
- TypographyBeginner5m
Box Model
5 topics- Box ModelBeginner5m
- Margin and PaddingBeginner5m
- Borders and ShadowsBeginner5m
- Display PropertiesBeginner5m
- PositioningBeginner5m
Layout
4 topics- FlexboxBeginner5m
- CSS GridBeginner5m
- Responsive DesignIntermediate5m
- Media QueriesIntermediate5m
Selectors & Effects
5 topics- Pseudo-ClassesIntermediate5m
- Pseudo-ElementsIntermediate5m
- TransitionsIntermediate5m
- AnimationsIntermediate5m
- TransformsIntermediate5m
Architecture
5 topics- CSS VariablesIntermediate5m
- Specificity and InheritanceAdvanced6m
- Z-IndexAdvanced6m
- CSS ArchitectureAdvanced5m
- AccessibilityAdvanced6m
Practice
2 topics- Responsive Website ProjectAdvanced7m
- CSS Interview QuestionsAdvanced15m
Visual guides
2 diagramsCode example
A taste of the track, from Introduction to CSS.
<style>
body {
font-family: system-ui, sans-serif;
background: #f8fafc;
padding: 20px;
}
h1 { color: #2965f1; }
p { color: #334155; line-height: 1.6; }
.highlight { background: #fef08a; }
</style>
<h1>Hello, CSS!</h1>
<p>CSS makes this page look <span class="highlight">much nicer</span>.</p>
A light-grey page with a blue heading, readable grey text and one highlighted phrase.
Practice exercises
Style a page so the background is light yellow, headings are dark green and paragraphs have a 1.5 line height.
Write one rule that gives all <h2> and <h3> elements a dark blue colour and 1.5rem bottom margin, plus a comment above it.
Make every link inside a <footer> grey, and every <li> that is a direct child of .steps bold.
Create a 200px-tall banner with a diagonal gradient from teal to navy and centred white text.
Style a paragraph with Georgia (serif fallback), 1.125rem size, 1.6 line height and a 60ch maximum width.
A box has width: 300px, padding: 10px 30px and border: 5px solid with content-box sizing. What is its total rendered width? Then change it so the total is exactly 300px.
Show all 25 exercises
Make a button with 12px top/bottom and 24px left/right padding, and centre a 400px-wide container on the page.
Create a 120px circular image with a 4px white border and a soft shadow.
Turn a row of <a> links into clickable buttons, each 100px wide with 10px padding, sitting side by side.
Put a “SALE” label in the top-left corner of a product image container.
Centre a 200×200 box both horizontally and vertically inside a container that is 100vh tall.
Create a gallery where each card is at least 160px wide, with 12px gaps, that adapts to any screen width.
Make a .gallery that shows images in as many 150px-minimum columns as fit, with 10px gaps, and fluid images.
Hide .sidebar on screens narrower than 768px and show it as a 250px column from 768px up. Add a dark-mode background.
Make every third list item red and give text inputs a blue border when focused.
Add a small grey “#” before every h2, without changing the HTML.
Make an image fade to 70% opacity and rotate 3 degrees over 300ms when hovered.
Create a “shake” animation that moves an element left and right 3 times in 400ms (for a wrong-password field).
Make an arrow icon (▶) rotate 90 degrees smoothly when its parent <details> is open.
Create --primary and --spacing variables on :root and use them for a .card’s border colour and padding. Add a fallback for --spacing.
Calculate the specificity of: (a) nav ul li a (b) .menu .item:hover (c) #header .logo
A dropdown with z-index: 100 appears behind a sticky header with z-index: 10. The dropdown’s parent .toolbar has position: relative; z-index: 1. Fix it.
Write BEM class names for a navigation bar with a list of links, where the current link is highlighted.
A dropdown menu opens only on .menu:hover. Make it also open for keyboard users.
Extend the page: add a dark theme using prefers-color-scheme by redefining only the colour variables.
Common interview questions
- Explain the CSS box model and box-sizing.
- What are the different values of the position property?
- What is the difference between em, rem and px?
- What are the three ways to add CSS to a page, and which is preferred?
- What is the cascade?
- Which properties are inherited?
- display: none vs visibility: hidden vs opacity: 0?
- block vs inline vs inline-block?
- When would you choose Flexbox over CSS Grid?
- How is CSS specificity calculated?
- What is the difference between pseudo-classes and pseudo-elements?
- How does z-index work, and why does it sometimes “not work”?
- What are CSS custom properties and how are they different from Sass variables?
- Explain mobile-first responsive design.
- What is margin collapsing?
- How do you centre an element horizontally and vertically?
- What do flex-grow, flex-shrink and flex-basis do?
- What does repeat(auto-fit, minmax(250px, 1fr)) do?
- What are grid-template-areas?
- Transitions vs animations?
- What is a stacking context?
- Which CSS properties are cheap to animate and why?
- How do you organise CSS in a large project?
- What are container queries and how are they different from media queries?
- How do you make CSS colours and units theme-able?
- What causes layout shift (CLS) and how does CSS help prevent it?
- What do :is(), :where() and :has() add?
- BEM, utility-first and CSS modules — how do they compare?
- How do you make focus styles accessible?