CSS position

The position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky).

Note: The sticky value is not supported in Internet Explorer or Edge 15 and earlier versions.

Syntax for setting position

position: static| absolute| fixed| relative| sticky| initial| inherit;

Position Property Values:

Sr. NO Value Description
1 static Default value. Elements render in order, as they appear in the document flow
2 absolute The element is positioned relative to its first positioned (not static) ancestor element
3 fixed The element is positioned relative to the browser window
4 relative The element is positioned relative to its normal position, so “left:20px” adds 20 pixels to the element’s LEFT position
5 sticky The element is positioned based on the user’s scroll position
A sticky element toggles between relative and fixed, depending on the scroll position. It is positioned relative until a given offset position is met in the viewport – then it “sticks” in place (like position:fixed).
Note: Not supported in IE/Edge 15 or earlier. Supported in Safari from version 6.1 with a -webkit- prefix.
6 initial Sets this property to its default value
7 inherit Inherits this property from its parent element.

Given Below is an Example

See the Pen CSS-Position by Ankit (@AnkitPathshalaCoding) on CodePen.

Exercise 12.1

Position the creature
This webpage contains an image of a planet, an image of a creature, and a div with a greeting. Your job is to make it look like the creature is sitting on the planet and saying the greeting.
In this first step, use absolute positioning to put the creature on top of the planet somewhere.