Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tailwindcss/line-clamp

tailwindlabs2mMIT0.4.4TypeScript support: included

A plugin that provides utilities for visually truncating text after a fixed number of lines.

readme

@tailwindcss/line-clamp

A plugin that provides utilities for visually truncating text after a fixed number of lines.

Installation

Install the plugin from npm:

npm install -D @tailwindcss/line-clamp

Then add the plugin to your tailwind.config.js file:

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

Usage

Use the line-clamp-{n} utilities to specify how many lines of text should be visible before truncating:

<p class="line-clamp-3">
  Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
</p>

To remove any line-clamping, use line-clamp-none:

<p class="line-clamp-3 md:line-clamp-none">
  Et molestiae hic earum repellat aliquid est doloribus delectus. Enim illum odio porro ut omnis dolor debitis natus. Voluptas possimus deserunt sit delectus est saepe nihil. Qui voluptate possimus et quia. Eligendi voluptas voluptas dolor cum. Rerum est quos quos id ut molestiae fugit.
</p>

Note that the line-clamp-{n} set other properties like display and overflow in addition to -webkit-line-clamp which are not unset by line-clamp-none, so depending on what you are trying to achieve you may need to explicitly override those properties with utilities like flex or overflow-visible as well.

Utilities are for clamping text up to 6 lines are generated by default:

Class CSS
line-clamp-1 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
line-clamp-2 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp-3 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
line-clamp-4 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 4;
line-clamp-5 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 5;
line-clamp-6 overflow: hidden;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 6;
line-clamp-none -webkit-line-clamp: unset;

Configuration

You can configure which values and variants are generated by this plugin under the lineClamp key in your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      lineClamp: {
        7: '7',
        8: '8',
        9: '9',
        10: '10',
      }
    }
  },
  variants: {
    lineClamp: ['responsive', 'hover']
  }
}

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

  • Nothing yet!

0.4.4 - 2023-03-30

Changed

  • Remove Tailwind CSS v3.3 warning (#28)

0.4.3 - 2023-03-30

Changed

  • Warn when used in Tailwind CSS v3.3+ (#26)

0.4.2 - 2022-09-02

Fixed

  • Update TypeScript types (#23)

0.4.1 - 2022-09-01

Added

  • Add typescript types (#22)

0.4.0 - 2022-04-27

This release of @tailwindcss/line-clamp is designed for Tailwind CSS v3.0+, and is not compatible with earlier versions.

Added

  • Add support for arbitrary values (#10)

0.3.1 - 2021-12-09

Fixed

  • Add LICENSE file (#13)

Changed

  • Remove dist folder and related dependencies (#11)

0.3.0 - 2021-12-09

Added

  • Make sure that Tailwind CSS v3 is in peerDependencies (c9a9115)

[0.2.2] - 2021-10-01

Changed

  • Update peer dependencies to support v3 alpha

0.2.1 - 2021-05-24

Fixed

  • Mark tailwindcss as a peer-dependency for monorepo support (#6)

0.2.0 - 2021-01-22

Added

  • Allow using numbers instead of strings in your config (#3)

0.1.0 - 2021-01-06

Initial release!