Learn CSS Online with a Free Interactive Editor

Learn CSS online with a free, beginner-friendly tutorial and a live CSS editor built into this page. Read a short lesson, edit real CSS classes, and watch the preview update instantly — no installation, no sign-up, nothing to download.

Lesson
CSS Editor
Copied!
Live Preview

Learn CSS for Free: A Complete Beginner's Guide to CSS Classes

CSS (Cascading Style Sheets) is the language that controls how a web page looks — colors, spacing, fonts, layout, and everything else HTML doesn't handle on its own. If you want to learn CSS online, the quickest path is to stop reading about selectors and start writing them, which is exactly what the live editor above lets you do against a real component.

What a CSS class actually is

A CSS class is a label you attach to an HTML element with the class attribute, so a style rule can target it. Write <div class="card"> in your HTML, then .card { } in your CSS, and every element carrying that class picks up the styles inside the curly braces. The same class can be reused on as many elements as you like, which is what makes classes the backbone of almost every real stylesheet — far more common than styling by tag name or ID.

Selectors: how CSS finds what to style

A selector is the part of a rule before the curly braces, and it decides which elements the rule applies to. An element selector like p matches every paragraph. A class selector like .card matches anything with class="card". An ID selector like #header matches the one element with that ID. You can also combine selectors — .card p targets paragraphs sitting inside anything with the class card.

Common CSS properties at a glance

PropertyControls
colorText color
backgroundBackground color or image
margin / paddingSpace outside / inside an element's border
borderAn element's outline and its style
displayHow an element takes up space (block, flex, grid...)
font-size / font-familyText size and typeface
flex / grid-template-columnsLayout of child elements
transitionSmooth animation between style changes

For the complete, official property list, the MDN CSS reference is the resource most working developers keep open in another tab.

The cascade: why "cascading" is in the name

When more than one rule could apply to the same element, CSS has to decide which one wins. That decision comes down to specificity (an ID beats a class, a class beats a tag name) and source order (later rules win ties). Understanding the cascade is what turns confusing "why isn't my style applying" moments into predictable, fixable ones.

A simple order to learn CSS in

  • Start with selectors and classes, plus colors, fonts, and basic text styling.
  • Learn the box model — margin, border, padding, width, and height — since almost every layout bug traces back to it.
  • Move on to display, position, and then Flexbox for one-dimensional layouts.
  • Add CSS Grid for two-dimensional layouts, and media queries for responsive design.
  • Finish with transitions, animations, and pseudo-classes like :hover for polish.

Switch between the preview components above, tweak their classes in the live editor, then test yourself with the exercises and quiz below — that repetition is what makes CSS syntax stick.

Where CSS fits going forward

Once classes, the box model, and Flexbox feel natural, most people pick up CSS Grid and a preprocessor or utility framework out of convenience — but every one of those tools still compiles down to the plain CSS you're practicing here. Time spent understanding real CSS classes and selectors keeps paying off no matter which framework you use later.

CSS Exercises

Write a real CSS rule in each box, then check your answer. Everything runs in your browser — nothing is sent anywhere.

CSS Quiz

Ten questions to test what you know. Your best score is saved on this device.

Frequently Asked Questions

CSS (Cascading Style Sheets) is the language used to style HTML — controlling color, spacing, fonts, and layout.

A class labels one or more HTML elements so a single CSS rule, written once, can style all of them consistently.

CSS has a steeper learning curve than HTML because of the box model and the cascade, but with practice on real examples it becomes intuitive fairly quickly.

A class can be reused on many elements, while an ID should be unique to a single element on the page and carries higher specificity.

Yes — the live editor on this page lets you write CSS and see it applied to real components instantly, at no cost.

Basic HTML helps, since CSS styles HTML elements, but you can pick up both together — this page's classes and demo markup are provided for you. If you want to start with HTML first, our free interactive HTML tutorial covers the basics in the same style as this page.

Flexbox arranges elements in a single row or column and distributes space between them, making it the standard tool for one-dimensional layouts like navbars.

Yes, this editor and all of its lessons, exercises, and quizzes are free to use.

More Developer Tools

Other free editors from the same toolbox.