🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #69

Fixed/Absolute Position


CSS position: fixed

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used set the final location of the element.

A fixed element does not leave a gap in the page where it would normally have been located.

Notice the fixed element in the lower-right corner of the page. Here is the CSS that is used:

Example

div.fixed {
  position: fixed;

bottom: 0;
  right: 0;
  width:
300px;
  border: 3px solid #73AD21;
}

CSS position: absolute

An element with position: absolute; is positioned relative to the nearest positioned ancestor (with position other than static).

However; if an absolute positioned element has no positioned ancestors, it uses the document body, and moves along with page scrolling.

Note: Absolute positioned elements are removed from the normal document flow, and can overlap other elements.

Here is a simple example:

Here is the CSS that is used:

Example

div.relative {
  position: relative;

width: 400px;
  height: 200px;
  border: 3px solid green;
}

div.absolute {
  position: absolute;

top: 80px;
  right: 0;
  width: 200px;
  height: 100px;
  border: 3px solid
  red;
}

Positioning Text On an Image

How to position text on an image:

Example

<div style="position:relative;text-align:center;">
<img alt="Cinque Terre" src="img_5terre_wide.jpg" style="width:100%;height:auto;opacity:0.5"/>
<div style="position:absolute;bottom:8px;left:16px;font-size:20px">Bottom Left</div>
<div style="position:absolute;top:8px;left:16px;font-size:20px">Top Left</div>
<div style="position:absolute;top:8px;right:16px;font-size:20px">Top Right</div>
<div style="position:absolute;bottom:8px;right:16px;font-size:20px">Bottom Right</div>
<div style="position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);font-size:20px">Centered</div>
</div>

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Fixed/Absolute Position – FAQs

Quick answers about learning Fixed/Absolute Position in CSS.

This free note from CodingNow 2.0 explains Fixed/Absolute Position in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Fixed/Absolute Position, is 100% free with no signup required.
With focused practice, most students grasp Fixed/Absolute Position in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now