Static and relative positioning
Definition and purpose
Static positioning follows normal flow. Relative positioning offsets a box while retaining its original allocation of space.
Static offsets ignored
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a { height: 30px; position: static; top: 20px; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>A stays at zero; B starts at 30px.
Syntax and mental model
position: relative; top: 12px; left: 8px; moves a box down and right. Insets do not move static boxes. A relative ancestor can establish an absolute positioning reference.
Relative offsets retain space
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a { height: 30px; position: relative; top: 20px; left: 10px; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>A moves but B still starts at 30px.
Common mistakes
Offsets do not push later siblings away; use margins for real spacing. Overlapping text can become unreadable.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Display contents and hidden boxes. Next lesson: Absolute positioning and containing blocks.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Static and relative positioning — knowledge check
Five questions on static and relative positioning.
What is the initial position value?
What happens to flow space when a relative box moves?
Does top move a static box?
What does positive left do for a relative box?
Which creates real spacing between flow siblings?