difference between position: relative; and position: absolute; in CSS?
68
28-Oct-2024
Updated on 28-Oct-2024
Ashutosh Kumar Verma
28-Oct-2024position: relative;
positions an element relative to its normal position in the document flow. It does not affect the layout of surrounding elements, but it can be moved using the top, right, bottom, or left properties. However, the element still occupies its original position in the flow.position: absolute;
removes the element from the normal document flow and positions it relative to its closest positioned ancestor (an ancestor element with a position other than static). If no such ancestor exists, it will be positioned relative to the initial containing block (usually the <html> element).Interaction
Example-
Also, Read: How can you center an element horizontally in CSS?