files/en-us/web/api/htmlelement/offsetparent/index.md
{{ APIRef("HTML DOM") }}
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 might be:
td, th, table in case the element itself is static positioned.If there is no positioned ancestor element, the body is returned.
[!NOTE]
offsetParentreturnsnullin the following situations:
- The element or any ancestor has the
displayproperty set tonone.- The element has the
positionproperty set tofixedand its containing block is the viewport. If the containing block is not the viewport,offsetParentreturns the nearest ancestor that forms a containing block, for example, an ancestor withtransform,perspective, orfilterstyles set.- The element is
<body>or<html>.
offsetParent is useful because
{{domxref("HTMLElement.offsetTop","offsetTop")}} and
{{domxref("HTMLElement.offsetLeft","offsetLeft")}} are relative to its padding edge.
An object reference to the element in which the current element is offset.
{{Specifications}}
{{Compat}}