tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

word-break vs word-wrap

Open franciscolourenco opened this issue 7 years ago • 19 comments

https://next.tailwindcss.com/docs/word-break/#content The word-break utilities documentation says it applies word-break, but its actually applying the word-wrap property.

I'm using v0.7.x

Is this changed in v1 or is it a bug?

franciscolourenco avatar Apr 05 '19 15:04 franciscolourenco

Those docs are correct for v1 and the v0.7.4 docs are correct for v0.7.4, there's a few little differences in this particular module.

v0.7.4:

.break-words {
  word-wrap: break-word;
}

.break-normal {
  word-wrap: normal;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

v1:

.break-normal {
  overflow-wrap: normal;
  word-break: normal;
}

.break-words {
  overflow-wrap: break-word;
}

.break-all {
  word-break: break-all;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

adamwathan avatar Apr 06 '19 20:04 adamwathan

Hi... We're on v2 now but .break-words is defining overflow-wrap: break-word;, however, this appears to have no effect in Chrome in my specific use-case. word-break: break-word; by itself does the trick, though!

Could it be safe to just define both?

unphased avatar Nov 23 '20 22:11 unphased

Hi... We're on v2 now but .break-words is defining overflow-wrap: break-word;, however, this appears to have no effect in Chrome in my specific use-case. word-break: break-word; by itself does the trick, though!

Could it be safe to just define both?

Same here. Take for instance a super long words - which are common for indo-european languages (eg german) - like 'Veranstaltungsinformationsdienst'. Tailwind's '.break-words'-utility won't break it. A custom class with 'word-break: break-word;' will do the job, while also preserving somewhat correct breakpoints that would get lost by using '.break-all'.

Any thoughts on this?

kkukelka avatar Mar 15 '21 11:03 kkukelka

The proposed solution (define both) seems great. Maybe the issue can be reopened?

mgussekloo avatar May 04 '21 10:05 mgussekloo

@adamwathan Any chance to jump back in?

Propaganistas avatar Jun 03 '21 09:06 Propaganistas

Hey! We don't monitor closed issues but if you think this should be revisited totally cool with me to open a new issue with a convincing motivating example 👍🏻

adamwathan avatar Jun 03 '21 12:06 adamwathan

I had a similar problem with this issue, because only word-break: break-word was working for my use case testing in the latest version of Chrome. So I guess both should be defined as mentioned in the past comments from @unphased and @mgussekloo

Why use both properties on .break-normal and not on .break-words?

koganas avatar Jul 09 '21 04:07 koganas

I've come up with an Codepen example where break-words is not enough. It seems to be related to being inside <td> - in that case a word-break: break-word; is needed to get wrapping.

jokull avatar Dec 21 '21 11:12 jokull

@jokull Thank you, I found the same problematic situation where break-words isn't enough and required word-break: break-word when dealing with text inside a table's <td>.

Note that word-break is supposedly deprecated and the correct solution (according to various related issues) is to add min-w-0 to the child of the flex container - though I can't find the right place to put this it seems...

Smerity avatar Jun 24 '22 09:06 Smerity

@Smerity Thanks for linking the relevant issues. For those using grid, adding min-w-0 to children of a grid container will fix the word break issue for text inside the grid child.

qwloh avatar Sep 16 '22 02:09 qwloh

@Smerity Thanks for linking the relevant issues. For those using grid, adding min-w-0 to children of a grid container will fix the word break issue for text inside the grid child.

this saved me an hour

RobSchilderr avatar Sep 22 '22 14:09 RobSchilderr

@Smerity Thanks. After adding min-w-0 to parent div it solve my problem.

ashikjs avatar Dec 17 '22 17:12 ashikjs

It blows my mind how tailwind, even in 2023, doesn't have a class which performs a simple: word-break: break-word;

I had to add it myself...

xyba1337 avatar Mar 30 '23 12:03 xyba1337

@xyba1337 this has been addressed multiple times (https://github.com/tailwindlabs/tailwindcss/issues/10004#issuecomment-1337464731, https://github.com/tailwindlabs/tailwindcss/issues/4340#issuecomment-840557704, https://github.com/tailwindlabs/tailwindcss/issues/3393#issuecomment-769997625). It's because word-break: break-word is deprecated and shouldn't be used.

More info: https://developer.mozilla.org/en-US/docs/Web/CSS/word-break#syntax

RobinMalfait avatar Mar 30 '23 12:03 RobinMalfait

@RobinMalfait, any chance there could be support for overflow-wrap: anywhere?

Based on the documentation from word-break:

Note: While word-break: break-word is deprecated, it has the same effect, when specified, as word-break: normal and overflow-wrap: anywhere — regardless of the actual value of the overflow-wrap property.

This will also help avoid the min-w-0 solution (unfortunately doesn't work for me) that I've seen in a few places.

Alchez avatar Apr 27 '23 10:04 Alchez

I just did some research (https://github.com/unocss/unocss/issues/2614#issue-1708355842) about word-break: break-word, overflow-wrap: anywhere and break-all. I agree overflow-wrap: anywhere should be supported.

@RobinMalfait @adamwathan Hope this issue can be re-open again.

serkodev avatar May 23 '23 20:05 serkodev

https://github.com/tailwindlabs/tailwindcss/discussions/12127 Created a related research and discussion for this issue.

serkodev avatar Oct 03 '23 09:10 serkodev

I also faced this issue today we should add word-break: break-word; for break-words class. Till then had to use min-w-0 workaround.

paramaggarwal avatar Jan 31 '25 10:01 paramaggarwal

There's still really good support for word-break: break-word. This really should be supported by tailwind:

Image

duhaime avatar Feb 18 '25 18:02 duhaime