CSS topProperty
Example
Set the top edge of the image to a position 5 pixels below the top edge of its containing element:
img
{
position:absolute;
top:5px;
}
{
position:absolute;
top:5px;
}
Try it Yourself »
Property definition and usage instructions
The top property specifies the top edge of an element. This property defines the offset between the top margin edge of a positioned element and the top edge of its containing block.
For relatively positioned elements, if both top and bottom are auto, their computed values are both 0; if one of them is auto, it takes the opposite value of the other; if neither is auto, bottom takes the opposite value of top.
Note:If the value of the "position" property is "static", setting the "top" property has no effect.
| Default value: | auto |
|---|---|
| Inherited: | no |
| version: | CSS2 |
| JavaScript Syntax: | object.style.top="50px" |
Browser Support
The numbers in the table indicate the first browser version that supports the property.
| Property | |||||
|---|---|---|---|---|---|
| top | 1.0 | 5.0 | 1.0 | 1.0 | 6.0 |
Property value
| Value | Description |
|---|---|
| auto | Default value. The position of the top edge is calculated by the browser. |
| % | Sets the position of the top edge as a percentage of the containing element. Negative values are allowed. |
| length | Sets the position of the element's top edge using units such as px, cm. Negative values are allowed. |
| inherit | Specifies that the value of the top property should be inherited from the parent element. |
Related Articles
CSS Tutorial:CSS Positioning
other extensions