CSS Position

The position property in CSS specifies how an element is positioned in the document. It controls whether an element is placed relative to its normal flow, its parent, or the viewport.

Position Values

Common position property values include:

Static Position

Static is the default positioning; elements appear in normal flow.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
  position: static;
}
</style>
</head>
<body>

<div>This is my first CSS page.</div>

</body>
</html>
Try this code

Relative Position

Relative positioning moves an element relative to its normal position.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
  position: relative;
  top: 10px;
  left: 20px;
}
</style>
</head>
<body>

<div>This is my first CSS page.</div>

</body>
</html>
Try this code

Absolute Position

Absolute positioning removes the element from normal flow and positions it relative to the nearest positioned ancestor.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div {
  position: absolute;
  top: 50px;
  right: 20px;
}
</style>
</head>
<body>

<div>This is my first CSS page.</div>

</body>
</html>
Try this code

Fixed Position

Fixed elements are positioned relative to the viewport and remain in place when scrolling.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div{
  position: fixed;
  top: 0;
  width: 100%;
}
</style>
</head>
<body>

<div>This is my first CSS page.</div>

</body>
</html>
Try this code

Sticky Position

Sticky elements behave like relative until a certain scroll position is reached, then they become fixed.

Example
<!DOCTYPE html>
<html>
<head>
<style>
div{
  position: sticky;
  top: 0;
}
</style>
</head>
<body>

<div>This is my first CSS page.</div>

</body>
</html>
Try this code

Best Practices for Position

Common Mistakes with Position

Tip: Combining position with z-index can control element stacking order for better layout control.