Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

CSS
CSS
0/10 completed
Beginner
Selectors and propertiesColors and fontsThe box modelDisplay and positioning
Intermediate
FlexboxCSS GridResponsive design
Advanced
Transitions and animationsCSS variables and architecture
Pro
Modern CSS: :has(), container queries and layers
Tracks / CSS / Beginner

Selectors and properties

CSS (Cascading Style Sheets) controls how HTML looks: colours, fonts, spacing and layout. HTML says what something is; CSS says how it looks.

Anatomy of a CSS rule

css
selector {
  property: value;
  another-property: value;
}
HTML · CSS · live preview
Preview

Three ways to add CSS

html
<!-- 1. External stylesheet: best for real projects (cached and reusable) -->
<link rel="stylesheet" href="styles.css">

<!-- 2. <style> in the head: handy for demos (like this site) -->
<style> p { color: navy; } </style>

<!-- 3. Inline style attribute: avoid; hard to maintain and overrides everything -->
<p style="color: navy">Hi</p>

Basic selectors

HTML · CSS · live preview
Preview

An element can have several classes: class="card featured dark".

Combinators: selecting by relationship

HTML · CSS · live preview
Preview

Attribute selectors

HTML · CSS · live preview
Preview

Pseudo-classes: selecting by state or position

HTML · CSS · live preview
Preview

Pseudo-elements: styling part of an element

HTML · CSS · live preview
Preview

Pseudo-classes use one colon (:hover); pseudo-elements use two (::before).

Practice

Style a to-do list using only selectors (no classes on the list items): make every odd item light grey, the first item bold, strike through items whose data-done attribute is "true" ([data-done="true"]), and turn items blue on hover.

HTML · CSS · live preview
Preview
✎ Check your understanding

1.Which selector targets every element with class="card"?

2.What does ul > li select?