Text Overflow

Utilities for controlling text overflow in an element.

Default class reference

Class
Properties
truncateoverflow: hidden; text-overflow: ellipsis; white-space: nowrap;
overflow-ellipsistext-overflow: ellipsis;
overflow-cliptext-overflow: clip;

Truncate

Use truncate to truncate overflowing text with an ellipsis () if needed.

Text Overflow - 图1

  1. <p class="truncate ...">...</p>

Overflow Ellipsis

Use overflow-ellipsis to truncate overflowing text with an ellipsis () if needed.

Text Overflow - 图2

  1. <p class="overflow-ellipsis overflow-hidden ...">...</p>

Overflow Clip

Use overflow-clip to truncate the text at the limit of the content area.

Text Overflow - 图3

  1. <p class="overflow-clip overflow-hidden ...">...</p>

Responsive

To control the text overflow in an element only at a specific breakpoint, add a {screen}: prefix to any existing text overflow utility. For example, adding the class md:overflow-clip to an element would apply the overflow-clip utility at medium screen sizes and above.

  1. <p class="truncate md:overflow-clip ...">
  2. <!-- ... -->
  3. </p>

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Customizing

Variants

By default, only responsive variants are generated for text overflow utilities.

You can control which variants are generated for the text overflow utilities by modifying the textOverflow property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. extend: {
  5. // ...
  6. + textOverflow: ['hover', 'focus'],
  7. }
  8. }
  9. }

Disabling

If you don’t plan to use the text overflow utilities in your project, you can disable them entirely by setting the textOverflow property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + textOverflow: false,
  6. }
  7. }

←Text Transform Vertical Align→

Edit this page on GitHub