VOOZH about

URL: https://www.geeksforgeeks.org/css/css-positioning-elements/

⇱ CSS Positioning Elements - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

CSS Positioning Elements

Last Updated : 19 Jan, 2026

CSS positioning is used to control the placement of elements on a web page. It allows elements to be positioned relative to the normal document flow, the browser window, or other elements.

  • The position property defines how an element is positioned.
  • Common position values include static, relative, absolute, fixed, and sticky.
  • Positioning works with properties like top, right, bottom, and left.
  • It helps create flexible layouts, overlays, and responsive designs.

Given below the different types of Positioning:

1. Static Positioning

Static is the default position of an element. It does not accept properties like top, left, right, or bottom.

  • The boxes follow the normal flow of the document.
  • There’s no overlap or displacement of elements.1

2. Relative Positioning

Relative positioning places an element relative to its normal position. You can move it using top, left, right, or bottom.

Box 2 is shifted 20px down and 30px to the right from its normal position.

3. Absolute Positioning

Absolute positioning removes the element from the document flow and places it relative to the nearest ancestor with a positioning context (relative, absolute, or fixed).

  • The pink box (.absolute) is positioned 50px down and 50px right within the .container.
  • It does not affect other elements in the flow.

4. Fixed Positioning

Fixed positioning removes the element from the flow and positions it relative to the viewport. It remains in place even when the page scrolls.

The fixed element stays at the top-right corner of the viewport even as the user scrolls.

5. Sticky Positioning

Sticky positioning switches between relative and fixed based on the scroll position.

The sticky element stays at the top of the viewport as you scroll but only within its containing element.

Comment
Article Tags: