Style top property
- Previous Page textTransform
- Next Page transform
- Go to the Previous Level HTML DOM Style Object
Definition and Usage
top
Property to set or return the top position of a positioned element.
This property specifies the top position of the element, including padding, scrollbars, borders, and margins.
Tip:The positioned element is position property Set to:relative
,absolute
or fixed
.
Tip:To set or return the bottom position of a positioned element, use bottom property.
See also:
CSS Tutorial:CSS Positioning
CSS Reference Manual:top property
Example
Example 1
Set the top position of the <button> element:
document.getElementById("myBtn").style.top = "100px";
Example 2
Use negative values - set the top position of the <div> element:
document.getElementById("myDiv").style.top = "-100px";
Example 3
Return the top position of the <div> element:
alert(document.getElementById("myDiv").style.top);
Syntax
Return the top property:
object.style.top
Set the top property:
object.style.top = "auto|length|%|initial|inherit"
Property Value
Value | Description |
---|---|
auto | Let the browser set the top position. Default. |
length | Define the top position with length units. Negative values are allowed. |
% | Set the top position with the percentage of the parent element's height. |
initial | Set this property to its default value. See initial. |
inherit | Inherit this property from its parent element. See inherit. |
Technical Details
Default Value: | None |
---|---|
Return Value: | A string that represents the top position of the located element. |
CSS Version: | CSS2 |
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page textTransform
- Next Page transform
- Go to the Previous Level HTML DOM Style Object