Style top Property
Clash Royale CLAN TAG#URR8PPP
<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]-->
Style top Property
❮ Style Object
Example
Set the top position of a <button> element:
document.getElementById("myBtn").style.top = "100px";
Try it Yourself »
Definition and Usage
The top property sets or returns the top position of a positioned element.
This property specifies the top position of the element including padding, scrollbar, border and margin.
Tip: A positioned element is an element with the position property set to: relative, absolute, or fixed.
Tip: To set or return the bottom position of a positioned element, use the bottom property.
Browser Support
Property | |||||
---|---|---|---|---|---|
top | Yes | Yes | Yes | Yes | Yes |
Syntax
Return the top property:
object.style.top
Set the top property:
object.style.top = "auto|length|%|initial|inherit"
Property Values
Value | Description |
---|---|
auto | Lets the browser set the top position. This is default |
length | Defines the top position in length units. Negative values are allowed |
% | Sets the top position in % of the height of the parent element |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]-->
Technical Details
Default Value: | auto |
---|---|
Return Value: | A String, representing the top position of a positioned element |
CSS Version | CSS2 |
More Examples
Example
Using negative values - Set the top position of a <div> element:
document.getElementById("myDiv").style.top = "-100px";
Try it Yourself »
Example
Return the top position of a <div> element:
alert(document.getElementById("myDiv").style.top);
Try it Yourself »
Related Pages
CSS tutorial: CSS Positioning
CSS reference: top property
❮ Style Object