Skip to content

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

License

Notifications You must be signed in to change notification settings

tailwindlabs/tailwindcss-line-clamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 6, 2021
08fdd1f · Jan 6, 2021

History

2 Commits
Jan 6, 2021
Jan 6, 2021
Jan 6, 2021
Jan 6, 2021
Jan 6, 2021
Jan 6, 2021
Jan 6, 2021

Repository files navigation

@tailwindcss/line-clamp

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

Installation

Install the plugin from npm:

# Using npm
npm install @tailwindcss/line-clamp

# Using Yarn
yarn add @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="overflow-hidden 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="overflow-hidden 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>

In the future we might add a line-clamp-none utility that is a bit more expressive, but we need to do some experimenting to determine the best implementation.

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

Aspect ratio classes up to 16 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: {
    aspectRatio: ['responsive', 'hover']
  }
}

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published