HOME   BLOG   PORTFOLIO  

HTML CSS

What are the differences between relative, absolute, and fixed positioning?

Relative positioning

Example for relative, this text is moved 50px from it's original position.

        CSS
        
          #example-relative {
            position: relative;
            right: 50px;
          }
      

Absolute positioning

Example for absolute!

        CSS
        
          #example-absolute {
            position: absolute;
            left: 0;
          }
      

Fixed positioning

Example for fixed!

        CSS
        
          #example-fixed {
            position: fixed;
            bottom: 0;
            right: 0;
          }
      

References
css-tricks.com | Absolute, Relative, Fixed Positioning: How Do They Differ?
css-tricks.com | position
levelup.gitconnected.com | CSS position property: relative, absolute, static, fixed, sticky
developer.mozilla.org | position - CSS: Cascading Style Sheets