Mozilla Firefox solution

Add:

display: inline-block;

to the style of your td.

Webkit based browsers (Google Chrome, Safari, ...) solution

Add:

display: inline-block;
word-break: break-word;

to the style of your td.

Note: Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to the standard.

Opera solution

Add:

display: inline-block;
word-break: break-word;

to the style of your td.

The previous paragraph applies to Opera in a similar way.

Answer from Stencil on Stack Overflow
Top answer
1 of 11
135

Mozilla Firefox solution

Add:

display: inline-block;

to the style of your td.

Webkit based browsers (Google Chrome, Safari, ...) solution

Add:

display: inline-block;
word-break: break-word;

to the style of your td.

Note: Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to the standard.

Opera solution

Add:

display: inline-block;
word-break: break-word;

to the style of your td.

The previous paragraph applies to Opera in a similar way.

2 of 11
98

Word-Break has nothing to do with inline-block.

Make sure you specify width and notice if there are any overriding attributes in parent nodes. Make sure there is not white-space: nowrap.

see this codepen

<html>

<head>
</head>

<body>
  <style scoped>
    .parent {
      width: 100vw;
    }

    p {
      border: 1px dashed black;
      padding: 1em;
      font-size: calc(0.6vw + 0.6em);
      direction: ltr;
      width: 30vw;
      margin:auto;
      text-align:justify;
      word-break: break-word;
      white-space: pre-line;
      overflow-wrap: break-word;
      -ms-word-break: break-word;
      word-break: break-word;
      -ms-hyphens: auto;
      -moz-hyphens: auto;
      -webkit-hyphens: auto;
      hyphens: auto;
    }


    }
  </style>
  <div class="parent">

    <p>
      Note: Mind that, as for now, break-word is not part of the standard specification for webkit; therefore, you might be interested in employing the break-all instead. This alternative value provides a undoubtedly drastic solution; however, it conforms to
      the standard.

    </p>

  </div>

</body>

</html>

🌐
GitHub
github.com › dompdf › dompdf › issues › 2868
word-wrap: break-word not working any longer · Issue #2868 · dompdf/dompdf
May 6, 2022 - In version 0.8.6 the css property "word-wrap: break-word;" on table cells was working as expected (a word is split in a table column with a fixed width): In our tests with dompdf version 1.1.1 and 1.2.1 the property doesn't seem to have any effect, the table column width is growing: Does anyone have a solution for this? The property "word-break: break-word;" is not ...
Author   PDFCoder
Discussions

html - Why doesn't word-wrap work properly in CSS3? - Stack Overflow
BTW: according to this: ... doesn't work in Opera :/ 2012-12-11T11:36:03.88Z+00:00 ... Jukka K. Korpela · Jukka K. Korpela Over a year ago · Breaking a word at an arbitrary point, without even adding a hyphen at the end of a line, is not correct by the rules of pig Latin, not to mention Latin or English. 2013-01-07T08:51:40.277Z+00:00 ... To follow up @JukkaK.Korpela comment (be it many years ago), this is why the hyphens CSS property exists ... More on stackoverflow.com
🌐 stackoverflow.com
html - css word-wrap: break-word won't work - Stack Overflow
To properly break long-words it ... several CSS properties, I would suggest defining and applying helper class like this: .break-long-words { overflow-wrap: break-word; word-wrap: break-word; word-break: break-all; word-break: break-word; hyphens: auto; } ... overflow-wrap and word-wrap are aliases for same thing but some browsers support one and not the other ... More on stackoverflow.com
🌐 stackoverflow.com
April 13, 2024
"overflow-wrap: break-word" not working in table
I'm implementing table inside html, but line break seems not working in items in table. This is CSS table { ... td, th { padding: 5px 15px 5px 15px; word-break: break-all; white-space:nowrap; } and HTML ... ... More on github.com
🌐 github.com
8
November 16, 2017
Please break titles on words, not letters - Meta Stack Overflow
To solve it, you may remove this from Stack Overflow CSS: ... Remove it? But... it's !important. ... I never really understood "!important". I always read it as "not important". ... Reported on Meta.SE: On sites with new responsive theme, word wrap on long titles breaks in the middle of a word. More on meta.stackoverflow.com
🌐 meta.stackoverflow.com
November 16, 2017
🌐
CSS-Tricks
css-tricks.com › almanac › properties › w › word-break
word-break | CSS-Tricks
July 12, 2021 - IE8 introduced -ms-word-break as a synonym for word-break. Don’t use the -ms- prefix. ... Apparently the support in Firefox should be nope, instead of yep. Firefoc 41.0.2 on OSX 10.11 El Capitan does not show a linebreak in your example. Safari and Chrome do. ... Does not work on Firefox on Windows either.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › word-break
word-break - CSS - MDN Web Docs
The specification also lists an additional value, manual, which is not currently supported in any browsers. When implemented, manual will have the same effect as word-break: normal except that breaks won't be automatically inserted in Southeast Asian languages.
🌐
LogRocket
blog.logrocket.com › home › a complete guide to css word-wrap, overflow-wrap, and word-break
A complete guide to CSS word-wrap, overflow-wrap, and word-break - LogRocket Blog
June 4, 2024 - Selecting an element in the DOM tree will display its corresponding CSS styles. You can modify the styles and see the effect on your layout as you track down the source of the bug: As already mentioned, if you have white-space property on an element, set its value to allow wrapping for overflow-wrap: anywhere or overflow-wrap: break-word to work.
🌐
W3Schools
w3schools.com › cssref › css3_pr_word-break.php
CSS word-break property
word-break: normal|break-all|keep-all|break-word|initial|inherit; ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top answer
1 of 6
35

white-space: nowrap will prevent word-break from taking effect. Some templates apply white-space: nowrap which necessitates overriding this attribute with white-space: normal.

2 of 6
22

To properly break long-words it requires to combine several CSS properties, I would suggest defining and applying helper class like this:

.break-long-words {
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-all;
  word-break: break-word;
  hyphens: auto;
}

Properties explained:

  • overflow-wrap and word-wrap are aliases for same thing but some browsers support one and not the other so we need them both. They are offical "correct" way to break words but they don't have any effect on elements with dynamic width so we need more...
  • word-break is originally intended for requiring a particular behaviour with CJK (Chinese, Japanese, and Korean) text but works similar to word-wrap but in WebKit break-all value breaks everything and everywhere. For that reason we must use non-standard and poorly documented WebKit-only break-word value.
  • and optionally, if it makes sense for break words to have hypens (ie. for URLs it probably doesn't) we can use hypens in browsers that support them (at the moment Firefox, Safari, Edge and IE 10+). Also note that in Firefox hypens don't work if you have word-brake property so unless you have fixed-width container you must choose between hypens on FF or legacy support.

Note that I omitted vendor prefixes but if you don't use something like Autoprefixer than this is full verison:

.break-long-words {
  overflow-wrap: break-word;
  word-wrap: break-word;
  -ms-word-break: break-all;
  word-break: break-all;
  word-break: break-word;
  -ms-hyphens: auto;
  -moz-hyphens: auto;
  -webkit-hyphens: auto;
  hyphens: auto;
}
Find elsewhere
🌐
Coder's Block
codersblock.com › blog › deep-dive-into-text-wrapping-and-word-breaking
Deep Dive into Text Wrapping and Word Breaking / Coder's Block
January 22, 2024 - Certain CSS properties and values can be used for additional control over the wrapping of CJK text specifically. Default browser behavior allows words to be broken in CJK text. This means that word-break: normal (the default) and word-break: break-all will give you the same results. However, you can use word-break: keep-all to prevent CJK text from wrapping within words (non-CJK text will be unaffected). Here’s an example in Korean. Note how the word “자랑스럽게” does or doesn’t break.
🌐
GitHub
github.com › Kozea › WeasyPrint › issues › 541
"overflow-wrap: break-word" not working in table · Issue #541 · Kozea/WeasyPrint
November 16, 2017 - I'm implementing table inside html, but line break seems not working in items in table. This is CSS · table { ... td, th { padding: 5px 15px 5px 15px; word-break: break-all; white-space:nowrap; }
Author   kination
🌐
Tailwind CSS
tailwindcss.com › docs › word-break
word-break - Typography - Tailwind CSS
Use the break-normal utility to only add line breaks at normal word break points:
🌐
CSS-Tricks
css-tricks.com › almanac › properties › o › overflow-wrap
overflow-wrap | CSS-Tricks
December 11, 2021 - But others shouldn’t – i.e. long strings of numbers, some special or repeated characters or mix of them, and for them hyphens won’t work (unless you are Safari, then expect unexpected..) I is also true, that overflow-wrap: break-word would break the word in this example, as it will break everything but not necessarily in the same or correct way.
🌐
GitHub
github.com › w3c › csswg-drafts › issues › 1171
[css-text-3] word-break: break-all doesn't break before sentence-ending punctuation if UAX #14 is used · Issue #1171 · w3c/csswg-drafts
August 8, 2017 - word-break: break-all is specified as: Breaking is allowed within “words”: in addition to normal soft wrap opportunities: specifically, any typographic character units resolving to the NU (“numeric”), AL (“alphabetic”), or SA (“Southeast...
Author   littledan
Top answer
1 of 2
5

It seems to work fine:

.txt {
  word-break: break-all;
  word-wrap: break-word;
  min-height:150px;
  max-width:150px;
  overflow-x: auto;
}
<div class="txt">
The company's revenue has been increasing for the last five years with an overall growth of 49% between 2015 and 2019. Revenue increased 7% to $426.4 million for the year ended December 29, 2019, as compared to $398.2 million for the year ended December 30, 2018. The increase was primarily driven by $28.5 million in incremental revenue from an additional 359 operating weeks provided by new restaurants opened during and subsequent to the year ended December 30, 2018 as well as an increase in its comparable restaurant sales. Net income increased by $0.7 million and 12% to $6.2 million for the year ended December 29, 2019 as compared to $5.5 million during the comparable period in 2018. This was due to the increase in depreciation and amortization costs, as well as the increase in income tax benefits. The company's cash equivalents at the end of 2019 totaled $10.1 million, an increase of $2 million from the previous year. Operating activities generated $43.4 million, while investing activities used $33.3 million. Financing activities used another $8.3 million primarily for common stock repurchases and line of credit payments.
</div>

Did you "inspect" your div to see if some other css rule is messing the thing?

When you hit F12 in your browser and then select your div either by clicking on it (1 or 2), you'll see what styles are applied to it in 3.
You'll likely see word-break: break-all; or the same with word-wrap because it is overriden by some other rule.

2 of 2
2

you can do this instead of nesting div into td

.txt {
  word-break: break-all;
  word-wrap: break-word;
  min-height:150px;
  max-width:150px;
}
<table>
  <tr>
    <td class="txt">skdjfhskadjfhsdlkajfhdsakljfhsdakjfhslkadjfhsdalkjfhsadlkjfhsdalkjfhsadlkjfhsdakljfhsdalkjfhsadlkjfhsdalkjfhsladkjfhslakjfhlskadjfh</td>
   <tr>
</table>

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › overflow-wrap
overflow-wrap - CSS - MDN Web Docs - Mozilla
September 28, 2022 - The same as the anywhere value, with normally unbreakable words allowed to be broken at arbitrary points if there are no otherwise acceptable break points in the line, but soft wrap opportunities introduced by the word break are NOT considered when calculating min-content intrinsic sizes.
🌐
Bricks Community Forum
forum.bricksbuilder.io › how to
Word-break in CSS - How To - Bricks Community Forum
January 22, 2024 - Hi there I am trying to add word-break to an element on my page (the tabs title element) but it’s not working. I tried adding a class and doing it in the builder, and it does not work. What am I doing wrong? I need t…
Top answer
1 of 2
4

There are other questions about this subject, for instance this one with many excellent answers, but that amount of info may distract from the basic question, what do the different values to word-break do. So here's an answer to that question and that question only.

If you take this snippet

body {
  max-width: 15em;
  box-shadow: green 0 0 8px;
  word-break: normal;
}
Some short words, somewhatlongerwords and extremelylongwordsthatarereallylong for testing purposes.

With the default value of normal, words are not broken; ordinary word wrap is used and the longest word overflows out of the box. Screenshot:


break-all breaks all words at the end of the line, no matter if they would fit in their entirety on the next line or not.


keep-all is meant for CJK (Chinese, Japanese and Korean) words, which ordinarily don't have spaces between them.
With pure English text, there's no difference to normal.

(If you're interested, this MDN article features an example with Japanese text, where you can see the difference.)


And break-word breaks up those words that don't fit in the box. This is not the same as break-all, which breaks all words regardless.

Now this last one is non-standard, and it doesn't work in all browsers, so if you want this, you should also write overflow-wrap: break-word; in your stylesheet, and for compatibility with older browsers word-wrap: break-word; as well.

There is more to it, but I'll refer you to this question for the reasoning, the history, etc.

2 of 2
-1

Word break - breaks the word to the next line if it exceeds the width. You can check the css works in the browser or not in the below site.

caniuse.com

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Text › Wrapping_breaking_text
Wrapping and breaking text - CSS - MDN Web Docs
A hard break character can be added using ‐ or &#x2010;, and a soft break character can be added using the &shy;, &#173;, or &#xad; HTML character codes. A hard break will always break, even if it is not necessary to do so. A soft break only breaks if breaking is needed. ... .box { inline-size: 150px; overflow-wrap: break-word; hyphens: manual; border: 4px solid #f76707; border-radius: 5px; padding: 10px; }