← All Exercises
Clamp Paragraphs to Three Lines
intermediatecss
Background
line-clamp needs the legacy box-orient pair in most engines; clipping visually must not remove text from the accessibility tree.
Problem
Limit a card description to exactly three lines with an ellipsis and a fixed line height, and keep the full text available to assistive technology and search.
Input
A card with a long description and a fixed width.
Output
CSS that clamps the description to three lines.
Sample tests
Sample 1
Input: Description longer than three lines
Expected: display:-webkit-box with -webkit-line-clamp:3 and overflow:hidden shows a three-line ellipsis
Sample 2
Input: Screen reader reads the card
Expected: the full description remains in the DOM because clamping is visual only
Your solution
Learning objective
Clamp text to a fixed number of lines with a stable line height and a max-size fallback.