Kombai Logo

Tailwind CSS Height

Height defines how tall elements appear on the interface. The flexibility of height properties allows developers to manage fixed dimensions, responsive scaling, and dynamic sizing efficiently.

Tailwind CSS simplifies this process with an extensive range of utility classes for height management. These classes are designed for quick implementation, allowing you to achieve diverse layouts and responsive designs. This guide explores how to use height utilities in Tailwind CSS:

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

Overview of Height

Adding Fixed Height

Predefined scales are particularly effective when your design requires uniform height proportions. Use these fixed height utilities- h-2, h-3, h-4, etc. to set heights based on Tailwind's spacing scale.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Adding Full Height

A full-height utility allows you to stretch an element's height to fully cover its parent container or viewport. This is useful for creating immersive sections or hero banners.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Adding Viewport Height

h-screen utility can be used to make an element cover the entire height of the viewport:

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Adding Dynamic Viewport Height

Dynamic viewport height utility allows elements to cover the whole viewport height as the UI shrinks or expands.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Adding Large Viewport Height

Large viewport height utility allows define the height upto the largest possible extent, similar to h-screen.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Adding Small Viewport Height

Small viewport height utility allows define the height upto the smalles possible extent.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

States and Responsiveness

Hover and Focus States

You can conditionally modify the height of an element on user interactions, such as hovering or focusing. Use modifiers like hover, focus, etc. to target these states.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Breakpoint Modifiers

Breakpoints allow you to adjust element heights based on screen size for responsive designs. Use modifiers like sm, md, etc. to target individual breakpoints.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Custom Height

You can also customize Tailwind's theme to define unique height values that align with your branding or design guidelines.

Extending the Theme

Modify your tailwind.config.js file to add custom values directly into your project.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Using Arbitrary Values

In scenarios where quick runtime values can fill in, Tailwind allows arbitrary values to suit your requirements.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Real World Examples

This example demonstrates a responsive product gallery with cards that adjust their height based on content.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Vertical Timeline with Fixed Heights

A timeline component that uses fixed heights for consistent spacing.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Full-Height Hero Section with Scroll Indicator

A hero section that takes up the full viewport height with a scroll indicator.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Multi-Level Dashboard Sidebar

A dashboard sidebar with varying heights for different menu sections.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Team Member Grid with Variable Heights

A responsive grid showing team members with cards that adjust height based on content.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Customization Examples

Responsive Product Card with Custom Height Breakpoints

This example demonstrates how to create a product card with custom heights at different breakpoints.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Dynamic Height Dashboard Sidebar

This example shows how to create a dashboard sidebar with custom height utilities.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

This example demonstrates creating an image gallery with varying custom heights.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Best Practices

Maintain Design Consistency

Stick to pre-defined classes like h-16, h-32, and h-64 rather than relying on arbitrary heights whenever possible. This approach reduces visual clutter.

You can also create custom height scales in your tailwind.config.js file to maintain consistency if your project’s design systems require specific measurements. For instance, defining a series of custom heights for a card component used across your web app ensures standardized dimensions. Pair these height utilities with standardized padding (p-*) and margin (m-*) classes to maintain proportional spacing.

Additionally, ensure consistency by aligning heights with breakpoints to enable responsive designs. For instance, height variations based on screen size—like h-24 md:h-48 lg:h-64—help different elements adapt seamlessly across different devices while keeping the overall design visually consistent.

Leverage Utility Combinations

Combining height utilities with complementary classes like w-*, flex, and spacing utilities allows you to create intricate layouts efficiently. For example, combining h-screen with flex justify-center items-center can help you center content vertically and horizontally on full-height sections. Similarly, you could add classes like p-* to maintain proper spacing.

You can also combine min-h-* and max-h-* utilities with responsive prefixes to control the vertical expansion and contraction of elements on different screens. This combination is particularly useful for creating scrollable sections where the height is constrained within a maximum limit while ensuring a responsive minimum height.

Accessibility Considerations

Enhance Readability and Navigability

Ensure sufficient vertical spacing between interactive elements or content blocks by using h-* utilities. You can also use responsive height utilities (md:h-*, lg:h-*) to cater to varying screen sizes, enhancing accessibility both for smaller devices and larger monitors.

Organize content hierarchically within vertically spaced containers to direct user attention appropriately. Avoid assigning extremely small heights to your elements. Instead, aim for readable dimensions and use responsive adjustments alongside padding utilities to create legible and accessible designs.

Focus on High Contrast

Combining proper height utilities with high-contrast colors significantly improves accessibility for visual impairments. Ensure backgrounds covering a full section or element (h-screen, h-full) have contrasting text colors to improve readability. For example, pairing a bg-gray-800 with text-white ensures sufficient contrast for text that spans the entire height of a container.

Debugging Common Issues

Handle Nested Element Challenges

When facing height-related issues in deeply nested structures, excessive utility overrides can cause conflicts. Manage these nested hierarchies by explicitly defining heights at different container levels using utilities like h-auto, min-h-*, and max-h-*. This ensures that children nodes adapt appropriately without exceeding or shrinking unexpectedly within parent containers.

Isolate Utility Conflicts

Utility conflicts often occur when multiple height-based classes unintentionally overwrite desired styling. To debug such issues, prioritize baseline values and only extend them as needed. When multiple height utilities are applied to the same element (e.g., h-32 and h-auto), use browser DevTools to inspect rendered styles and identify overrides.

You can also isolate conflicting classes by systematically removing and reapplying utilities to narrow the source of the problem. Use Tailwind’s !important modifier (!h-40) sparingly for critical corrections, but always aim for clean and readable utility combinations to create maintainable codebases.

Beyond utility inspection, validate the consistency of custom height additions in tailwind.config.js and their responsive usage. Conflicts often arise when arbitrary height values are unintentionally used beyond their intended scope. Keep configurations well-organized and well-documented to avoid such issues.