1. Presets
  2. Line Clamp

Presets

@twind/preset-line-clamp

MIT License Latest Release Github

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

Note

Based on @tailwindcss/line-clamp.

🤝 Compatibility

@twind/preset-line-clamp@tailwindcss/line-clamp
>=1.0.0-next.27 <1.1.0>=0.3 <0.5

📦 Installation

with @twind/core

Install from npm:

sh
npm install @twind/core @twind/preset-line-clamp

Add the preset to your twind config:

twind.config.js
js
import { defineConfig } from '@twind/core'
import presetLineClamp from '@twind/preset-line-clamp'

export default defineConfig({
  presets: [presetLineClamp(/* options */)],
  /* config */
})
Usage with a script tag
html
<head>
  <script
    src="https://cdn.jsdelivr.net/combine/npm/twind,npm/@twind/preset-line-clamp"
    crossorigin
  ></script>
  <script>
    twind.install({
      presets: [twind.presetLineClamp(/* options */)],
      /* config */
    })
  </script>
</head>

with Twind CDN

html
<head>
  <script src="https://cdn.twind.style/line-clamp" crossorigin></script>
  <script>
    twind.install({
      presets: [twind.presetLineClamp()],
      /* config */
    })
  </script>
</head>

🙇 Usage

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

html
<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:

html
<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>

🔧 Theme

A lineClamp section is added to the theme. Its values are used for looking up the value. If no value is found the given parameter is used.

js
setup({
  theme: {
    lineClamp: {
      card: '5',
    },
  },
})

tw('line-clamp-card')
// => -webkit-line-clamp:5

// Not found in theme => use as is
tw('line-clamp-7')
// => -webkit-line-clamp:7