Saturday, January 11, 2025
HomeProgrammingHow to wrap text in CSS

How to wrap text in CSS

To wrap text in CSS, use word-wrap, overflow-wrap, or white-space. Set overflow-wrap: break-word; (or word-wrap: break-word;) to break long words that don’t fit within a container. This ensures no text overflows unsightly.

Use white-space: normal; (default) to allow wrapping or white-space: nowrap; to prevent it entirely. For truncating overflowing text with ellipsis, combine text-overflow: ellipsis;, overflow: hidden;, and white-space: nowrap;.

Example:

css
p {
overflow-wrap: break-word;
white-space: normal;
}

These properties provide better readability and maintain a responsive design. Always test styles across devices and resolutions for consistency.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x