Add `wrap-anywhere` utility by serkodev · Pull Request #12128 · tailwindlabs/tailwindcss · GitHub
Skip to content

Add wrap-anywhere utility - #12128

Merged
philipp-spiess merged 10 commits into
tailwindlabs:mainfrom
serkodev:feat/break-anywhere
Feb 21, 2025
Merged

philipp-spiess merged 10 commits into
tailwindlabs:mainfrom
serkodev:feat/break-anywhere

Conversation

@serkodev

@serkodev serkodev commented Oct 3, 2023 •

Copy link
Copy Markdown
Contributor

Related discussion #12127

.wrap-anywhere {
  overflow-wrap: anywhere;
}

Updated 2024-11-30

The new changes remove the original @supports because I agree that developers should decide for themselves whether to maintain backward compatibility. Also updated in line with the new changes in the next branch.

@serkodev serkodev changed the title Add break-anywhere utility (#12127) Add break-anywhere utility Oct 3, 2023
@brandonmcconnell

Copy link
Copy Markdown
Contributor

@serkodev

Copy link
Copy Markdown
Contributor Author

@brandonmcconnell For browsers that do not support overflow-wrap: anywhere, it's likely that they will support the older property word-break: break-word given its longevity in the web standards.

Moreover, the @supports (not) query boasts a substantial 97.77% browser coverage. This suggests that the approach should function effectively in the vast majority of browsing environments. So it should serve as a progressive enhancement, ensuring a seamless experience for users across different browsers.

@jonathanlal

Copy link
Copy Markdown

this is much needed

@RobinMalfait
RobinMalfait changed the base branch from master to archive/master-2024-02-23 March 4, 2024 21:45
@silverwind

Copy link
Copy Markdown
Contributor

Imho it shouldn't use @supports for the sake of keeping it lightweight and because @supports is known to have obscure bugs. Users should be aware of the browsers they support and if the prop is not supported, I would see it as graceful degradation.

@yuheiy

yuheiy commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

There are subtle differences between the behavior of word-break: break-word and overflow-wrap: anywhere, so they should not be included in the same utility class. If the users want to progressively enhance, it should be the user’s responsibility.

Tailwind states the following regarding browser support:

Tailwind CSS v3.0 is primarily designed and tested with the latest stable versions of Chrome, Firefox, Edge, and Safari, and does not support any version of Internet Explorer, including IE 11.

While the majority of Tailwind CSS features are compatible with all modern browsers, the framework also incorporates APIs for several advanced features not yet universally supported, such as the :focus-visible pseudo-class and backdrop-filter utilities.

Given that Tailwind is a foundational framework, users can easily avoid using unsupported features by simply not utilizing the corresponding utility or modifier, similar to how one would refrain from using specific CSS features in their own stylesheets.

https://tailwindcss.com/docs/browser-support

For example, the support rate for text wrap utilities is lower, but this is not a problem. Whether or not to use those properties should be left to the user’s discretion.

@silverwind

Copy link
Copy Markdown
Contributor

There are subtle differences between the behavior of word-break: break-word and overflow-wrap: anywhere, so they should not be included in the same utility class. If the users want to progressively enhance, it should be the user’s responsibility.

I agree and think this should just be .break-anywhere { overflow-wrap: anywhere }, let the user deal with the subtle differences and browser support instead of trying to be smart.

@liesahead

liesahead commented Jul 12, 2024 •

Copy link
Copy Markdown

Still very much needed.. It wouldn't be a problem if it was possible to redefine word break classes through tailwind config.

@silverwind

silverwind commented Jul 12, 2024 •

Copy link
Copy Markdown
Contributor

Meanwhile, you can define a plugin in your config to add this. Here in the simplest variant:

import plugin from 'tailwindcss/plugin.js';

plugins: [
  plugin(({addUtilities}) => {
    addUtilities({
      '.break-anywhere': {
        'overflow-wrap': 'anywhere',
      },
    });
  }),
],

@sadeghi-aa

Copy link
Copy Markdown

Hi. Is there any update on this PR? I need the word-break: break-word; functionality. I did some research and found out that I can also use word-break: normal; in combination with overflow: anywhere; but the latter also doesn't exist in TailwindCSS. Does anyone have a solution for this issue?

@shrall

shrall commented Aug 27, 2024

Copy link
Copy Markdown

Hi. Is there any update on this PR? I need the word-break: break-word; functionality. I did some research and found out that I can also use word-break: normal; in combination with overflow: anywhere; but the latter also doesn't exist in TailwindCSS. Does anyone have a solution for this issue?

adding in a custom class just like @silverwind 's comment should work for now

@brandonmcconnell

Copy link
Copy Markdown
Contributor

@sadeghi-aa You could also use an arbitrary utility in the meantime, like [word-break:break-word]

@404missinglink

Copy link
Copy Markdown

Any update on merging this with base tailwind? Just went down such a huge rabbit hole since I didn't know break-word was deprecated and my iPhone users were complaining.

@sepehr-safari

Copy link
Copy Markdown

ship it!

@danielraab

Copy link
Copy Markdown

Why this pull request is into tailwindlabs:archive/master-2024-02-23 ?

@serkodev

Copy link
Copy Markdown
Contributor Author

@danielraab the old master branch renamed by the maintainers

@serkodev
serkodev force-pushed the feat/break-anywhere branch from e02d323 to 13d7eef Compare November 30, 2024 13:07
@serkodev
serkodev changed the base branch from archive/master-2024-02-23 to next November 30, 2024 13:07
@serkodev
serkodev requested a review from a team as a code owner November 30, 2024 13:07
@francislavoie

francislavoie commented Dec 3, 2024 •

Copy link
Copy Markdown

I'd love to see this land for v4. This is the only usage of utilities we have in our project, so it would let us clean up at the same time as upgrading, instead of having to use the new @utilities in v4.

We're doing this as a workaround for now:

  plugins: [
    plugin(({addUtilities}) => {
      addUtilities({
        '.break-anywhere': {
          'overflow-wrap': 'anywhere',
        },
      });
    }),
  ],

@adamwathan

Copy link
Copy Markdown
Contributor

Hey folks! We're not going to add anything new to v3 now that v4 is out so going to close this one, but definitely open to tackling this in v4 if someone wants to open a new PR at some point. Sorry for the lack of discussion here, hard to make time to think through these small additions sometimes when there are other bigger things going on.

@adamwathan adamwathan closed this Jan 28, 2025
@adamwathan adamwathan reopened this Jan 28, 2025
@adamwathan

Copy link
Copy Markdown
Contributor

Ignore me, didn't realize this had been updated for v4 🙈 will try to make time to make a decision about the exact API here soon!

@adamwathan adamwathan added the v4 label Jan 28, 2025
@philipp-spiess philipp-spiess changed the title Add break-anywhere utility Add wrap-anywhere utility Feb 21, 2025
@philipp-spiess

Copy link
Copy Markdown
Contributor

@philipp-spiess
philipp-spiess merged commit 62d3e74 into tailwindlabs:main Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.