In CSS, the position property specifies how an element is positioned in the document. There are five possible values for this property:
static.<style>
.box {
position: static;
}
</style>
<div class="box">Static Box </div>
top, right, bottom, and left to offset it from that position.<style>
.box {
position: relative;
left:10px;
top:10px;
}
</style>
<div class="box">Relative Box </div>
<style>
.box {
position: fixed;
top: 10px;
right: 10px;
}
</style>
<div class="box">Fixed Box </div>
position other than static).<style>
.box {
position: absolute;
top: 10px;
right: 10px;
}
</style>
<div class="box">Absolute Box </div>
relative until it crosses a defined scroll threshold (e.g., top), after which it becomes fixed<style>
.box {
position: sticky;
top: 10px;
right: 10px;
}
</style>
<div class="box">Sticky Box </div>
Demo:
style.css
body{
font-family: Arial, Helvetica, sans-serif;
}
.static-box {
position: static;
padding: 70px;
}
.relative-box {
position: relative;
top:10px;
background-color: red;
height: 300px;
width: 300px;
padding: 15px;
margin-bottom: 50px;
}
.absolute-box {
position: absolute;
top: 150px;
right: 10px;
background-color: yellow;
padding: 15px;
}
.sticky-box {
position: -webkit-sticky;
position: sticky;
top: 100px;
background-color: #45cf45;
padding: 10px;
width: 100px;
height: 100px;
}
.fixed-box {
position: fixed;
top: 10px;
right: 20px;
padding: 10px;
border: 1px solid red;
}
.row-content{
display: flex;
padding: 20px;
gap: 10px;
}
.leftside{
background-color: #ddd;
width: 75%;
padding: 20px;
height: 1200px;
}
.rightside{
width: 24%;
padding: 20px;
}
position.html
<div class="static-box">Static Box </div>
<div class="row-content">
<div class="leftside">
<div class="relative-box">
Relative Box
<div class="absolute-box">Absolute Box </div>
</div>
</div>
<div class="rightside sticky-box">Sticky</div>
</div>
<div class="fixed-box">Fixed Box </div>
Output:
© 2025Think4u. All Rights Reserved.