How to Create Columns with the Same Height in Tailwind CSS ?
Last Updated :
14 Feb, 2024
Creating columns of equal height is a common design requirement in web development. This need arises in scenarios like displaying a grid of cards or a list of items where each column should have the same height regardless of its content. Tailwind CSS, a utility-first CSS framework, provides several ways to achieve equal height columns effortlessly. This article will explore these methods, including Flexbox, Grid, and other Tailwind utilities, with detailed descriptions and complete HTML code examples.
Using Flexbox
Tailwind CSS's Flexbox utilities make it simple to create columns with equal height. By applying flex
display and flex-col
direction to a container, and then controlling the width of each child element, you can ensure that all columns match the height of the tallest column.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Equal Height Columns with Flexbox</title>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>
<body>
<div class="flex p-4">
<div class="flex-1 bg-blue-500 p-4 text-white">
GeeksforGeeks: A computer science portal for geeks.
</div>
<div class="flex-1 bg-green-500 p-4 text-white">HTML</div>
<div class="flex-1 bg-red-500 p-4 text-white">CSS</div>
</div>
</body>
</html>
Output

Using Grid
The CSS Grid layout offers another approach to creating equal-height columns. Tailwind CSS provides Grid utilities that simplify this process. By setting a container to grid
and defining the grid columns, all child elements automatically have equal height.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Equal Height Columns with Grid</title>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>
<body>
<div class="p-4 grid grid-cols-3 gap-2">
<div class="bg-blue-500 p-4 text-white">
GeeksforGeeks: A computer science portal for geeks.
</div>
<div class="bg-green-500 p-4 text-white">HTML</div>
<div class="bg-red-500 p-4 text-white">CSS</div>
</div>
</body>
</html>
Output

Using Tailwind CSS Height Utilities
While Flexbox and Grid are the most straightforward ways to achieve equal-height columns, there may be scenarios where you need to explicitly set the height of columns. Tailwind's height (h
) utilities can be used to manually set the height of each column to the same value.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content=
"width=device-width, initial-scale=1.0">
<title>Equal Height Columns with Height Utilities</title>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>
<body>
<div class="m-4 flex">
<div class="w-1/3 bg-blue-500 p-4 text-white h-64">
GeeksforGeeks: A computer science portal for geeks.
</div>
<div class="w-1/3 bg-green-500 p-4 text-white h-64">HTML</div>
<div class="w-1/3 bg-red-500 p-4 text-white h-64">CSS</div>
</div>
</body>
</html>
Output

Similar Reads
How to Specify Height to Fit-Content with Tailwind CSS ? Specifying height to fit-content in Tailwind CSS means setting an elementâs height to automatically adjust based on its content. Tailwind provides the h-fit utility class, which ensures the element's height dynamically adapts to its content's size.Adjusting Height with h-fit in Tailwind CSSThis appr
3 min read
How to Create Equal Height Columns in CSS ? Equal Height Columns in CSS refer to ensuring that multiple columns in a layout have the same height, regardless of the content inside each column. This can be achieved using modern CSS techniques like Flexbox, CSS Grid, or the Table display property.Table of ContentUsing FlexUsing GridUsing Table p
3 min read
How to Creating Horizontal Rule Divider with Text in Tailwind CSS ? In this article, we will understand how to create a horizontal rule (HR) divider that contains text with Tailwind CSS. The problem here is that in an HR, there is no text, & only a divider is visible, and there is no default method to add text in Tailwind CSS. Tailwind CSS is a highly customizab
3 min read
How to create fixed/sticky footer on the bottom using Tailwind CSS ? In this article, we are going to create a fixed/sticky footer on the bottom using Tailwind CSS. Tailwind CSS is a highly customizable, utility-first CSS framework from which we can use utility classes to build any design. With Tailwind CSS we can create a design by simply adding classes. Installatio
2 min read
How to Create a 4-Column Layout Grid with CSS? We can create a layout with multiple columns using CSS. It is easier to design complex layouts. In this article, we are going to discuss how to create a 4-column layout grid using CSS. We will discuss different approaches, their syntax, and code examples of each method. A 4-column layout grid is a c
3 min read