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

Offset Properties: top, right, bottom, left

Using offset properties to move positioned elements from their reference point.

Offset Properties: top, right, bottom, left

You'll learn how to use the four offset properties to precisely move positioned elements away from their reference point.

What Are Offset Properties?

When you apply positioning to an element (like position: relative from the previous lesson), the element gains the ability to move. But how do you actually move it? That's where the offset properties come in: top, right, bottom, and left.

These properties define how far the element should shift from its reference point. Think of them as giving directions: "Move 20px down from the top" or "Shift 10px away from the left side."

How They Work

Each offset property takes a distance value (usually in pixels, ems, or percentages) and moves the element:

  • top: Moves the element down from its top edge
  • bottom: Moves the element up from its bottom edge
  • left: Moves the element right from its left edge
  • right: Moves the element left from its right edge

For a relatively positioned element, these offsets move it from where it would normally be in the flow:

.shift-down {
  position: relative;
  top: 20px; /* Moves 20px down from original position */
}

.shift-right {
  position: relative;
  left: 30px; /* Moves 30px to the right */
}

You can combine them too:

.diagonal-shift {
  position: relative;
  top: 15px;
  left: 25px; /* Moves both down and right */
}

Important Note

The properties are named for the edge they reference, but they push away from that edge. top: 20px pushes the element 20px down from the top, not up!

Key Takeaway: Offset properties (top, right, bottom, left) control how far a positioned element moves from its reference point, with each property pushing the element away from the named edge.