Favorites

CSS position Property

position
CSS PropertyThis property is supported by all modern browsers.
Updated 22nd November 2026

The position property sets how an element is positioned: static, relative, absolute, fixed or sticky, used with top, right, bottom and left.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The position property controls how an element is placed in the page and how it participates in the document’s normal flow. It determines whether an element leaves space where it would normally be, or whether it is removed from that flow and overlaid on top of other content. That placement decision also affects which box is used as the element’s reference for offset calculations and whether the element creates a new stacking context; stacking order is further influenced by z-index.

Because offsets are interpreted relative to the element’s chosen reference, the meaning of offset properties such as top and left depends on the positioning mode in effect. Ancestor properties that establish new containing blocks or transform the coordinate system — for example an applied transform on a parent — can change where and how a positioned descendant is anchored, which is important when you want an element to be tied to a specific container rather than to the viewport.

Positioning interacts with normal layout behavior and other layout properties. How elements behave in flow alongside or around positioned items depends on their formatting context; for instance, the overall rendering will differ if you combine positioning with different display or float strategies. Likewise, spacing rules such as margin and wrapping behavior still matter when building responsive UIs, so mixing out-of-flow elements with flow-based layout requires care to avoid overlaps, unexpected reflow, or accessibility issues.

In practical use, this property is commonly used to create overlays, anchored UI elements, or to remove an element from normal layout to position it precisely. Because it affects stacking and flow, it’s a powerful tool but can also make layouts harder to maintain if overused; prefer clear containment and predictable anchoring (for example by keeping positioned elements within a well-defined container) and test across sizes to ensure responsive behavior.

Definition

Initial value
static
Applies to
All elements except for generated content
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.position

Interactive Demo

Pick an option, then scroll this box.

Positioned

More content in the scrolling box.

More content in the scrolling box.

More content in the scrolling box.

More content in the scrolling box.

More content in the scrolling box.

More content in the scrolling box.

Demo Code
HTML Code
<div class="demo-scroll">
	<p>Pick an option, then scroll this box.</p>
	<div class="demo-element">Positioned</div>
	<p>More content in the scrolling box.</p>
	<p>More content in the scrolling box.</p>
	<p>More content in the scrolling box.</p>
	<p>More content in the scrolling box.</p>
	<p>More content in the scrolling box.</p>
	<p>More content in the scrolling box.</p>
	</div>
CSS Code
.demo-scroll {
	position: relative;
	width: 300px;
	height: 190px;
	overflow: auto;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
}
.demo-scroll p {
	margin: 10px;
	font-size: 14px;
	color: #444;
}
.demo-element {
	width: 90px;
	padding: 10px;
	background: #f72585;
	color: #fff;
	font-size: 14px;
	position: static;
}

Syntax

position: static | relative | absolute | fixed | sticky

Values

  • staticThis keyword let the element use the normal behavior, that is it is laid out in its current position in the flow. The top, right, bottom, and left properties do not apply.
  • relativeThis keyword lays out all elements as though the element were not positioned, and then adjust the element's position, without changing layout (and thus leaving a gap for the element where it would have been had it not been positioned).
  • absoluteDo not leave space for the element. Instead, position it at a specified position relative to its closest positioned ancestor or to the containing block. Absolutely positioned boxes can have margins, they do not collapse with any other margins.
  • stickyThe box position is calculated according to the normal flow (this is called the position in normal flow). Then the box is offset relative to its flow root and containing block and in all cases, including table elements, does not affect the position of any following boxes.
  • fixedDo not leave space for the element. Instead, position it at a specified position relative to the screen's viewport and doesn't move when scrolled. When printing, position it at that fixed position on every page.

Example

<section class="position-demo">
<h1>CSS position property demo</h1>
<p>Try scrolling to see sticky and fixed behavior.</p>

<div class="container">
<div class="box static">Static</div>

<div class="box relative">Relative
<span class="note">top: 10px; left: 10px;</span>
</div>

<div class="box absolute">Absolute</div>

<div class="box sticky">Sticky</div>

<div class="box">Other content to create flow</div>
</div>

<div class="spacer"></div>
</section>

<div class="box fixed">Fixed</div>
/* Basic page styles */
body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
    margin: 0;
    padding: 20px;
    background: #f7f7fb;
    color: #0f172a;
}

.position-demo {
    max-width: 900px;
    margin: 0 auto;
}

h1 {
    font-size: 20px;
    margin: 0 0 8px 0;
}

p {
    margin: 0 0 12px 0;
    color: #475569;
}

/* Container demonstrates positioning context for absolute */
.container {
    position: relative; /* positions absolute children relative to this box */
    border: 1px dashed #cbd5e1;
    padding: 20px;
    height: 220px;
    overflow: auto;
    background: #ffffff;
    border-radius: 8px;
}

.box {
    padding: 10px 14px;
    background: #e2e8f0;
    border-radius: 6px;
    margin-bottom: 12px;
    width: 160px;
}

.static {
    /* position: static (default)  -  participates in normal flow */
}

.relative {
    position: relative; /* offset from its normal position */
    top: 10px;
    left: 10px;
    background: #c7f9cc;
}

.absolute {
    position: absolute; /* removed from flow; positioned relative to .container */
    top: 20px;
    right: 20px;
    background: #ffd8a8;
}

.fixed {
    position: fixed; /* fixed to the viewport */
    bottom: 20px;
    right: 20px;
    background: #ffd6e0;
    box-shadow: 0 4px 10px rgba(2,6,23,0.08);
}

.sticky {
    position: sticky; /* sticks to top of viewport when scrolled */
    top: 0;
    background: #cfe8ff;
    z-index: 2;
}

.note {
    display: block;
    font-size: 12px;
    color: #475569;
    margin-top: 6px;
}

.spacer {
    height: 800px; /* create scrollable page to demonstrate sticky & fixed */
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS position property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.