1. 字体
  2. line-height

字体

行高

用于控制元素的行距(行高)的工具类。

ClassStyles
text-<size>/<number>
font-size: <size>; line-height: calc(var(--spacing) * <number>);
text-<size>/(<custom-property>)
font-size: <size>; line-height: var(<custom-property>);
text-<size>/[<value>]
font-size: <size>; line-height: <value>;
leading-none
line-height: 1;
leading-<number>
line-height: calc(var(--spacing) * <number>)
leading-(<custom-property>)
line-height: var(<custom-property>);
leading-[<value>]
line-height: <value>;

示例

基础示例

使用字体大小工具类(如 text-sm/6text-lg/7)来同时设置元素的字体大小和行高:

text-sm/6

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

text-sm/7

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

text-sm/8

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-base/6 ...">So I started to walk into the water...</p><p class="text-base/7 ...">So I started to walk into the water...</p><p class="text-base/8 ...">So I started to walk into the water...</p>

当没有提供行高时,每个字体大小工具类也会设置一个默认的行高。你可以在字体大小文档中了解更多关于这些值及如何自定义它们的信息。

独立设置

使用 leading-<number> 工具类(如 leading-6leading-7)来独立于字体大小设置元素的行高:

leading-6

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

leading-7

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

leading-8

So I started to walk into the water. I won't lie to you boys, I was terrified. But I pressed on, and as I made my way past the breakers a strange calm came over me. I don't know if it was divine intervention or the kinship of all living things but I tell you Jerry at that moment, I was a marine biologist.

<p class="text-sm leading-6">So I started to walk into the water...</p><p class="text-sm leading-7">So I started to walk into the water...</p><p class="text-sm leading-8">So I started to walk into the water...</p>

移除行高

使用 leading-none 工具类将元素的行高设置为等于其字体大小:

The quick brown fox jumps over the lazy dog.

<p class="text-2xl leading-none ...">The quick brown fox...</p>

使用自定义值

Use the leading-[<value>] syntax to set the 行高 based on a completely custom value:

<p class="leading-[1.5] ...">  Lorem ipsum dolor sit amet...</p>

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

<p class="leading-(--my-line-height) ...">  Lorem ipsum dolor sit amet...</p>

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

响应式设计

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

<p class="leading-5 md:leading-6 ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.

自定义主题

The leading-<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.·Trademark Policy