height

Các utility để thiết lập chiều cao của một phần tử.

ClassStyles
h-<number>
height: calc(var(--spacing) * <number>);
h-<fraction>
height: calc(<fraction> * 100%);
h-auto
height: auto;
h-px
height: 1px;
h-full
height: 100%;
h-screen
height: 100vh;
h-dvh
height: 100dvh;
h-dvw
height: 100dvw;
h-lvh
height: 100lvh;
h-lvw
height: 100lvw;

Ví dụ

Ví dụ cơ bản

Sử dụng các utility h-<number> như h-24h-64 để thiết lập chiều cao cố định cho một phần tử dựa trên thang khoảng cách:

h-96
h-80
h-64
h-48
h-40
h-32
h-24
<div class="h-96 ...">h-96</div><div class="h-80 ...">h-80</div><div class="h-64 ...">h-64</div><div class="h-48 ...">h-48</div><div class="h-40 ...">h-40</div><div class="h-32 ...">h-32</div><div class="h-24 ...">h-24</div>

Sử dụng phần trăm

Sử dụng h-full hoặc các utility h-<fraction> như h-1/2h-2/5 để thiết lập chiều cao dựa trên phần trăm cho một phần tử:

h-full
h-9/10
h-3/4
h-1/2
h-1/3
<div class="h-full ...">h-full</div><div class="h-9/10 ...">h-9/10</div><div class="h-3/4 ...">h-3/4</div><div class="h-1/2 ...">h-1/2</div><div class="h-1/3 ...">h-1/3</div>

Khớp với viewport

Sử dụng utility h-screen để làm cho một phần tử trải dài toàn bộ chiều cao của viewport:

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

Khớp với viewport động

Sử dụng utility h-dvh để làm cho một phần tử trải dài toàn bộ chiều cao của viewport, thay đổi khi giao diện trình duyệt mở rộng hoặc thu nhỏ:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-dvh

<div class="h-dvh">  <!-- ... --></div>

Khớp với viewport lớn

Sử dụng utility h-lvh để thiết lập chiều cao của một phần tử thành chiều cao lớn nhất có thể của viewport:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-lvh

<div class="h-lvh">  <!-- ... --></div>

Khớp với viewport nhỏ

Sử dụng utility h-svh để thiết lập chiều cao của một phần tử thành chiều cao nhỏ nhất có thể của viewport:

Scroll the viewport to see the viewport height change

tailwindcss.com

h-svh

<div class="h-svh">  <!-- ... --></div>

Thiết lập cả chiều rộng và chiều cao

Sử dụng các utility như size-px, size-4, và size-full để thiết lập cả chiều rộng và chiều cao của một phần tử cùng một lúc:

size-16
size-20
size-24
<div class="size-16 ...">size-16</div><div class="size-20 ...">size-20</div><div class="size-24 ...">size-24</div><div class="size-32 ...">size-32</div><div class="size-40 ...">size-40</div>

Sử dụng giá trị tùy chỉnh

Use the h-[<value>] syntax to set the height based on a completely custom value:

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

For CSS variables, you can also use the h-(<custom-property>) syntax:

<div class="h-(--my-height) ...">  <!-- ... --></div>

This is just a shorthand for h-[var(<custom-property>)] that adds the var() function for you automatically.

Thiết kế phản hồi

Prefix a height utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.

Tùy chỉnh theme của bạn

The h-<number> and size-<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.

Copyright © 2025 Tailwind Labs Inc.·Chính sách thương hiệu