Back to CSS Notes
Topic #69

Fixed/Absolute Position

Fixed and absolute positioning take elements out of the flow entirely. Fixed pins to the viewport; absolute pins to an ancestor.


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 Coding Now Tech Institute'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 Coding Now Tech Institute 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 Coding Now Tech Institute, 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 Coding Now Tech Institute'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 Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now