W3cubDocs

/Web APIs

HTMLElement: offsetParent property

The HTMLElement.offsetParent read-only property returns a reference to the element which is the closest (nearest in the containment hierarchy) positioned ancestor element.

A positioned ancestor is either:

  • an element with a non-static position, or
  • td, th, table in case the element itself is static positioned.

If there is no positioned ancestor element, the body is returned.

Note: offsetParent returns null in the following situations:

  • The element or any ancestor has the display property set to none.
  • The element has the position property set to fixed (Firefox returns <body>).
  • The element is <body> or <html>.

offsetParent is useful because offsetTop and offsetLeft are relative to its padding edge.

Value

An object reference to the element in which the current element is offset.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
offsetParent 1 12 1 5.5 8 3 4.4 18 4 10.1 1 1.0

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent