h-auto: Tailwind CSS Height class

The h-auto class allows the element’s height to adjust dynamically based on its content.


h-auto

The h-auto class allows the element’s height to adjust dynamically based on its content. Instead of setting a fixed height, the element expands or contracts depending on how much content is inside it. This is useful for paragraphs, cards, or dynamic elements like accordions.

Code Example

html
<div class="h-auto bg-indigo-500 text-white text-center flex justify-center items-center font-bold rounded-md">Height: auto</div>

Preview

Height: auto

How to Use

Add the h-auto class directly to your HTML element:

html
<div class="h-auto">
<!-- Your content here -->
</div>

Responsive Usage

Use Tailwind's responsive prefixes to apply h-auto at specific breakpoints:

html
<div class="sm:h-auto md:h-auto lg:h-auto">
Responsive element
</div>
  • sm:h-auto — applies from 640px and up
  • md:h-auto — applies from 768px and up
  • lg:h-auto — applies from 1024px and up

Customization

You can extend or override this utility in your tailwind.config.js. See the Tailwind CSS documentation for details on customizing your theme.

Windframe is an AI visual editor for rapidly building stunning web UIs & websites

Start building stunning web UIs & websites!

Build from scratch or select prebuilt tailwind templates