Typography

Line Clamp

Utilities for clamping text to a specific number of lines.

Quick reference

Class
Properties
line-clamp-1overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1;
line-clamp-2overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
line-clamp-3overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
line-clamp-4overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 4;
line-clamp-5overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 5;
line-clamp-6overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6;
line-clamp-noneoverflow: visible; display: block; -webkit-box-orient: horizontal; -webkit-line-clamp: none;

Basic usage

Truncating multi-line text

Use the line-clamp-* utilities to truncate a block of text after a specific number of lines.

Line Clamp - 图1

  1. <article>
  2. <time>Mar 10, 2020</time>
  3. <h2>Boost your conversion rate</h2>
  4. <p class="line-clamp-3">Nulla dolor velit adipisicing duis excepteur esse in duis nostrud occaecat mollit incididunt deserunt sunt. Ut ut sunt laborum ex occaecat eu tempor labore enim adipisicing minim ad. Est in quis eu dolore occaecat excepteur fugiat dolore nisi aliqua fugiat enim ut cillum. Labore enim duis nostrud eu. Est ut eiusmod consequat irure quis deserunt ex. Enim laboris dolor magna pariatur. Dolor et ad sint voluptate sunt elit mollit officia ad enim sit consectetur enim.</p>
  5. <div>
  6. <img src="..." />
  7. Lindsay Walton
  8. </div>
  9. </article>

Undoing line clamping

Use line-clamp-none to undo a previously applied line clamp utility.

  1. <p class="line-clamp-3 lg:line-clamp-none">
  2. <!-- ... -->
  3. </p>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:line-clamp-4 to only apply the line-clamp-4 utility on hover.

  1. <p class="line-clamp-3 hover:line-clamp-4">
  2. <!-- ... -->
  3. </p>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:line-clamp-4 to apply the line-clamp-4 utility at only medium screen sizes and above.

  1. <p class="line-clamp-3 md:line-clamp-4">
  2. <!-- ... -->
  3. </p>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind provides the six line-clamp utilities. You can customize these values by editing theme.lineClamp or theme.extend.lineClamp in your tailwind.config.js file.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. extend: {
  4. lineClamp: {
  5. 7: '7',
  6. },
  7. }
  8. }
  9. }

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off line-clamp value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <p class="line-clamp-[7]">
  2. <!-- ... -->
  3. </p>

Learn more about arbitrary value support in the arbitrary values documentation.