The CSS position property is used to set the position for an element. it is also used to place an element behind another and also useful for the scripted animation effect.
You can position an element by using the top, bottom, left and right properties. These properties can be used only after position property is set first otherwise they have not worked.
The CSS position property values are relative, absolute, fixed, static and sticky.
CSS Static Position
This method of positioning is set by default. If we don’t mention the method of positioning for any element, the element has the position: static method by default.
By defining Static, the top, right, bottom and left will not have any control over the element. The element will be positioned with the normal flow of the page.
CSS Relative Position
An element with position: relative is positioned relatively with the other elements which are sitting at top of it.
You can use any values top, left, bottom, or right with the position property to move an HTML element anywhere in the HTML document.
CSS Fixed Position
The fixed positioning property used to put the text fixed on the browser. An element with fixed positioning allows it to remain in the same position even we scroll the page.
We can set the position of the element using the top, right, bottom, left.
CSS Absolute Position
An element with position: absolute will be positioned with respect to its parent that has a position other than static.
With the absolute positioning, you can place an element anywhere on a page.
CSS Sticky Position
The sticky value is like a compromise between relative and fixed values. If the element is placed in the middle of the document then when the user scrolls the document, the sticky element starts scrolling until it touches the top. When it touches the top, it will be fixed at that place in spite of further scrolling. We can stick the element at the bottom, with the bottom property.
CSS z-index Property
If you want to set the element should be placed in front of, or behind, the others then it possible by using the z-index property. Set z-index value is negative (for eg. -1) to placed behind the other element and set positive (for eg. 1) to placed in front of element.