Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS line-clamp limits a block of text to a chosen number of displayed lines, which is useful for compact previews, cards, and similar layouts. Browser support is not universal, so check the compatibility table for the browsers your site serves and use the established prefixed pattern when needed.

What does the CSS line-clamp property do?

line-clamp sets the maximum number of lines shown for a block. Its initial value is none; when using a number, specify an integer greater than zero. The property can also accept a block-ellipsis value, such as auto, no-ellipsis, or a custom string. See the MDN line-clamp reference for syntax and current browser compatibility.

Clamping is a presentation choice: choose a line count that fits the surrounding layout and keeps the preview useful. The property is not the same as CSS clamp(), which constrains a numeric value between minimum and maximum bounds.

How to clamp text with the legacy-compatible pattern

For older browser support, the established approach uses the prefixed property with the required display and orientation declarations:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
p {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

Replace 3 with the desired line count. The -webkit-line-clamp declaration only works with display: -webkit-box and -webkit-box-orient: vertical. In most cases, overflow: hidden clips the remaining content; without it, content may still be visible even when an ellipsis appears.

How to use the standard line-clamp property

For browsers that support the standard property, a basic rule can use line-clamp directly:

.preview {
  line-clamp: 2;
  overflow: hidden;
}

MDN also documents custom marker syntax, for example line-clamp: 3 "… (there is extra content)". Support can vary by syntax form, so check the compatibility table and test the browsers you target before relying on custom ellipsis behavior.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Standard and prefixed syntax compared

Implementation Declarations What to check
Standard property line-clamp: N, typically with overflow: hidden Support in your target browsers; custom ellipsis forms may have different support.
Legacy prefixed pattern display: -webkit-box, -webkit-box-orient: vertical, and -webkit-line-clamp: N, typically with overflow: hidden Keep the required display and orientation declarations together.

What to test before shipping

  • Check MDN’s current compatibility table for the browser versions your audience uses; line-clamp is marked “Limited availability” and is not Baseline.
  • Verify the clipped result at different viewport widths and text lengths, since wrapping affects which words appear before the cutoff.
  • Test anchors and other interactive text carefully: clamping an anchor can truncate in the middle of its text rather than at the end.
  • Confirm that overflow is clipped as intended and that the chosen line count leaves users enough context.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.