• Stars
    star
    1,152
  • Rank 39,050 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

@tailwindcss/line-clamp

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

Warning As of Tailwind CSS v3.3 the line-clamp utilities are now included in the framework by default and this plugin is no longer required.

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']
  }
}

More Repositories

1

tailwindcss

A utility-first CSS framework for rapid UI development.
HTML
77,154
star
2

headlessui

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
TypeScript
23,838
star
3

heroicons

A set of free MIT-licensed high-quality SVG icons for UI development.
JavaScript
20,391
star
4

prettier-plugin-tailwindcss

A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.
JavaScript
4,549
star
5

tailwindcss-forms

A plugin that provides a basic reset for form styles that makes form elements easy to override with utilities.
HTML
3,862
star
6

tailwindcss-typography

Beautiful typographic defaults for HTML you don't control.
JavaScript
3,513
star
7

tailwindcss.com

The Tailwind CSS documentation website.
MDX
3,066
star
8

tailwindcss-intellisense

Intelligent Tailwind CSS tooling for Visual Studio Code
TypeScript
2,635
star
9

tailwindcss-jit

JavaScript
2,197
star
10

tailwindcss-custom-forms

A better base for styling form elements with Tailwind CSS.
JavaScript
1,557
star
11

tailwindcss-aspect-ratio

JavaScript
905
star
12

tailwindcss-container-queries

A plugin for Tailwind CSS v3.2+ that provides utilities for container queries.
TypeScript
877
star
13

designing-with-tailwindcss

Source code for the "Designing with Tailwind CSS" course.
CSS
705
star
14

heroicons.com

JavaScript
697
star
15

tailwindcss-setup-examples

679
star
16

tailwindui-vue

Deprecated, please use the Headless UI repo instead.
JavaScript
650
star
17

play.tailwindcss.com

JavaScript
638
star
18

tailwindcss-playground

HTML
516
star
19

tailwindui-react

Deprecated, please use the Headless UI repo instead.
TypeScript
432
star
20

tailwindcss-from-zero-to-production

Source code for the "Tailwind CSS Up and Running" screencast series.
JavaScript
369
star
21

blog.tailwindcss.com

JavaScript
340
star
22

tailwindui-issues

Bug fixes and feature request tracking for Tailwind UI.
231
star
23

webpack-starter

A quick and simple example of using Tailwind CSS with Webpack.
JavaScript
216
star
24

tailwindcss-plugin-examples

Examples to help you get started building your own Tailwind CSS plugins.
JavaScript
208
star
25

discuss

A place to ask questions, get help, or share what you've built with Tailwind CSS.
171
star
26

tailwind-play-api

PHP
44
star
27

minimal-tailwind-postcss-plugin

A simple PostCSS plugin designed to cover all of the tricky integration points a build-tool needs to support for Tailwind CSS.
JavaScript
10
star
28

reproduction-headlessui-vue

JavaScript
8
star