DEV Community

Hamad
Hamad

Posted on

Truncate String with Ellipsis: CSS!

Today, I wanted to share a handy CSS technique for truncating long strings with an elegant ellipsis. If you've ever struggled with text overflowing and breaking your beautifully designed layout,

How to truncate strings using CSS and bring tidiness to your content?

๐’๐ง๐ข๐ฉ๐ฉ๐ž๐ญ ๐š๐ญ๐ญ๐š๐œ๐ก๐ž๐:

The overflow: hidden property hides any content that overflows the container, white-space: nowrap ensures the text doesn't wrap to the next line, and text-overflow: ellipsis adds the ellipsis when the text is truncated.

๐Ÿ’ก Pro tip #1: You can adjust the width of the container or combine this technique with media queries to create responsive designs that handle text truncation gracefully on different screen sizes.

๐Ÿ’ก Pro tip #2: Resize: horizontal or vertical can be used to scale it accordingly

If you found this tip helpful or have any questions, feel free to share your thoughts in the comments below. ๐ŸŽจ

Image description

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay