HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Position

CSS Layout

CSS Position

The CSS Position property is used to control how an element is positioned on a webpage.

By default, HTML elements are displayed according to the normal document flow. The position property allows you to move elements relative to their normal position, a parent element, or the browser window. The supporting concepts are explained in Anchor Positioning and CSS Z-index.

CSS Position is commonly used for:

  • Navigation bars
  • Popups and modals
  • Sticky headers
  • Tooltips
  • Custom layouts

Syntax

CSS Position Syntax

css

selector {
    position: value;
}

CSS Position Example

css

.box {
    position: relative;
    left: 20px;
}

This moves the element 20px to the right from its original position.

Attributes

ValueDescriptionExample
staticDefault positioningposition: static;
relativePositioned relative to its normal positionposition: relative;
absolutePositioned relative to nearest positioned ancestorposition: absolute;
fixedPositioned relative to browser viewportposition: fixed;
stickySwitches between relative and fixed based on scrollposition: sticky;

Example

CSS Position Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Position Example</title>
    <style>
        .relative-box {
            position: relative;
            left: 30px;
            background-color: lightblue;
            padding: 10px;
            margin-bottom: 20px;
        }
        .container {
            position: relative;
            height: 200px;
            border: 2px solid black;
        }
        .absolute-box {
            position: absolute;
            top: 20px;
            right: 20px;
            background-color: orange;
            padding: 10px;
        }
        .fixed-box {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: lightgreen;
            padding: 10px;
        }
    </style>
</head>
<body>
    <div class="relative-box">Relative Position</div>
    <div class="container">
        <div class="absolute-box">Absolute Position</div>
    </div>
    <div class="fixed-box">Fixed Position</div>
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
position11211

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • static is the default value for all elements.
  • relative keeps the element in the normal document flow.
  • absolute removes the element from the normal flow.
  • fixed keeps the element visible while scrolling.
  • sticky behaves like relative until a scroll threshold is reached.

Positioning often works together with:

  • top
  • right
  • bottom
  • left

Position Comparison

Position TypeAffects Layout FlowScrolls with Page
staticYesYes
relativeYesYes
absoluteNoYes
fixedNoNo
stickyYesPartially

Conclusion

The CSS Position property gives you precise control over element placement. Whether you need a simple offset, a floating button, a sticky navigation bar, or a complex layout, understanding positioning is essential for modern web development.

PreviousCSS DisplayNextAnchor Positioning