CSS position Property

Beginner
⏱️ 8 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The position property controls how elements are placed on the page. It is one of the most important CSS properties for badges, overlays, navbars, and scroll-based UI.

01

static

Normal flow.

02

relative

Small offsets.

03

absolute

Inside parent.

04

fixed

Viewport lock.

05

sticky

Scroll stick.

06

Offsets

top left right.

Introduction

The position property in CSS specifies the type of positioning method used for an element.

This property allows you to control the layout and positioning of elements on a web page, giving you flexibility in designing complex and responsive layouts. Understanding how to use the position property effectively is essential for creating well-structured web pages.

Definition and Usage

Most page content uses the default static positioning. Switch to relative when you need a small visual nudge or when you want to create a positioning context for children.

Use absolute for badges and overlays inside a card, fixed for navbars and floating action buttons, and sticky for headings that should stay visible while scrolling a section.

💡
Beginner Tip

top, right, bottom, and left only affect positioned elements — that is, anything except position: static.

📝 Syntax

The syntax for the position property is as follows:

syntax.css
element {
  position: value;
}

Here, value can be one of several keywords that define the positioning behavior of the element.

Basic Example

position-relative.css
.badge-wrapper {
  position: relative;
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
}

Syntax Rules

  • static is the default and follows normal document flow.
  • relative offsets an element but keeps its original space reserved.
  • absolute is positioned against the nearest non-static ancestor.
  • fixed is positioned relative to the browser viewport.
  • sticky needs a scroll threshold such as top: 0.
  • Combine with z-index when layers overlap.

🎯 Default Value

The default value of the position property is static. This means that the element is positioned according to the normal flow of the document.

⚡ Quick Reference

QuestionAnswer
Default valuestatic
Removed from flowabsolute, fixed
Creates positioning contextrelative, absolute, fixed, sticky
Offset propertiestop, right, bottom, left
InheritedNo
Common useBadges, navbars, overlays, sticky headings

💎 Property Values

ValueExampleDescription
staticposition: static;The element is positioned according to the normal flow of the document. This is the default value.
relativeposition: relative;The element is positioned relative to its normal position. Setting top, right, bottom, or left adjusts it away from that spot.
absoluteposition: absolute;The element is positioned relative to its nearest positioned ancestor. If none exists, it uses the initial containing block.
fixedposition: fixed;The element is positioned relative to the viewport and stays in place when the page scrolls.
stickyposition: sticky;The element toggles between relative and fixed based on scroll position within its container.
static relative absolute fixed sticky

When Does position Matter?

position is the right tool when normal flow is not enough:

  • Product badges — Place a “Sale” label in the corner with absolute.
  • Site navigation — Keep a header visible with fixed.
  • Section headings — Stick chapter titles with sticky.
  • Minor adjustments — Nudge icons or labels with relative.

For full-page layout grids, also learn Flexbox and Grid. Position solves targeted placement problems inside those layouts.

👀 Live Preview

Static and relative boxes stay in flow. The coral box uses absolute inside the dashed container.

Positioning context

static
relative + offset
absolute

Examples Gallery

Start with the reference overview, then practice relative offsets, absolute badges, and fixed or sticky UI patterns.

🖱 Position Types

Compare all five position values — matching the reference example.

Example 1 — All Position Values

In this example, we’ll demonstrate the different values of the position property.

position-overview.html
<style>
  .static { position: static; }
  .relative { position: relative; top: 20px; }
  .absolute { position: absolute; top: 50px; left: 50px; }
  .fixed { position: fixed; bottom: 0; }
  .sticky { position: sticky; top: 0; }
</style>
Try It Yourself

How It Works

Each class changes how the browser calculates placement. Only static ignores offset properties.

Example 2 — Relative Offset

Use position: relative with top and left to nudge an element while keeping its original space in the layout.

position-relative.html
<style>
  .shifted {
    position: relative;
    top: 20px;
    left: 30px;
  }
</style>
Try It Yourself

How It Works

The element moves visually, but surrounding content still behaves as if it occupies its original spot.

🔀 Layered UI

Use absolute, fixed, and sticky positioning for real interface patterns.

Example 3 — Absolute Badge on a Card

Set the card to position: relative and the badge to position: absolute so the label stays in the top-right corner.

position-absolute.html
<style>
  .card { position: relative; }
  .badge {
    position: absolute;
    top: 12px;
    right: 12px;
  }
</style>
Try It Yourself

How It Works

The relative parent becomes the positioning context. The absolute child is placed using offsets from that box, not the whole page.

Example 4 — Fixed Navbar and Sticky Headings

Combine position: fixed for a persistent navbar with position: sticky for section titles that stick while scrolling.

position-fixed-sticky.html
<style>
  nav { position: fixed; top: 0; }
  .section-title {
    position: sticky;
    top: 52px;
  }
</style>
Try It Yourself

How It Works

fixed anchors to the viewport. sticky behaves like relative until scroll passes a threshold, then sticks like fixed within its scroll container.

position and offset properties

Positioned elements use top, right, bottom, and left to set placement. z-index controls stacking when elements overlap.

pointer-events is often combined with absolutely positioned overlays so decorative layers do not block clicks.

positioned-overlay.css
.card {
  position: relative;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

🧠 How position Works

1

Choose a positioning method

Set static, relative, absolute, fixed, or sticky.

position
2

Apply offsets if needed

Use top, right, bottom, or left to place the element.

Offsets
3

Find the containing block

Absolute children anchor to the nearest positioned ancestor or the viewport.

Context
=

Precise placement

Badges, navbars, overlays, and sticky headings land exactly where you need them.

Browser Compatibility

The position property is widely supported in all modern browsers. The sticky value has slightly less support in very old browsers but is available in all current versions. Always test your website across different browsers to ensure compatibility.

Layout · Universal support

Reliable position support

Chrome, Firefox, Safari, Edge, and Opera support static, relative, absolute, and fixed. sticky works in all modern browsers.

97% Modern browser support
Google Chrome 1+ · sticky 56+
Full support
Mozilla Firefox 1+ · sticky 32+
Full support
Apple Safari 1+ · sticky 7+
Full support
Microsoft Edge 12+ · sticky 16+
Full support
Opera 4+ · sticky 42+
Full support

Testing tip

Test sticky inside overflow containers. A parent with overflow: hidden can prevent sticky from working as expected.

position property 97% supported

Bottom line: All five position values are safe to use in modern projects.

Conclusion

The position property in CSS is a fundamental tool for controlling the layout of web pages. By understanding and utilizing its different values, you can create sophisticated and responsive designs.

Whether you’re aligning elements, creating fixed navigation bars, or developing complex layouts, the position property is essential for effective web design.

💡 Best Practices

✅ Do

  • Set position: relative on parents that contain absolute children
  • Use fixed sparingly for navbars and floating controls
  • Give sticky elements a clear top threshold
  • Combine with z-index when layers overlap
  • Prefer Flexbox or Grid for main page structure

❌ Don’t

  • Position every element when normal flow would work
  • Forget that absolute elements are removed from document flow
  • Assume sticky works inside every overflow container
  • Overlap fixed UI with important content on small screens
  • Use absolute positioning as a substitute for responsive layout systems

Key Takeaways

Knowledge Unlocked

Five things to remember about position

Use these points when placing elements on the page.

5
Core concepts
02

relative

Offset + context.

Pattern
03

absolute

Badges/overlays.

Use case
04

fixed

Viewport UI.

Context
📌 05

sticky

Scroll stick.

Pattern

❓ Frequently Asked Questions

position sets how an element is placed in the document. static follows normal flow, relative offsets from its normal spot, absolute is placed relative to a positioned ancestor, fixed stays relative to the viewport, and sticky switches between relative and fixed while scrolling.
The default value is static. Elements in normal flow are not offset by top, right, bottom, or left.
relative keeps the element in document flow and moves it from its original position. absolute removes the element from flow and positions it using offsets against its nearest positioned ancestor.
An absolutely positioned element uses the nearest ancestor with position other than static as its containing block. Setting position: relative on a parent keeps the child anchored inside that box.
Use sticky for section headings, table headers, or toolbars that should stick within a scroll area after the user scrolls past them. You must set a threshold such as top: 0.

Practice in the Live Editor

Open the HTML editor and build a card with an absolutely positioned badge or a sticky heading.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful