Skip to content
Learn Netverks

Lesson

Step 25/31 81% through track

positioning-layers

Positioning: relative, absolute, and fixed

Last reviewed Jun 1, 2026 Content v20260601
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
intermediate

This lesson

This lesson teaches Positioning: relative, absolute, and fixed—the ideas, syntax, and habits you need before moving on in HTML & CSS.

Without a solid grasp of Positioning: relative, absolute, and fixed, you will repeat mistakes in HTML & CSS exercises and on real pages or scripts.

You will apply Positioning: relative, absolute, and fixed in contexts like: Landing pages, dashboards, marketing sites, and portfolio pieces built without a framework.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs.

Toward the end of the track—use it to consolidate patterns before the capstone or summary lessons.

Position lets you take elements out of normal flow when you need overlays: badges on cards, dropdown panels, sticky headers, and modal backdrops. Used carelessly, it causes invisible overlaps and broken mobile layouts.

Quick reference

  • static — default; layout in normal flow.
  • relative — stays in flow; creates an offset box and a positioning context for children.
  • absolute — removed from flow; positioned against the nearest ancestor with non-static position (or the viewport).
  • fixed — like absolute, but anchored to the viewport (watch mobile browser chrome).
  • sticky — hybrid; acts relative until a scroll threshold, then fixed within its container.

HTML + CSS pattern: badge on a card

Wrap the card in position: relative and place the badge with position: absolute; top; right. The HTML stays a simple article; CSS handles placement.

Practice flow

  1. Run the playground and note badge placement.
  2. Remove position: relative from the card—watch the badge jump to another ancestor.
  3. Add position: sticky; top: 0 to the header bar and scroll the page content.

Challenge

Anchor a notification dot

  1. Add a .dot on the avatar with position: absolute.
  2. Place it at top: 0; right: 0 with a red background.

Done when: the dot stays on the avatar corner when you resize the preview.

Go deeper — Containing blocks and containing layout (intermediate / experienced)

Absolutely positioned elements resolve against a containing block. For absolute, that is the nearest ancestor with transform, filter, perspective, or non-static position—not always the element you expect. In interviews, mention you verify in DevTools → Computed → position and scroll the ancestor chain.

fixed descendants can become relative to a transformed parent in modern browsers—another reason to keep transform on a deliberate wrapper.

Pitfalls

  • Using absolute positioning for entire page layout instead of flex/grid.
  • Forgetting to set a positioned ancestor, so overlays attach to the viewport.
  • Tiny click targets on absolutely positioned icons without padding.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What part of this lesson needs a second read?
  • What would you try differently in a real project?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump