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:
These properties provide better readability and maintain a responsive design. Always test styles across devices and resolutions for consistency.