1. 排版
  2. line-height(行高)

排版

line-height

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

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

于是我开始走进水里。老实说孩子们,我当时吓坏了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你杰瑞,在那一刻,我就是一名海洋生物学家。

text-sm/7

于是我开始走进水里。老实说孩子们,我当时吓坏了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你杰瑞,在那一刻,我就是一名海洋生物学家。

text-sm/8

于是我开始走进水里。老实说孩子们,我当时吓坏了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。我不知道这是神的干预还是所有生物的亲密关系,但我告诉你杰瑞,在那一刻,我就是一名海洋生物学家。

<p class="text-base/6 ...">于是我开始走进水里...</p><p class="text-base/7 ...">于是我开始走进水里...</p><p class="text-base/8 ...">于是我开始走进水里...</p>

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

独立设置行高

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

leading-6

于是我开始走向水中。老实说孩子们,我当时害怕极了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。不知道是神的干预还是万物有灵,但我要告诉你杰瑞,那一刻我就是一名海洋生物学家。

leading-7

于是我开始走向水中。老实说孩子们,我当时害怕极了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。不知道是神的干预还是万物有灵,但我要告诉你杰瑞,那一刻我就是一名海洋生物学家。

leading-8

于是我开始走向水中。老实说孩子们,我当时害怕极了。但我坚持前进,当我穿过浪花时,一种奇怪的平静笼罩了我。不知道是神的干预还是万物有灵,但我要告诉你杰瑞,那一刻我就是一名海洋生物学家。

<p class="text-sm leading-6">于是我开始走向水中...</p><p class="text-sm leading-7">于是我开始走向水中...</p><p class="text-sm leading-8">于是我开始走向水中...</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