Tailwind CSS v1.0 is here! Learn more →

Position

Utilities for controlling how an element is positioned in the DOM.

Class reference

Class Properties
.static position: static;
.fixed position: fixed;
.absolute position: absolute;
.relative position: relative;
.sticky position: sticky;
.pin-t top: 0;
.pin-r right: 0;
.pin-b bottom: 0;
.pin-l left: 0;
.pin-y top: 0; bottom: 0;
.pin-x right: 0; left: 0;
.pin top: 0; right: 0; bottom: 0; left: 0;
.pin-none top: auto; right: auto; bottom: auto; left: auto;

Static Default

Use .static to position an element according to the normal flow of the document.

Any offsets will be ignored and the element will not act as a position reference for absolutely positioned children.

Static parent

Absolute child

<div class="static bg-grey-dark">
  Static parent
  <div class="absolute pin-b pin-l bg-grey-darkest">
    Absolute child
  </div>
</div>

Relative

Use .relative to position an element according to the normal flow of the document.

Offsets are calculated relative to the element's normal position and the element will act as a position reference for absolutely positioned children.

Relative parent

Absolute child

<div class="relative bg-grey-dark">
  Relative parent
  <div class="absolute pin-b pin-l bg-grey-darkest">
    Absolute child
  </div>
</div>

Absolute

Use .absolute to position an element outside of the normal flow of the document, causing neighboring elements to act as if the element doesn't exist.

Offsets are calculated relative to the nearest parent that has a position other than static, and the element will act as a position reference for other absolutely positioned children.

With static positioning

Relative parent

Static parent

Static child

Static sibling

With absolute positioning

Relative parent

Static parent

Absolute child

Static sibling

<div class="relative bg-grey-light">
  Relative parent
  <div class="static bg-grey-dark">
    Static parent
    <div class="absolute pin-t pin-r bg-grey-darkest">
      Absolute child
    </div>
    <div class="bg-grey-light inline-block">
      Static sibling
    </div>
  </div>
</div>

Fixed

Use .fixed to position an element relative to the browser window.

Offsets are calculated relative to the viewport and the element will act as a position reference for absolutely positioned children.

Fixed child
Absolute child

Scroll me!

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero.

Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.

Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna.

Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi.

Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque.

Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.

Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet.

Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam.

<div class="bg-grey-light pt-16">
  <div class="fixed bg-grey-dark">
    Fixed child
    <div class="absolute pin-t pin-r bg-grey-darkest">
      Absolute child
    </div>
  </div>

  Scroll me!

  Lorem ipsum...
</div>

Sticky

Note that sticky positioning is not supported in IE11.

Use .sticky to position an element as relative until it crosses a specified threshold, then treat it as fixed until its parent is off screen.

Offsets are calculated relative to the element's normal position and the element will act as a position reference for absolutely positioned children.

<div>
    <div class="sticky pin-t ...">Sticky Heading 1</div>
    <p class="py-4">Quisque cursus...</p>
</div>
<div>
    <div class="sticky pin-t ...">Sticky Heading 2</div>
    <p class="py-4">Integer lacinia...</p>
</div>
<div>
    <div class="sticky pin-t ...">Sticky Heading 3</div>
    <p class="py-4">Nullam mauris...</p>
</div>
<!-- etc. -->

Pinning edges

Use the .pin{-edge?} utilities to anchor absolutely positioned elements against any of the edges of the nearest positioned parent.

Combined with Tailwind's spacing utilities, you'll probably find that these are all you need to precisely control absolutely positioned elements.

Class
pin
Edge (optional)
  All (default)
t Top
r Right
b Bottom
l Left
y Top and Bottom
x Left and Right

.pin-x.pin-t

.pin-y.pin-r

.pin-x.pin-b

.pin-y.pin-l

.pin

.pin-l.pin-t

.pin-t.pin-r

.pin-r.pin-b

.pin-b.pin-l

<!-- Span top edge -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-x pin-t h-8 bg-grey-darker"></div>
</div>

<!-- Span right edge -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-y pin-r w-8 bg-grey-darker"></div>
</div>

<!-- Span bottom edge -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-x pin-b h-8 bg-grey-darker"></div>
</div>

<!-- Span left edge -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-y pin-l bg-grey-darker"></div>
</div>

<!-- Fill entire parent -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin bg-grey-darker"></div>
</div>

<!-- Pin to top left corner -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-l pin-t h-8 w-8 bg-grey-darker"></div>
</div>

<!-- Pin to top right corner -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-t pin-r h-8 w-8 bg-grey-darker"></div>
</div>

<!-- Pin to bottom right corner -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-b pin-r h-8 w-8 bg-grey-darker"></div>
</div>

<!-- Pin to bottom left corner -->
<div class="relative h-24 w-24 bg-grey-light">
  <div class="absolute pin-b pin-l h-8 w-8 bg-grey-darker"></div>
</div>

Responsive

To position an element only at a specific breakpoint, add a {screen}: prefix to any existing positioning utility. For example, adding the class md:absolute to an element would apply the absolute utility at medium screen sizes and above, and adding lg:pin-y would apply pin-y at large screens and above.

For more information about Tailwind's responsive design features, check out the Responsive Design documentation.

Responsive element
Responsive element
Responsive element
Responsive element
Responsive element

Customizing

Responsive and State Variants

By default, only responsive variants are generated for positioning utilities.

You can control which variants are generated for the positioning utilities by modifying the position property in the modules section of your Tailwind config file.

For example, this config will also generate hover and focus variants:

{
// ...
modules: {
    // ...
-   position: ['responsive'],
+   position: ['responsive', 'hover', 'focus', 'active', 'group-hover'],
}
}

Disabling

If you don't plan to use the positioning utilities in your project, you can disable them entirely by setting the position property to false in the modules section of your config file:

{
// ...
modules: {
    // ...
-   position: ['responsive'],
+   position: false,
}
}