HTMLElement.offsetParent

The HTMLElement.offsetParent read-only property returns a reference to the element which is the closest (nearest in the containment hierarchy) positioned ancestor element. If there is no positioned ancestor element, the nearest ancestor tdthtable will be returned, or the body if there are no ancestor table elements either.

NOTE:

offsetParent returns null in the following situations:

  • The element or its parent element 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.

Syntax

parentObj = element.offsetParent;
  • parentObj is an object reference to the element in which the current element is offset.

Specification

Specification Status Comment
CSS Object Model (CSSOM) View Module
The definition of 'offsetParent' in that specification.
Working Draft

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
offsetParent
Experimental
Chrome Full support 47Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support 11WebView Android Full support 47Chrome Android Full support 47Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.