CSS Intro

CSS Intro Quiz

CSS Intro Exercise

CSS Basic

CSS Basic Quiz

CSS Basic Exercise

CSS Advance

CSS Advance Quiz

CSS Advance Exercise


CSS3 Quiz

CSS3 Exercise

CSS Properties

CSS Functions

CSS Selectors

CSS top Property

CSS top Property



The top property is used to change the vertical position of a positioned element. It does not work on non-positioned elements.

  1. If position is absolute or position is fixed then the top property sets the top of an element to a unit to the top of the top edge of its nearest positioned ancestor.
  2. If position is relative then the top property sets the top of an element to a unit to the top/bottom of its normal position.
  3. If position is sticky then the top property behaves like its position is relative when the element is inside the viewport, and like its position is fixed when it is outside.
  4. If position is static then the top property has no effect.


Default Value:-


Its default value is auto.




Its syntax is:- top : auto | length | initial | inherit;


Further Explanation:-


Value Description
auto Lets the browser calculate the top edge position.
length Sets the top edge position in px, cm, etc.
% Sets the top edge position in % of containing element.
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Code Explanation

All Tutorials related to CSS Properties

All Sections related to CSS