docs.rodeo

MDN Web Docs mirror

top

{{CSSRef}} 

The top CSS property sets the vertical position of a positioned element. This {{glossary("inset properties", "inset property")}}  has no effect on non-positioned elements.

{{EmbedInteractiveExample("pages/css/top.html")}} 

The effect of top depends on how the element is positioned (i.e., the value of the {{cssxref("position")}}  property):

When both top and {{cssxref("bottom")}}  values are specified, there are three different cases:

Syntax

/* <length> values */
top: 3px;
top: 2.4em;
top: anchor(bottom);
top: anchor-size(--myAnchor self-block, 10%);

/* <percentage>s of the height of the containing block */
top: 10%;

/* Keyword value */
top: auto;

/* Global values */
top: inherit;
top: initial;
top: revert;
top: revert-layer;
top: unset;

Values

Formal definition

{{CSSInfo}} 

Formal syntax

{{csssyntax}} 

Examples

A positioned element set 10% from the top

body {
  background: beige;
}

div {
  position: absolute;
  top: 10%;
  right: 40%;
  bottom: 20%;
  left: 15%;
  background: gold;
  border: 1px solid blue;
}
<div>The size of this content is determined by the position of its edges.</div>

{{EmbedLiveSample('Examples','100%','200')}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN