Monday, 4 Aug 2025
  • My Interests
  • My Saves
  • Try Intents
Subscribe
Focus - Code Reveals
  • Home
  • HTML
    What is Symentic HTML

    What is Symentic HTML?

    By Chief Editor

    What are the async and defer attributes in the “script” tag?

    By Chief Editor

    What is a Meta Tag in HTML?

    By Chief Editor

    What is Block level Element and Inline Level Element?

    By Chief Editor

    What is Doctype HTML in HTML?

    By Chief Editor

    What are the different types of HTML tags?

    By Chief Editor
  • JavaScript

    What are the Rest and Spread operators in JavaScript?

    By Chief Editor

    What is the Event Loop in JavaScript?

    By Chief Editor

    Explain Call, Apply and Bind in JavaScript.

    By Chief Editor

    What is Callback Hell in JavaScript?

    By Chief Editor

    Is JavaScript a synchronous or asynchronous language?

    By Chief Editor

    How to Reverse a String in JavaScript: Two Essential Methods

    By Chief Editor
  • Frontend Interview

    How to Reverse a String in JavaScript: Two Essential Methods

    By Chief Editor

    Explain Deep Copy and Shallow Copy in JavaScript.

    By Chief Editor

    Difference Between position: relative and position: absolute in CSS

    By Chief Editor

    Is JavaScript a synchronous or asynchronous language?

    By Chief Editor

    What is Position in CSS?

    By Chief Editor

    What is Block level Element and Inline Level Element?

    By Chief Editor
  • Backend Interview

    Difference between HTML Tag and HTML Element in HTML?

    By Chief Editor

    How Does React Work?

    By Chief Editor

    How to Improve the Performance of React Applications

    By Chief Editor

    What is Virtual DOM in React?

    By Chief Editor

    Lazy Loading in React.js: Boosting Performance and Reducing Load Time

    By Chief Editor

    What is a Promise in JavaScript, and what are its parameters?

    By Chief Editor
  • Nodejs
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate
  • πŸ”₯
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • React Interview
  • HTML
  • Frontend Interview
  • CSS
  • Redux
  • Javascript
  • System Design
Font ResizerAa
Focus - Code RevealsFocus - Code Reveals
  • My Saves
  • My Interests
  • My Feed
  • History
  • Technology
Search
  • Homepage
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • HTML
  • CSS
  • Backend Interview
Have an existing account? Sign In
Follow US
Β© 2022 Code Reveals Inc. All Rights Reserved.
Home Blog Difference Between position: relative and position: absolute in CSS
CSSFrontend Interview

Difference Between position: relative and position: absolute in CSS

Chief Editor
Last updated: February 16, 2025 6:40 pm
Chief Editor
Share
SHARE
Propertyposition: relativeposition: absolute
DefinitionThe element is positioned relative to its original position in the normal document flow.The element is positioned relative to its nearest positioned ancestor (or the <html> if no ancestor has position: relative, absolute, or fixed).
Affects Document Flow?βœ… Yes, it remains in the document flow and occupies space.❌ No, it is removed from the document flow, meaning other elements behave as if it does not exist.
Reference PointThe original position of the element.The nearest ancestor with position: relative, absolute, or fixed. If none, it is positioned relative to the <html> (viewport).
Usage of top, right, bottom, leftMoves the element from its normal position without affecting surrounding elements.Moves the element relative to the nearest positioned ancestor, completely detached from the normal document flow.
Exampleβœ… Used when you want to shift an element slightly from its normal position while keeping the surrounding layout intact.βœ… Used when you need to place an element precisely, often for overlays, tooltips, dropdowns, etc.

Example of position: relative

cssCopyEdit.container {
  position: relative;
  width: 300px;
  height: 200px;
  background: lightblue;
}

.child {
  position: relative;
  top: 20px;
  left: 30px;
  background: yellow;
}

πŸ“Œ Result:

  • The .child element moves 20px down and 30px right from its normal position inside .container.
  • Other elements are not affected.

Example of position: absolute

cssCopyEdit.container {
  position: relative; /* Acts as the reference for absolute positioning */
  width: 300px;
  height: 200px;
  background: lightblue;
}

.child {
  position: absolute;
  top: 20px;
  left: 30px;
  background: yellow;
}

πŸ“Œ Result:

  • The .child element is positioned 20px down and 30px right, but relative to .container (not its normal position).
  • If .container did not have position: relative, the .child would be positioned relative to the entire page (viewport).

Key Takeaways

  • relative keeps the element in flow, moving it slightly from its original position.
  • absolute removes the element from flow and positions it relative to the closest positioned ancestor.

Share This Article
Email Copy Link Print
Previous Article What is Symentic HTML What is Symentic HTML?
Next Article What is Block level Element and Inline Level Element?
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Trusted Source for Accurate and Timely Updates!

Our commitment to accuracy, impartiality, and delivering breaking news as it happens has earned us the trust of a vast audience. Stay ahead with real-time updates on the latest events, trends.
FacebookLike
XFollow
InstagramFollow
YoutubeSubscribe
LinkedInFollow
QuoraFollow
- Advertisement -
Ad imageAd image

Popular Posts

What is Callback Hell in JavaScript?

Callback Hell in JavaScript refers to a situation where you have multiple nested callbacks, making…

By Chief Editor

What is Symentic HTML?

Semantic HTML refers to using HTML tags that convey the meaning or purpose of the…

By Chief Editor

How to Improve the Performance of React Applications

React is a powerful library for building interactive user interfaces, but performance issues can arise…

By Chief Editor

You Might Also Like

What are the Lexical Scope in JavaScript
Frontend InterviewJavaScript

What are the Lexical Scope in JavaScript?

By Chief Editor
CSSFrontend Interview

What is Position in CSS?

By Chief Editor
Frontend InterviewHTML

What is Block level Element and Inline Level Element?

By Chief Editor
Frontend InterviewJavaScript

How to Reverse a String in JavaScript: Two Essential Methods

By Chief Editor

Focus by CodeReveals is your dedicated platform for mastering tech interviews and advancing your development skills. Whether you’re aiming to become a Frontend Developer, Backend Developer, or simply preparing for your next big interview, we’re here to guide you every step of the way.

Our mission is to help aspiring developers gain real-world knowledge, build confidence, and succeed in technical interviews. We offer structured content, curated interview questions, coding challenges, and practical guidance β€” all designed by experienced professionals who understand what top tech companies are looking for.

At Improve, we don’t just teach β€” we prepare you to think like a developer, solve like an engineer, and present like a pro.

Join us and start improving today β€” because your dream tech job is within reach

Most Famous
  • HTML
  • CSS
  • JavaScript
  • NodeJS
Top Categories
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
Usefull Links
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate

Β©2025Β  Code Reveals Inc. All Rights Reserved.

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?