03. Positioning an Element

There are three ways to position an element: absolute, relative and fixed.


An element with absolute positioning is completely removed from the document flow. Thus, no other documents push it around, and you can move elements to exact locations on the screen.

To note the exact position of the element with a property of absolute, we set properties top, left, right or bottomto specify the position.

div.abs {
  position: absolute; 
  top: 10px;
  left: 10px;

The above code will take a div with class "abs" out of the flow and place it where it is exactly 10 pixels from the top and 10 pixels from the left.


You may place an object relative to where it's supposed to be. Again, you can use the top, left, right and bottom properties to specify its position.

div.rel {
  position: relative; 
  top: 10px;
  left: 10px;

The above code will place it 10 pixels down and 10 pixels to the right of where it's supposed to be.

Fixed Positioning

This will position an element relative to the viewport window. An example of this would be a navigation bar that stays up on the top of your screen. Even with the user scrolling down the page, a fixed element will keep its position.

div.fix {
  position: fixed;  

The element with class fix will stay in one position, no matter how the user scrolls.

Using z-index to specify element order

If boxes overlap, you may use the z-index property to control which element appears on the top. The higher z-index valued components will appear at the top.

Build modern and responsive webpages

Responsive Typography

Build modern and responsive webpages Try Front-end

Responsive web design helps your site maintain its design integrity on a variety of screen sizes, but how does it affect your typography? With this practical book, graphic designers, web designers, and front-end developers alike will learn the nuts and bolts of how to get the best appearance from type without sacrificing performance on any device.

$ Check price
24.9924.99Amazon 4.5 logo(3+ reviews)

More Front-end resources

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources