Top / Right / Bottom / Left

Utilities for controlling the placement of positioned elements.

Class reference

Class
Properties
.inset-0top: 0; right: 0; bottom: 0; left: 0;
.inset-autotop: auto; right: auto; bottom: auto; left: auto;
.inset-y-0top: 0; bottom: 0;
.inset-x-0right: 0; left: 0;
.inset-y-autotop: auto; bottom: auto;
.inset-x-autoright: auto; left: auto;
.top-0top: 0;
.right-0right: 0;
.bottom-0bottom: 0;
.left-0left: 0;
.top-autotop: auto;
.right-autoright: auto;
.bottom-autobottom: auto;
.left-autoleft: auto;

Usage

Use the .{top|right|bottom|left|inset}-0 utilities to anchor absolutely positioned elements against any of the edges of the nearest positioned parent.

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

.inset-x-0.top-0

.inset-y-0.right-0

.inset-x-0.bottom-0

.inset-y-0.left-0

.inset-0

.left-0.top-0

.top-0.right-0

.right-0.bottom-0

.bottom-0.left-0

<!-- Span top edge -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute inset-x-0 top-0 h-8 bg-gray-700"></div>
</div>

<!-- Span right edge -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute inset-y-0 right-0 w-8 bg-gray-700"></div>
</div>

<!-- Span bottom edge -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute inset-x-0 bottom-0 h-8 bg-gray-700"></div>
</div>

<!-- Span left edge -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute inset-y-0 left-0 w-8 bg-gray-700"></div>
</div>

<!-- Fill entire parent -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute inset-0 bg-gray-700"></div>
</div>

<!-- Pin to top left corner -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute left-0 top-0 h-8 w-8 bg-gray-700"></div>
</div>

<!-- Pin to top right corner -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute top-0 right-0 h-8 w-8 bg-gray-700"></div>
</div>

<!-- Pin to bottom right corner -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute bottom-0 right-0 h-8 w-8 bg-gray-700"></div>
</div>

<!-- Pin to bottom left corner -->
<div class="relative h-24 w-24 bg-gray-400">
  <div class="absolute bottom-0 left-0 h-8 w-8 bg-gray-700"></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:inset-y-0 to an element would apply the inset-y-0 utility at medium screen sizes and above.

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

<div class="relative h-32 bg-gray-400 p-4">
  <div class="absolute inset-0 sm:bottom-0 sm:left-0 md:top-0 md:inset-x-0 lg:right-0 lg:inset-y-0 xl:bottom-0 xl:inset-x-0"></div>
</div>
Responsive element

Customizing

Top / Right / Bottom / Left scale

By default Tailwind only provides 0 and auto top/right/bottom/left/inset utilities. You can change, add, or remove these by editing the theme.inset section of your tailwind.config.js file.

  // tailwind.config.js
  module.exports = {
    theme: {
      inset: {
        '0': 0,
-       auto: 'auto',
+       '1/2': '50%',
      }
    }
  }

Negative values

If you'd like to add any negative top/right/bottom/left classes that take the same form as Tailwind's negative margin classes, prefix the keys in your config file with a dash:

  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
        inset: {
+         '-16': '-4rem',
        }
      }
    }
  }

Tailwind is smart enough to generate classes like -top-16 when it sees the leading dash, not top--16 like you might expect.

Responsive and pseudo-class variants

By default, only responsive variants are generated for top, right, bottom, left, and inset utilities.

You can control which variants are generated for the top, right, bottom, left, and inset utilities by modifying the inset property in the variants section of your tailwind.config.js file.

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

  // tailwind.config.js
  module.exports = {
    variants: {
      // ...
-     inset: ['responsive'],
+     inset: ['responsive', 'hover', 'focus'],
    }
  }

Disabling

If you don't plan to use the top, right, bottom, left, and inset utilities in your project, you can disable them entirely by setting the inset property to false in the corePlugins section of your config file:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     inset: false,
    }
  }

Tailwind UI is now in early access!