Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Position

CSS Position

CSS CODES & EXAMPLES

CSS Position

Learn how CSS positioning controls the exact placement of HTML elements. Understand static, relative, absolute, fixed and sticky positioning with practical website examples.

01

Introduction to CSS Position

Control the placement of elements

The CSS position property determines how an element is positioned in a document. It works together with properties such as top, right, bottom and left.

Common values:static relative absolute fixed sticky
02

position: static

The default positioning

Every HTML element is positioned as static by default. Static elements follow the normal document flow and are not affected by top, right, bottom or left.

Element 1
Static Element
Element 3
position-static.css
.box {
  position: static;
}
03

position: relative

Move an element relative to its normal position

A relatively positioned element remains in the normal document flow, but it can be moved using top, right, bottom and left.

Normal Element
Relative Element
Next Element
position-relative.css
.box {
  position: relative;
  top: 15px;
  left: 20px;
}
04

position: absolute

Position an element relative to its positioned ancestor

An absolutely positioned element is removed from the normal document flow. It is positioned relative to its nearest positioned ancestor.

NEW

Course Card

The badge is positioned using absolute positioning.

position-absolute.css
.parent {
  position: relative;
}

.badge {
  position: absolute;
  top: 15px;
  right: 15px;
}
06

position: sticky

Combine normal and fixed-like positioning

A sticky element behaves like a relatively positioned element until a specified scroll position is reached. It then sticks to that position within its scrolling container.

Sticky Navigation

Scroll this area to understand the sticky effect.

CSS positioning is important for headers, menus, cards, badges and floating controls.

Sticky positioning is frequently used for website navigation.

Keep scrolling to see the element remain visible.

position-sticky.css
.menu {
  position: sticky;
  top: 0;
}
07

top, right, bottom & left

Control the exact position

The offset properties determine how far a positioned element is moved from its reference edge.

Offset
offset.css
.box {
  position: absolute;

  top: 20px;
  right: 20px;

  bottom: auto;
  left: auto;
}
08

Relative + Absolute Positioning

The most common positioning combination

A parent with position: relative creates a positioning context for a child with position: absolute.

Course Image 30% OFF

Web Designing

Learn HTML, CSS and modern web design.

relative-absolute.css
.card {
  position: relative;
}

.badge {
  position: absolute;
  top: 12px;
  right: 12px;
}
09

Centering an Element

Center an absolutely positioned element

An absolutely positioned element can be centered using top: 50%, left: 50% and transform.

CENTERED
center-position.css
.parent {
  position: relative;
}

.child {
  position: absolute;

  top: 50%;
  left: 50%;

  transform:
    translate(-50%, -50%);
}
10

Overlay Effects

Place content over images and other elements
FEATURED COURSE

Web Designing

Explore Course
overlay.css
.image {
  position: relative;
}

.overlay {
  position: absolute;

  left: 0;
  right: 0;
  bottom: 0;
}
See also  HTML Lists
11

Fixed Header

Create a header that stays at the top
SNCEC
Home   Courses   Contact

Fixed Header Example

A fixed header remains attached to the viewport while the page content moves underneath it.

fixed-header.css
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}
12

Floating Button

Fixed action button example
+
Floating Action Button

Commonly used for support, chat, WhatsApp or quick actions.

floating-button.css
.floating-button {
  position: fixed;

  right: 25px;
  bottom: 25px;

  width: 55px;
  height: 55px;

  border-radius: 50%;
}
13

Sticky Navigation

Keep navigation visible while scrolling
14

Positioned Cards

Practical course card design
DCA POPULAR

Diploma in Computer Application

Learn computer fundamentals, office applications, internet and practical digital skills.

View Course
ADCA NEW

Advanced Computer Application

Develop advanced computer and professional application skills.

View Course
WEB OFFER

Web Designing

Learn HTML, CSS, responsive layouts and modern web design.

View Course
15

Image Overlay

Text positioned over an image
LEARN • PRACTICE • ACHIEVE

Build Your Digital Skills

Learn practical computer skills with structured lessons.

16

Responsive Positioning

Use media queries with positioned elements
RESPONSIVE

Responsive Positioning

The badge changes its position on smaller screens.

responsive-position.css
.card {
  position: relative;
}

.badge {
  position: absolute;
  top: 15px;
  right: 15px;
}

@media (max-width: 600px) {

  .badge {
    top: 10px;
    right: 10px;
  }

}
See also  CSS Align Items
17

Live CSS Runner

Run a real CSS Position example
LIVE PREVIEW
18

Practice Task

Test your CSS Position knowledge

🎯 Your Challenge

Create a modern course card using CSS positioning.

  • Make the card position: relative.
  • Add a discount badge using position: absolute.
  • Place the badge in the top-right corner.
  • Create a fixed help button at the bottom-right.
  • Create a sticky navigation bar.
  • Create an image overlay using absolute positioning.
  • Make the design responsive with a media query.
19

CSS Position Quick Reference

Important properties at a glance
static Default positioning in normal document flow.
relative Moves an element relative to its normal position.
absolute Positions an element relative to a positioned ancestor.
fixed Positions an element relative to the viewport.
sticky Sticks an element after reaching a specified offset.
top Controls the top offset of a positioned element.
right Controls the right offset.
bottom Controls the bottom offset.
left Controls the left offset.
`;document.getElementById( "positionPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){runPositionDemo();} );

HTML Paragraph

  • 17/08/2026

CSS Float

  • 18/08/2026

Leave a Reply

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