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

Top comments (0)