CSS top Property
Description
The top
CSS property specifies the vertical position of a positioned element. It has no effect on non-positioned elements. The top
property can be used to position an element relative to its containing block, which is the ancestor element that establishes the element's normal position. The containing block is typically the nearest positioned ancestor, but it can also be the document body if no positioned ancestor is found.
- Initial value
- auto
- Applies to
- Positioned elements
- Inherited
- No
- Computed value
- If specified as a length, the corresponding absolute length; if specified as a percentage, the specified value; otherwise, 'auto'.
- Animatable
- Yes
- JavaScript syntax
- object.style.top
Interactive Demo
Syntax
top: auto | <length> | <percentage>
Values
- <length>Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px).
- <percentage>Integer, followed by a percent sign (%). The value is a percentage of the height of the parent object.
- autoDefault position, according to the regular HTML layout of the page.
Example
<div class="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
<div class="menu">Ut wisi enim ad minim veniam, quis nostrud exerci taion ullamcorper suscipit lobortis nisl ut aliquip ex en commodo consequat. </div>
.menu {
position: absolute;
left: 300px;
top: 50px;
width: 120px;
background: #e0e0e0;
border: 1px solid #000;
padding: 5px;
}
.content {
position: absolute;
left: 0;
top: 0;
width: 280px;
background: #00a5b6;
color: white;
padding: 5px;
padding-right: 60px;
text-align: justify;
}
Browser Support
The following table will show you the current browser support for the CSS top
property.
Desktop | |||||
12 | 1 | 1 | 6 | 1 |
Tablets / Mobile | |||||
18 | 4 | 14 | 1 | 1 | 37 |
Last updated by CSSPortal on: 1st January 2024