1. css
  2. /properties
  3. /offset-position

offset-position

Definition

offset-position is a CSS property that defines the positioning of an element relative to a specified anchor point using the offset property in combination with other offset properties like offset-anchor, offset-distance, or offset-path. The offset position can be defined using keywords or length values.

Examples

In this example, the offset-anchor property is set to nearest, which sets the anchor point to the nearest positioned ancestor. The offset-position property is set to top right, which positions the element 20px to the top and right of the anchor point:

.element {
  position: absolute;
  offset: 20px;
  offset-anchor: nearest;
  offset-position: top right;
}

In this example, the offset-anchor property is set to 0 0, which sets the anchor point to the top left corner of the viewport. The offset-position property is set to 50% 50%, which positions the element 20px to the right and down from the center of the viewport:

.element {
  position: absolute;
  offset: 20px;
  offset-anchor: 0 0;
  offset-position: 50% 50%;
}

In this example, the offset-anchor property is set to a CSS selector for an element with the ID of #anchor. The offset-position property is set to bottom left, which positions the element 20px to the bottom and left of the anchor element:

.element {
  position: absolute;
  offset: 20px;
  offset-anchor: #anchor;
  offset-position: bottom left;
}

#anchor {
  position: absolute;
  top: 100px;
  left: 100px;
}

Values

ValueDescription
autoThe default value, which lets the browser decide the offset position.
top, right, bottom, leftPositions the element relative to the anchor point using these directions.
<length>, <percentage>Specifies the distance from the anchor point in pixels or a percentage of the containing block's size.
<custom-ident>Specifies a CSS selector for an element to use as the anchor point.

Best Practices

  • Use offset-position in conjunction with other offset properties to position an element relative to a specified anchor point.
  • Be mindful of the anchor point and how it will affect the element's position.
  • Avoid using offset-position with values that will cause the element to be positioned outside of its containing block, as it can cause layout and rendering issues.
  • Test your designs on different devices and screen sizes to ensure that the element is positioned correctly.
  • Be mindful of performance when using offset-position, as it can cause layout and rendering issues on complex or animated elements.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesNoYesYes