Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS top property

CSS top property

Example

Set the image's top edge 5 pixels below its containing element's top edge:

img

{

position:absolute;

top:5px;

}

Try it »


Property definition and usage

The top property specifies the top edge of an element. It 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 of the other value; if neither is auto, bottom takes the opposite of the top value.

Note: If 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 this property.

property
top 1.0 5.0 1.0 1.0 6.0

Attribute values

Value Description
auto Default. The top edge position is calculated by the browser.
% Sets the top position as a percentage of the containing element. Negative values are allowed.
length Sets the top position of the element using units such as px, cm, etc. Negative values are allowed.
inherit Specifies that the top property should be inherited from the parent element.

Related Articles

CSS Tutorial: CSS Positioning