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

Display and positioning

Before Flexbox and Grid, you need to understand normal flow: how the browser places elements by default. Then you'll learn to take elements out of the flow with position.

Block vs inline

HTML · CSS · live preview
Preview
display Starts a new line? Width/height work? Examples
block Yes Yes div, p, h1, section
inline No No (only horizontal padding/margin push things) span, a, strong
inline-block No Yes Buttons, badges
none Removed completely — Hidden elements
flex / grid Block container whose children follow flex/grid rules Yes Layouts (next lessons)
HTML · CSS · live preview
Preview

Hiding things

  • display: none: removed from the layout and from screen readers.
  • visibility: hidden: invisible, but still takes up space.
  • opacity: 0: invisible but still clickable (careful!).

Positioning

The position property, combined with top, right, bottom, left and z-index, moves elements.

relative: nudge from its normal place

HTML · CSS · live preview
Preview

absolute: placed relative to the nearest positioned ancestor

This is the classic pattern for badges, icons and overlays:

HTML · CSS · live preview
Preview

The golden pattern: parent position: relative; + child position: absolute;. The child is placed relative to the parent. Without a positioned parent, it's placed relative to the whole page.

fixed: stuck to the viewport

HTML · CSS · live preview
Preview

sticky: normal until you scroll past it

HTML · CSS · live preview
Preview

The site header on this website uses position: sticky.

Stacking with z-index

When positioned elements overlap, z-index decides which is on top: higher numbers sit closer to you. It only works on positioned (or flex/grid) elements.

HTML · CSS · live preview
Preview

Practice

Build a product image card with: an image, a "−20%" sale badge in the top-left corner (absolutely positioned), and a heart "favourite" button in the top-right. Then add a sticky "Add to cart" bar at the bottom of a scrollable product description.

HTML · CSS · live preview
Preview
✎ Check your understanding

1.A child has position: absolute; top: 0; right: 0. What is it positioned relative to?

2.Which hides an element but keeps its space in the layout?

← The box model