How to make truncate text in CSS

jetthoughts-dev

JetThoughts Dev

Posted on August 1, 2022

How to make truncate text in CSS
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
Enter fullscreen mode Exit fullscreen mode

Image description

There is no native CSS property for truncating text. However, you can use the ellipsis character to display truncated text.

p {
  max-width: 800px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
Enter fullscreen mode Exit fullscreen mode

Image description

Note we have given the element a fixed width. This is made because the element needs a certain width.

💖 💪 🙅 🚩
jetthoughts-dev
JetThoughts Dev

Posted on August 1, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Drawing Togo's Flag with CSS
css Drawing Togo's Flag with CSS

November 19, 2024

Exploring Nesting with Flexbox
learning Exploring Nesting with Flexbox

August 30, 2024

Bad CSS-Dad Jokes (III)
css Bad CSS-Dad Jokes (III)

September 27, 2024

Bad CSS-Dad Jokes (II)
css Bad CSS-Dad Jokes (II)

September 23, 2024