CSS Position Property Explained!
Tags: css, webdev, javascript, beginners
Published: 2021-03-27 08:55:37

# Introduction

We struggle a lot while positioning elements at the right place on the webpage. Sometimes we also find that **top/left/bottom/right** has no effect on the element. The position property of CSS controls the positioning of elements on the webpage and its behavior. It also influences other elements of the webpage.

![gif-4mb](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l8sgwqjj1zp7duqpi6u9.gif)
 

Today, we are going to look into the position property and its different values in CSS. 


# Position Property

> The position property specifies the type of positioning method used for an element.
 -[W3Schools](https://www.w3schools.com/)

It defines the position of an element in the document.

There are 5 major key value of position property

- **Static**
- **Absolute**
- **Relative**
- **Fixed**
- **Sticky**

<hr/>

## Static

It is the default value of position property. The element is rendered in order of placement. It doesn't break the flow of the document. **top/left/bottom/right** attribute don't work with static position property.

![02-Static-position-FROONT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2dfk5kipsd8emqos2ts.gif)
 

**Why to use: It will scale on all browser**

<hr/>

## Absolute

The element is removed from the normal flow of the document. Other elements will behave as it's not even there in the document. All the position property will work. Absolute positioned elements are relative to their parent element.

![03-Absolute-position-FROONT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9idoejoee7e3rhsvfnws.gif)
 

**Why to use: Use when to position element according to parent element**

<hr/>

## Relative

The element is positioned relative to its normal position. It acts as a static element. Now, **top/left/bottom/right** attribute will work on the element. It is mostly used for the parent elements.

![04-Relative-position-FROONT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6mnkp9rj7u55lx6do890.gif)
 

**Why to use: Use for parent element of an absolute positioned element**

<hr/>

## Fixed

The fixed position element is the same as the absolute position. They are removed from the normal flow of the document. But unlike absolute position elements, they are always relative to the HTML tag.

![05-fixed-position-FROONT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/acpsez0pagwlfs1ubwtn.gif)
 

**Why to use: Use when you want the header to be fixed on the top of the viewport.**

<hr/>

## Sticky

The sticky position is unique. It behaves according to scroll. If you scroll past the element, it will stick to the position. After that, it will work as a fixed element.

![CssPositionSticky](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jo882nlrtykgmc7smxce.gif)
 

Click [here](https://www.w3schools.com/cssref/tryit.asp?filename=trycss_position_sticky) for live action of sticky position property.

**Why to use: When you want something to stick after a certain click like *Buy Now*, *Login*.**

<hr/>

# Last Note

I hope now you will able to position the element according to your need without much frustration. Thank you are reading the blog post.

GIF Credit : [FROONT BLOG](https://blog.froont.com/)

### 🔗 Connect with me:

[**Twitter**](https://twitter.com/surajondev) [**GitHub**](https://github.com/surajondev)