Posts Learn Components Snippets Categories Tags Tools About
/

How to Multi-Line Truncate Text in Tailwind CSS

Learn how to truncate and clamp multi-line text in TailwindCSS

Created on Jul 08, 2021

13261 views

Truncating text is very common to provide a good visualization of the user interface. By default, TailwindCSS provide a "truncate" class out of the box but it only supports the single-line truncate.
<p class="truncate">
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>

In order to perform multi-line truncate you will have to install TailwindCSS line-clamp plugin. The steps are very simple, so let's get started.

1 - Install the Plugin
# Using Yarn
yarn add @tailwindcss/line-clamp

# Using npm
npm install @tailwindcss/line-clamp

2 - Require the Plugin in TailwindCSS Config
// tailwind.config.js

module.exports = {
  plugins: [
    require('@tailwindcss/line-clamp'),
  ],
}

3 - Truncate Text
<p class="line-clamp-2">
  Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</p>

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Sponsors 👑

+ Add Yours
)