Course contentsShow
← Web Development
Lesson 228 of 2,9824. CSS Layout FoundationsFree lesson

The Root Stacking Context

How the html element creates the root stacking context and serves as the foundation for all layering.

The Root Stacking Context

You'll learn: How the <html> element automatically creates the foundation for all visual layering in your web page.

What Is the Root Stacking Context?

Remember learning about stacking contexts in the previous lesson? Every single web page has at least one stacking context by default—the root stacking context. This context is automatically created by the <html> element (the topmost element in your HTML document) and serves as the container for all other elements and any additional stacking contexts you create.

Think of the root stacking context like the canvas of a painting. Before you can layer paint strokes on top of each other, you need that initial canvas surface. The <html> element provides that foundational layer for your entire page. Everything you see—every positioned element, every z-index value, every nested stacking context—exists within this root context.

Why It Matters

The root stacking context establishes the baseline rules for how elements stack. When you position elements using relative, absolute, fixed, or sticky, or when you create new stacking contexts with properties like z-index, they all ultimately exist within this root context created by <html>.

You never need to explicitly create the root stacking context—it's always there automatically. But understanding that it exists helps explain why certain layering behaviors happen the way they do, especially when dealing with complex positioning scenarios.

Key Takeaway: The <html> element automatically creates the root stacking context, which acts as the foundational layer containing all other elements and nested stacking contexts on your page.