Sizing

Height

Utilities for setting the height of an element.

Quick reference

Class
Properties
h-0height: 0px;
h-pxheight: 1px;
h-0.5height: 0.125rem;
h-1height: 0.25rem;
h-1.5height: 0.375rem;
h-2height: 0.5rem;
h-2.5height: 0.625rem;
h-3height: 0.75rem;
h-3.5height: 0.875rem;
h-4height: 1rem;
h-5height: 1.25rem;
h-6height: 1.5rem;
h-7height: 1.75rem;
h-8height: 2rem;
h-9height: 2.25rem;
h-10height: 2.5rem;
h-11height: 2.75rem;
h-12height: 3rem;
h-14height: 3.5rem;
h-16height: 4rem;
h-20height: 5rem;
h-24height: 6rem;
h-28height: 7rem;
h-32height: 8rem;
h-36height: 9rem;
h-40height: 10rem;
h-44height: 11rem;
h-48height: 12rem;
h-52height: 13rem;
h-56height: 14rem;
h-60height: 15rem;
h-64height: 16rem;
h-72height: 18rem;
h-80height: 20rem;
h-96height: 24rem;
h-autoheight: auto;
h-1/2height: 50%;
h-1/3height: 33.333333%;
h-2/3height: 66.666667%;
h-1/4height: 25%;
h-2/4height: 50%;
h-3/4height: 75%;
h-1/5height: 20%;
h-2/5height: 40%;
h-3/5height: 60%;
h-4/5height: 80%;
h-1/6height: 16.666667%;
h-2/6height: 33.333333%;
h-3/6height: 50%;
h-4/6height: 66.666667%;
h-5/6height: 83.333333%;
h-fullheight: 100%;
h-screenheight: 100vh;
h-minheight: min-content;
h-maxheight: max-content;
h-fitheight: fit-content;

Show all classes

Basic usage

Fixed heights

Use h-{number} or h-px to set an element to a fixed height.

Height - 图1

  1. <div class="h-96 ...">h-96</div>
  2. <div class="h-80 ...">h-80</div>
  3. <div class="h-64 ...">h-64</div>
  4. <div class="h-48 ...">h-48</div>
  5. <div class="h-40 ...">h-40</div>
  6. <div class="h-32 ...">h-32</div>
  7. <div class="h-24 ...">h-24</div>

Full height

Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

  1. <div class="h-48">
  2. <div class="h-full ...">
  3. <!-- This element will have a height of `12rem` (h-48) -->
  4. </div>
  5. </div>

Viewport height

Use h-screen to make an element span the entire height of the viewport.

  1. <div class="h-screen">
  2. <!-- ... -->
  3. </div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:h-full to only apply the h-full utility on hover.

  1. <div class="h-8 hover:h-full">
  2. <!-- ... -->
  3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:h-full to apply the h-full utility at only medium screen sizes and above.

  1. <div class="h-8 md:h-full">
  2. <!-- ... -->
  3. </div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind’s height scale is a combination of the default spacing scale as well as some additional values specific to heights.

You can customize your spacing scale by editing theme.spacing or theme.extend.spacing in your tailwind.config.js file.

tailwind.config.js

  1. module.exports = { theme: { extend: { spacing: { '128': '32rem', } } }}

To customize height separately, use the theme.height section of your tailwind.config.js file.

tailwind.config.js

  1. module.exports = { theme: { extend: { height: { '128': '32rem', } } }}

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off height value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <div class="h-[32rem]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.