The Wayback Machine - https://web.archive.org/web/20240712010856/https://www.geeksforgeeks.org/tailwind-css-height/
Open In App

Tailwind CSS Height

Last Updated : 23 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

This class accepts lots of values in tailwind CSS in which all the properties are covered in class form.  It is the alternative to the CSS height Property. This class is used to set the height of an element. The height class does not contain padding, margin, and the border of elements.

Height classes:

  • h-0: This class sets the height to zero.
  • h-auto: This class sets the height according to the content.
  • h-px: This class is used to set the height in 1px fix.
  • h-1/2: This class sets the height to half of the window.
  • h-1/3: This class sets the height to one-third of the window.
  • h-1/4: This class sets the height to one-fourth of the window.
  • h-1/5: This class sets the height to one-fifth of the window.
  • h-1/6: This class sets the height to one-sixth of the window.
  • h-full: This class sets an element’s height to 100% of its parent, as long as the parent has a defined height.
  • h-screen: This class used to make an element span the entire height of the viewport.

Note: You can change the number with the valid “rem” values or set the percentage value.

h-0: This class is used to set the specific height for any element, you can change the number with a valid number of rem units to fix the height of the element.

Syntax:

<element class="h-0">...</element>

Example:

HTML




<!DOCTYPE html> 
<head> 
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"> 
</head> 
  
<body class="text-center mx-4 space-y-2"> 
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1> 
    <b>Tailwind CSS Height Class</b> 
    <div class="flex flex-wrap-reverse p-4 mx-12 
                space-x-4 h-64 bg-green-200">
        <div class="h-8 w-12 bg-green-400 
                    rounded-lg">h-8</div>
        <div class="h-12 w-12 bg-green-400 
                    rounded-lg">h-12</div>
        <div class="h-16 w-12 bg-green-400 
                    rounded-lg">h-16</div>
        <div class="h-20 w-12 bg-green-400 
                    rounded-lg">h-20</div>
        <div class="h-24 w-12 bg-green-400 
                    rounded-lg">h-24</div>
        <div class="h-32 w-12 bg-green-400 
                    rounded-lg">h-32</div>
        <div class="h-40 w-12 bg-green-400 
                    rounded-lg">h-40</div>
        <div class="h-48 w-12 bg-green-400 
                    rounded-lg">h-48</div>
        <div class="h-52 w-12 bg-green-400 
                    rounded-lg">h-52</div>
    </div>
</body> 
  
</html>


Output:

h-auto: This class is used to let the browser determine the height of the element.

Syntax:

<element class="h-auto">...</element>

Example:

HTML




<!DOCTYPE html> 
<head> 
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"> 
</head> 
  
<body class="text-center mx-4 space-y-2"> 
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1> 
    <b>Tailwind CSS Height Class</b> 
    <div class="mx-48 bg-green-200 p-8">
        <div class="h-auto bg-green-400 
                    rounded-lg">h-auto</div>
    </div>
</body> 
  
</html>


Output:

h-screen: This class is used to make an element span the entire height of the viewport.

Syntax:

<element class="h-screen">...</element>

Example:

HTML




<!DOCTYPE html> 
<head> 
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"> 
</head> 
  
<body class="text-center mx-4 space-y-2"> 
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1> 
    <b>Tailwind CSS Height Class</b> 
    <div class="mx-48 bg-green-200 p-8">
        <div class="h-screen bg-green-400 
                    rounded-lg">h-screen</div>
    </div>
</body> 
  
</html>


Output:

h-full: This class is used to set an element’s height to 100% of its parent, as long as the parent has a defined height.

Syntax:

<element class="h-full">...</element>

Example:

HTML




<!DOCTYPE html> 
<head> 
    <link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" 
          rel="stylesheet"> 
</head> 
  
<body class="text-center mx-4 space-y-2"> 
    <h1 class="text-green-600 text-5xl font-bold">
        GeeksforGeeks
    </h1> 
    <b>Tailwind CSS Height Class</b> 
    <div class="mx-48 h-48 bg-green-200 p-8">
        <div class="h-full bg-green-400 
                    rounded-lg">h-full</div>
    </div>
</body> 
  
</html>


Output:



Previous Article
Next Article

Similar Reads

HTML width/height Attribute vs CSS width/height Property
In HTML 5, few elements follow the width and height attributes and maximum elements do not follow this attribute. Like img, iframe, canvas, and svg kind of elements follow the width and height attributes but div, span, article and section type of elements don't follow them.The width and height attributes are affected in img, svg tags, those are wea
3 min read
How to expand floated child div's height to its parent's height in CSS ?
Making the height of the floating child div equal to the height of the parent div is referred to as expanding the height of the floated child div to the height of the parent div. Approach 1: Using the CSS "clearfix" method is the first approach to increase a floated child div's height to match its parent's height. When an element is floated, it is
4 min read
Tailwind CSS Line Height
This class accepts lots of value in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS Line Height property. This class is used to set the amount of space used for lines, such as in the text. Negative values are not allowed. Line Height classes: leading-3: This class set the line-height at .75rem
2 min read
Tailwind CSS Max-Height
This class accepts lots of values in tailwind CSS in which all the properties are covered in class form. It is the alternative to the CSS Max-Height property. This class is used to set the maximum height of an element. If the content of the element is larger than the specified maximum-height then the content will overflow otherwise it has no effect
2 min read
Tailwind CSS Min-Height
This class accepts lots of values in tailwind CSS in which all the properties are covered in class form. It is the alternative to the CSS Min-Height Property. This class is used to set the minimum height of an element. The min-height class is used when the content of the element is smaller than the min-height and if the content is larger than the m
2 min read
How to fill up the rest of screen height using Tailwind CSS ?
In this article, we will learn how to fill up the rest of the screen height using Tailwind CSS. Approach: To solve the above problem we'll be using the Flex Class and Height Class of Tailwind CSS. The classes that we'll be using to solve this are as follows. flex: It is used to set the length of flexible items. The flex class is much responsive and
1 min read
How to make grid items auto height using tailwind CSS ?
You can easily make CSS grid items to auto height using grid-template-columns property in Tailwind CSS. Tailwind uses grid-col and grid-row property which is an alternative to the grid-template-columns property in CSS. The grid-template-columns property in CSS is used to set the number of columns and size of the columns of the grid. This class acce
2 min read
How to fill the height of the viewport with tailwind CSS ?
Tailwind CSS is a popular utility-first CSS framework that makes designing and building responsive websites easier. Filling the height of the viewport with a specific element or container is a common design requirement. This is simple to accomplish with Tailwind CSS, and we will look at various approaches in this article. Syntax: Before we dive int
4 min read
How to specify height to fit-content with Tailwind CSS ?
Tailwind CSS is a popular utility-first CSS framework that makes it easy to create responsive and customizable user interfaces. The ability of Tailwind CSS to specify the height of an element using the fit-content value allows the height of an element to adjust to the content inside it, making it useful for creating dynamic layouts. In this article
3 min read
How to make div fill full height of parent in Tailwind CSS ?
Tailwind CSS is a utility-first CSS framework that provides various pre-designed classes for easy and efficient styling of HTML elements. Sometimes, we may encounter a scenario where we need to make a div fill the full height of its parent element. In such a case, we can use Tailwind CSS classes to achieve this goal. To make a div fill the full hei
4 min read
three90RightbarBannerImg