Position relative lets you move an element a little bit from where it normally sits. It keeps space for the element in the page layout.
Position relative in CSS
selector {
position: relative;
top: 10px; /* moves down 10px */
left: 5px; /* moves right 5px */
}The position: relative; property keeps the element in the normal page flow.
Using top, left, bottom, and right moves the element from its original spot.
div {
position: relative;
top: 20px;
left: 10px;
}p {
position: relative;
top: -5px;
left: 0;
}button {
position: relative;
right: 15px;
bottom: 10px;
}The blue box moves down and right from its normal place, but space for it remains reserved. The second box stays where it is.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Position Relative Example</title> <style> .box { width: 150px; height: 100px; background-color: lightblue; margin: 20px; position: relative; top: 30px; left: 40px; border: 2px solid navy; padding: 10px; font-family: Arial, sans-serif; } </style> </head> <body> <div class="box">This box is moved down 30px and right 40px.</div> <div>This box stays in normal position.</div> </body> </html>
Relative positioning moves the element visually but keeps its original space in the layout.
If you want the element to not take space where it was, use position: absolute; instead.
Use browser DevTools (right-click element > Inspect) to see how the element moves.
Position relative moves an element from its normal spot without changing page layout.
You can move elements up, down, left, or right using top, left, bottom, and right.
It is useful for small adjustments and layering elements.