Top / Right / Bottom / Left

Utilities for controlling the placement of positioned elements.

Class reference

Class Properties
.inset-0 top: 0; right: 0; bottom: 0; left: 0;
.inset-y-0 top: 0; bottom: 0;
.inset-x-0 right: 0; left: 0;
.top-0 top: 0;
.right-0 right: 0;
.bottom-0 bottom: 0;
.left-0 left: 0;
.inset-auto top: auto; right: auto; bottom: auto; left: auto;
.inset-y-auto top: auto; bottom: auto;
.inset-x-auto left: auto; right: auto;
.top-auto top: auto;
.bottom-auto bottom: auto;
.left-auto left: auto;
.right-auto right: 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 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.

Responsive element
Responsive element
Responsive element
Responsive element
Responsive element

Customizing

Positions

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%',
}
}
}

Responsive and State 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,
}
}