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.

{{InteractiveExample("CSS Demo: top")}} 

top: 0;
top: 4em;
top: 10%;
top: 20px;
<section id="default-example">
  <div class="example-container">
    <div id="example-element">I am absolutely positioned.</div>
    <p>
      As much mud in the streets as if the waters had but newly retired from the
      face of the earth, and it would not be wonderful to meet a Megalosaurus,
      forty feet long or so, waddling like an elephantine lizard up Holborn
      Hill.
    </p>
  </div>
</section>
.example-container {
  border: 0.75em solid;
  padding: 0.75em;
  text-align: left;
  position: relative;
  width: 100%;
  min-height: 200px;
}

#example-element {
  background-color: #264653;
  border: 4px solid #ffb500;
  color: white;
  position: absolute;
  width: 140px;
  height: 60px;
}

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