Style top property
The Style object
Definition and Usage
The top property sets or returns the top position of a positioned element.
This property specifies the top position of an element, including: padding, scrollbar, border and margin.
**Tip:** A positioned element is an element whose position property is set to: relative, absolute, or fixed.
Syntax
Set the top property:
Object.style.top="auto|
length
|
%
|inherit"
Return the top property:
Object.style.top
| Value | Description |
|---|---|
| auto | Default. The top position is calculated by the browser. |
| length | Defines the position of the top edge of the element relative to the top edge of the nearest positioned parent element, using units such as px and cm. Negative values are allowed. |
| % | Defines the percentage position of the top edge of the element relative to the top edge of the nearest positioned parent element. |
| inherit | The value of the top property is inherited from the parent element. |
Browser support





All major browsers support the top property.
**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".
Example
Example
Set the top position of a button:
Try it »
The Style object