Lesson info

Lesson info

Using the position property is one of many ways you can change the layout and positioning of an element. This property is unique in that it allows elements to be positioned relative to themselves (relative), relative to a parent element (absolute), or relative to the viewport, even when the page is scrolled (fixed). The flexibility of the position property makes it possible to create very unique web layouts. You can even specify the stacking order of positioned elements that overlap other elements using the z-index property.

Here we’ll cover the values you can set for the position property:

  1. ‍Auto
  2. ‍Relative
  3. Absolute
  4. ‍Fixed
Clone this projectDownload project assetsDownload lesson assets


An element's Position can be set in a number of ways. This is really helpful when we're creating designs that require overlapping elements, or even elements that are persistently Positioned on the viewport, regardless of your scroll Position.

We'll talk about these four: Auto (or Static), Relative, Absolute, and Fixed. This is a quick crash course on these four.

Let's do Auto. This is what we generally refer to as the "normal document flow." (Elements stacking and wrapping like we'd expect in a Word document).

But for now, let's do Relative Positioning. Three images side-by-side. Three paragraphs underneath. The second image, with Relative Positioning we can move this left and right to partially overlap the other images. And what's cool about Relative Positioning is it doesn't interrupt or mess with the normal document flow. It leaves a seat warmer in its place. Its spot is held and moving it isn't messing with other content.

Let's do this with the paragraphs. Same thing with Relative Positioning here. We can overlap other content without affecting the normal document flow.

Let's do Absolute Positioning. Same setup as Relative here. But when we set this element to Absolute? It's completely removed from the document flow. Yanked out. In this case, the image's parent element has its Position set to Relative, which means our Absolutely-Positioned image is Positioned around that parent element.

And finally, let's cover Fixed. Fixed elements are Positioned around the viewport; not their parent element. That means we can scroll down the page and the Fixed elements stay Fixed — they stay where they are Relative to the viewport.

So, auto (or Static) Positioning respects the normal document flow. Relative Positioning lets us move our elements around without messing with the document flow. Absolute Position positions content around its parent element. And Fixed Position positions content Relative to the viewport, persistently holding something where it is regardless of scrolling.