CSS Tutorial for Beginners
Learn CSS step by step with this beginner tutorial: selectors, colours, the box model, Flexbox, CSS Grid, responsive web design, dark mode and animations, with live examples you can edit online.
Browse all 49 lessons by stage
- Lessons
- 49
- Live examples
- 136
- Exercises
- 277
- Quiz questions
- 198
CSS course at a glance
Who it's for
Beginners who know basic HTML, designers who want to build their own pages, and developers who want layout to finally make sense.
Prerequisites
The basics of HTML: elements, attributes, classes and how a page is structured.
What you need
A modern browser with developer tools. Every example can be edited and run right on the lesson page.
How long it takes
Two to three weeks for the Basics and Intermediate stages at an hour a day, and five to seven weeks for the full course.
CSS roadmap: beginner to advanced
Follow the chapters in order, because each one builds on the last. Every lesson has live examples, exercises and a quiz.
Basics
How CSS works, selectors, colours, backgrounds, borders, text, fonts, units, sizing and overflow.
- 1CSS IntroductionWhat CSS does, how it connects to HTML, and your first styles.
- 2CSS SyntaxRules, declarations, grouping selectors and comments.
- 3Adding CSS to HTMLInline styles, style tags and external stylesheets, and which one to use.
- 4SelectorsTarget exactly the elements you want by tag, class, id, family or attribute.
- 5Combinators & AttributesTarget elements by their relationship to other elements, and by their attributes: descendant, child, sibling and attribute selectors with examples.
- 6ColorsColour names, HEX, RGB, HSL, transparency and contrast.
Show all 13 lessonsShow fewer
- 7BackgroundsBackground colours, images, cover/contain, positioning and layers.
- 8Borders & RadiusBorders, rounded corners, circles, pills and outlines.
- 9TextAlign, space, decorate and transform text for readable pages.
- 10FontsFont families, sizes, weights, the font shorthand and web fonts.
- 11Units (px, rem, %)Pixels, rems, percentages, viewport units and fluid sizes.
- 12Width & HeightControl element size with width, height, min and max sizes, box-sizing and aspect-ratio, and make boxes that shrink nicely on small screens.
- 13Overflow & VisibilityDecide what happens when content is too big for its box, add scrollbars, truncate text with an ellipsis, and hide elements with visibility, opacity or display.
Intermediate
Box model, display, position, Flexbox, Grid, pseudo-classes, menus, forms, tables and specificity.
- 14Box ModelEvery element is a box. Learn how its size really works.
- 15Margin & PaddingSpace inside and outside elements, shorthands and centring.
- 16DisplayControl how a box behaves: block, inline, inline-block, none, flex, grid.
- 17Position & z-indexMove elements with relative, absolute, fixed and sticky, and stack them with z-index.
- 18Float & ClearWrap text around images with float, stop the wrapping with clear, fix collapsed parents with display flow-root, and know when to use flexbox instead.
- 19FlexboxLine things up in rows or columns, space them out and centre anything.
Show all 19 lessonsShow fewer
- 20GridTwo-dimensional layouts with rows, columns, fr units and named areas.
- 21CenteringCenter text, blocks, images and whole boxes horizontally and vertically with text-align, margin auto, flexbox, grid and position.
- 22Pseudo-classesStyle elements by state and position: hover, focus, first, nth and more.
- 23Pseudo-elementsStyle parts of elements and add decorative content with ::before and ::after.
- 24Links & ButtonsStyle links in every state, remove or restyle underlines, build accessible buttons with hover, focus and disabled states, and make link-styled buttons.
- 25Lists & NavbarsStyle list bullets and numbers, remove default list styles, and turn a list of links into horizontal and vertical navigation bars with active states.
- 26Dropdowns & TooltipsBuild dropdown menus and tooltips with only CSS, using position absolute, :hover and :focus-within, plus accessible options with details and popover.
- 27FormsStyle text inputs, textareas, selects, checkboxes and radio buttons, add focus and error states, and lay out forms that work on phones.
- 28TablesMake HTML tables readable with border-collapse, padding, zebra stripes, hover rows, sticky headers and number alignment, and make them work on phones.
- 29Images & FiltersSize and crop images with object-fit and object-position, round them, add filters such as grayscale and blur, build hover effects and image overlays.
- 30Specificity & CascadeWhich rule wins when two rules disagree, and how to stop fighting your CSS.
- 31Inheritance & !importantLearn which properties children inherit, how inherit, initial, unset and revert work, when !important is acceptable, and how @layer organises the cascade.
- 32calc() & clamp()Do maths in CSS: mix units with calc(), pick the smaller or larger value with min() and max(), and build fluid sizes with clamp().
Advanced
Variables, media queries, responsive design, container queries, nesting, dark mode and animation.
- 33CSS VariablesStore colours and sizes once, reuse everywhere, and switch themes.
- 34Media QueriesAdapt layouts to phones, tablets and desktops, starting with mobile.
- 35Responsive DesignBuild pages that work on every screen: the mobile-first approach, fluid layouts, flexible units, breakpoints, and testing at phone, tablet and desktop widths.
- 36Responsive ImagesMake images, background images, videos and embeds fit any screen: max-width, aspect-ratio, object-fit, image-set() and art direction with media queries.
- 37Responsive TypographyMake text readable on every screen: rem units, fluid font sizes with clamp(), a type scale, line length with ch, line height, and text that respects user settings.
- 38Responsive LayoutsBuild the layouts every site needs, card grids, sidebars, holy grail pages, switchers and sticky footers, so they adapt to any screen with grid and flexbox.
Show all 17 lessonsShow fewer
- 39Responsive NavbarBuild a navigation bar that shows links in a row on desktops and collapses into an accessible hamburger menu on phones, with CSS and a few lines of JavaScript.
- 40Container QueriesMake components respond to the space they're placed in, not the screen: container-type, @container rules, named containers and container query units.
- 41:has(), :is() & :where()Use the parent selector :has(), group selectors with :is() and :where(), exclude elements with :not(), and understand how each affects specificity.
- 42Nesting & Logical PropsWrite nested CSS without a preprocessor using the & selector, and use logical properties like margin-inline and padding-block that work in every writing direction.
- 43Dark Mode & ColoursAdd dark mode with prefers-color-scheme, color-scheme and light-dark(), build a theme toggle, and mix colours with color-mix(), oklch() and relative colours.
- 44TransitionsAnimate changes smoothly between two states, from hover effects to menus.
- 45TransformsMove, rotate, scale and skew elements without disturbing the layout.
- 46AnimationsMulti-step animations with @keyframes: spinners, pulses and entrance effects.
- 47Shadows & GradientsDepth with box-shadow and colour blends with linear and radial gradients.
- 48clip-path & Blend ModesCut elements into shapes with clip-path, fade edges with mask-image, and blend colours and images with mix-blend-mode and background-blend-mode.
- 49Scroll Snap & ColumnsBuild swipeable carousels with scroll-snap, smooth anchor scrolling with scroll-behavior and scroll-margin, and newspaper-style text columns with the columns property.
What is CSS?
CSS (Cascading Style Sheets) is the language that controls how HTML looks: colours, fonts, spacing, layout and even animation. HTML says "this is a heading"; CSS says "make it large, dark blue and centred".
One CSS file can style an entire website. Change a colour in one place and every page updates. That's why every website, from a small personal blog to a large online shop, uses CSS.
This tutorial starts with the basics of writing rules and choosing colours, then builds up to real layouts with Flexbox and Grid, responsive pages that work on phones, and smooth animations. Every lesson includes examples you can edit and run, followed by exercises and a short quiz.
You should know the basics of HTML before starting. When you're done, JavaScript will make your pages interactive.
A short history of CSS
In the early web, pages were styled with HTML tags and attributes such as <font> and bgcolor. Every page carried its own styling, so changing a site's colours meant editing every file by hand. In 1994 Håkon Wium Lie, working with Tim Berners-Lee at CERN, proposed Cascading Style Sheets: a separate language that would describe how documents look, while HTML described what they contain. Bert Bos joined the work, and the W3C published CSS level 1 as a recommendation in 1996.
CSS 2 followed in 1998 with positioning and media types, and the long-lived CSS 2.1 tidied up the details. Browser support was patchy for years, and early web designers relied on tables and floats to build layouts. Instead of one giant CSS3 release, the language was then split into separate modules, such as Selectors, Colours and Backgrounds, that could each move forward at their own pace.
That modular approach brought the features modern CSS is known for. Flexbox became reliable in all major browsers in the mid 2010s, and CSS Grid arrived in 2017, finally giving the web a real two-dimensional layout system. Custom properties (CSS variables), clamp(), container queries, the :has() selector and native nesting have followed, which means many tasks that once needed JavaScript or a preprocessor can now be done in plain CSS.
How the course is organised
The 49 lessons are split into three stages. Basics (13 lessons) explains how CSS works and covers selectors, colours, backgrounds, borders, text, fonts, units and sizing. Intermediate (19 lessons) teaches the box model, display, positioning, Flexbox and Grid, then applies them to links, menus, forms, tables and images, and explains specificity and inheritance. Advanced (17 lessons) covers variables, media queries, responsive design, container queries, modern selectors, nesting, dark mode, transitions and animations.
The order matters. Layout makes much more sense once you understand the box model, and responsive design builds directly on Flexbox and Grid.
How to follow this course
Keep one small HTML page and style it as you go. Each time you learn something new, apply it to that page: a new colour scheme after the colours lesson, a centred card after Flexbox, a two-column layout after Grid. By the end of the course you'll have a single page that shows off everything you know.
Use your browser's developer tools from the start. Right-click any element, choose Inspect, and you can see every rule that applies to it, which ones were overridden and why. When a style doesn't do what you expect, the developer tools almost always show you the reason in seconds.
Thinking in CSS
Most CSS frustration comes from three ideas: the cascade, the box model and layout flow. The cascade decides which rule wins when several target the same element. The box model decides how much space an element really takes up. Layout flow decides where each element sits next to its neighbours. Once these three click, CSS stops feeling unpredictable, and the course returns to them again and again so they become second nature.
Good CSS is also about restraint. A small set of colours, a consistent spacing scale and a few reusable classes keep a site easy to change. The lessons on variables, specificity and inheritance show how professional teams keep large stylesheets under control.
What you will learn
9 practical skills, built one lesson at a time
- Write CSS rules and target exactly the elements you want
- Use colours, backgrounds, borders, fonts and text styles
- Understand the box model, margin and padding
- Build layouts with Flexbox and CSS Grid
- Make pages responsive for phones, tablets and desktops, with fluid images, type and navigation
- Style links, buttons, lists, navigation bars, forms, tables and images
- Use modern CSS: container queries, :has(), nesting, clamp() and dark mode
- Add hover effects, transitions, transforms and animations
- Organise styles with CSS variables and understand specificity
Practise CSS your way
Learning sticks when you use it. Pick a mode.
CSS Exercises
Fill in blanks, predict output and fix broken code with instant feedback.
277 exercisesCSS Quiz
5, 10 or 20 questions with a timer and explanations after every answer.
198 questionsCSS Cheat Sheet
Every important piece of syntax on one printable page.
Open cheat sheetCode Playground
A full HTML, CSS and JavaScript editor with live preview and console.
Open playgroundBuild projects with CSS
Real mini-projects with starter code, steps and a full solution.
Personal Profile Card
A clean, shareable profile card with a photo, name, bio, skills and social links.
Recipe Web Page
A well-structured, good-looking recipe page with an image, ingredients, steps and a facts table.
Tip Calculator
Split a bill between friends with live tip buttons. Your first real interactive app.
To-Do List App
Add, complete, delete and filter tasks, saved in the browser so they survive a refresh.
Digital Clock & Greeting
A live clock with date, a 12/24-hour toggle and a greeting that changes with the time of day.
Colour Palette Generator
Generate random harmonious palettes, lock favourites, copy HEX codes and press Space for new colours.
CSS FAQ
How long does it take to learn CSS?
You can learn the core of CSS in two to three weeks of regular practice. Layout with Flexbox and Grid is where most of the learning happens, so build a few small projects to make it stick.
Is CSS hard to learn?
The syntax is easy: it's mostly property: value;. What takes practice is layout, and understanding why a rule does or doesn't apply. That's exactly what the box model, Flexbox and specificity lessons focus on.
Do I need to learn HTML before CSS?
Yes. CSS styles HTML elements, so you need to know how to write them. The basics of our HTML tutorial are enough to start.
Should I learn a CSS framework like Tailwind or Bootstrap?
Learn plain CSS first. Frameworks are built on top of it, and you'll use them much more effectively once you understand what their classes actually do.
What is the difference between Flexbox and Grid?
Flexbox lays things out in one direction, either a row or a column. Grid works in two directions at once, with rows and columns. Most real layouts use both.
What does "cascading" mean in CSS?
When more than one rule targets the same element, the cascade decides which one wins. It looks at where the rule comes from, how specific its selector is and which rule comes last. Understanding the cascade, and the specificity lesson that explains it, solves most "why isn't my style working?" problems.
Is CSS a programming language?
Not in the traditional sense. CSS describes how things should look rather than giving step-by-step instructions. Modern CSS does have variables, functions such as calc() and clamp(), and conditions through media and container queries, so it rewards logical thinking just like programming does.
Do I still need media queries now that container queries exist?
Yes. Media queries respond to the size of the screen, which suits page-level layout. Container queries respond to the size of a component's parent, which suits reusable cards and widgets. Most modern sites use both, and the Advanced stage teaches when to choose each one.
How do I make my website look good on phones?
Start with a flexible layout using Flexbox or Grid, set images to scale with their container, use relative units such as rem and %, and add media queries where the design needs to change. The responsive design lessons cover each step with examples you can resize.
What should I learn after CSS?
JavaScript is the natural next step, because it makes your styled pages interactive. You'll use CSS and JavaScript together constantly, for example to open menus, switch to dark mode or animate elements when they scroll into view.
More tutorials
HTML
The skeleton of every web page. Start here.
Start HTMLJavaScript
The programming language that makes web pages interactive.
Start JavaScriptPython
A friendly first programming language for scripts, data and automation.
Start PythonJava
A reliable, widely used language for apps, Android and big systems.
Start JavaKotlin
The modern language for Android apps, servers and multiplatform code.
Start KotlinSwift
Apple's fast, safe language for iPhone, iPad, Mac and SwiftUI apps.
Start Swift