HTML // Forgotten_Tag_<wbr>
We build complex React applications but often forget the basics. Meet <wbr> — the native HTML tag that fixes your responsive typography.
We spend hours configuring Webpack, debating SSR vs. CSR, and learning new frameworks. Yet, sometimes the best solution to a modern UI problem is a dusty HTML tag from the 90s that everyone forgot about.
I’m talking about the tag you see right in the title of this post: the Word Break Opportunity.
The problem: long technical strings
If you are building a dev blog, a documentation site, or a dashboard, you deal with long strings without spaces. CamelCase variables, database IDs, or file paths.
On mobile, these strings destroy your layout. They either overflow the screen or get cut off harshly.
Meet the Candidate: <wbr>
Unlike the aggressive <br /> (which forces a new line no matter what) or the grammatical ­ (which adds a hyphen), <wbr /> is polite.
It tells the browser: “This is a single word, but IF you run out of space, you can safely break the line right here. Otherwise, keep it together.”
But to truly appreciate it, we need to see the struggle. Let’s simulate a developer trying to fix a broken technical title on a mobile screen, iterating from a “panic fix” to the ultimate solution.
<span class="truncate"> Frontend_Patterns_For_Modern_Web </span>
<span class="break-all"> Frontend_Patterns_For_Modern_Web </span>
<span> Frontend_<wbr />Patterns_<wbr />For_<wbr />Modern_<wbr />Web </span>
<span class="inline-block text-pretty break-words">
Frontend_<wbr />Patterns_<wbr />For_<wbr />Modern_<wbr />Web
</span>! Dead end :: the zero width space (
\u200B)You might be tempted to solve this by injecting the invisible “Zero Width Space” character via JavaScript. Do not do this.
- Layout Glitches: Browsers treat it as a standard space with zero width. They often prioritize breaking at these points prematurely, ruining the flow of multi-word titles compared to the smarter
<wbr>.- Copy-Paste Poison: This is the dealbreaker for tech blogs. If a user copies your title and pastes it into a Terminal or VS Code, the invisible character is pasted too. It causes mysterious syntax errors that are impossible to debug.
Unlike this hack,
<wbr>is purely structural—it vanishes when copied to the clipboard.
Level up: the Tailwind combo
The <wbr> tag handles the logic of breaking. But to make it look truly professional, we need to handle the aesthetics of the surrounding text.
Enter text-wrap: pretty.
This is a newer CSS feature (available in Tailwind as text-pretty). It prevents “orphans” — single words left alone on a new line. It calculates the line balance to ensure the text block looks solid.
The Ultimate Strategy:
- Use
<wbr>to mark logical break points (e.g., after underscores). - Use
text-prettyto balance the lines. - Use
break-wordsas a failsafe.
Real-world implementation
You don’t want to manually type <wbr /> into every heading. Let’s create a parser that automatically injects these “soft breaks” after every underscore in your technical titles.
Here is the logic I use for the titles on this very blog:
// The Goal: Inject <wbr> after every underscore
// Input: "My_Long_Component_Name"
const SmartTitle = ({ text: string }) => {
return (
<span className="inline-block text-pretty break-words">
{text.split("_").map((segment, index, array) => (
<Fragment key={index}>
{segment}
{/* Add underscore & wbr if not the last segment */}
{index < array.length - 1 && (
<>
_<wbr />
</>
)}
</Fragment>
))}
</span>
);
};Why this matters
It creates a “Fluid UI”. Your technical terms look solid on a 4K monitor (Frontend_Patterns_For_Modern_Web) but gracefully adapt on an iPhone SE (Frontend_Patterns_ + new line + For_Modern_Web), without adding ugly hyphens or breaking in the middle of a letter.
Native HTML. Zero dependencies. Infinite responsiveness.
System :: Discovery log
You have just rediscovered a piece of ancient internet history. The
<wbr>tag has been in the HTML spec forever, waiting for this moment.If you learned something new, execute the
ack_sequence below.