HTML wbr Tag

HTML wbr Tag

HTML <wbr> Tag: Word Break Opportunity

The <wbr> (Word Break Opportunity) tag in HTML is used to suggest a possible line break in long words or URLs when needed, without forcing a break. If the word fits within the container, the browser will not break it. However, if necessary (e.g., due to small screen sizes or container constraints), the word will break at the <wbr> position.

1. Syntax

<p>Visit our website: www.example<wbr>.com for more details.</p>
  • If the browser window is wide enough, it will display "www.example.com" as a single word.

  • If the text overflows the container, the browser may break the word at wbr>, displaying:

    www.example .com

2. When to Use <wbr>

  • Long Words: To prevent horizontal scrolling by allowing breaks in long words.

  • URLs: Helps break long URLs neatly.

  • Code Snippets: To improve readability in code samples.

3. Examples

Example 1: Breaking a Long Word

<p>This is an example of a very<wbr>longwordthatdoesnotfit.</p>

✅ If space is limited, the word "verylongwordthatdoesnotfit" will break at very- and continue on the next line.

Example 2: Breaking a Long URL

<p>Download from: https://www.<wbr>longdomainname<wbr>.com/download</p>

✅ If the URL is too long, it will break at "longdomainname.com" instead of causing horizontal scrolling.

Example 3: Breaking Code Snippets

<p>To install, use: npm<wbr>install<wbr>-g<wbr>package-name</p>

✅ Ensures the command is readable without breaking in awkward places.

4. <wbr> vs Other Line Break Options

MethodUse CaseExample
<wbr>Suggests a break in long words, but only if neededsuper<wbr>longword
&shy; (soft hyphen)Suggests a break and displays a hyphen (-) when brokensuper&shy;longwordsuper- longword
<br>Forces a break at that pointsuper<br>longword
word-wrap: break-word; (CSS)Breaks entire words if neededUsed in CSS for text wrapping

5. Conclusion

  • The <wbr> tag does not force a break but allows one when needed.

  • Useful for responsive design to prevent layout issues.

  • Works well with long words, URLs, and code snippets.

Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close