I tried word-wrap: break-word;
, but it separates lines mid word.
In HTML, the <br> element creates a line break. You can add it wherever you want text to end on the current line and resume on the next.
The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line. word-break: break-all; It is used to break the words at any character to prevent overflow.
Use word-wrap:break-word; It even works in IE6, which is a pleasant surprise. word-wrap: break-word has been replaced with overflow-wrap: break-word; which works in every modern browser.
To have text-overflow property used, the text element must first overflow. This can be done by preventing the element from wrapping the overflowed content to a new line, which can be done by setting white-space: nowrap . Additionally overflow must be set to hidden .
In order to use word-wrap: break-word
, you need to set a width (in px). For example:
div { width: 250px; word-wrap: break-word; }
word-wrap is a CSS3 property, but it should work in all browsers, including IE 5.5-9.
As long as you specify a width on the element, it should wrap itself without needing anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With