Skip to main content

HTML Tags

HTML <wbr> Tag

Written by Updated HTML <wbr> Tag exercises

Learn how the HTML <wbr> tag suggests optional line-break positions inside long words, URLs, and identifiers.

The wbr tag marks a place where a long word or URL may break onto the next line, if it needs to. Unlike br, it does not force a line break; it only allows one.

It is useful for long unbroken strings that would otherwise overflow on a phone: URLs, file names, long product codes, or very long words in languages like German.

Syntax

html

<p>HTML5<wbr>AND<wbr>CSS3</p>

It is a void element, with no closing tag, and it has no attributes of its own.

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>WBR Tag Example</title>
  <style>
    .example {
      width: 240px;
      padding: 16px;
      border: 2px solid #29AB87;
      border-radius: 8px;
      font-family: Arial, sans-serif;
      line-height: 1.6;
    }
  </style>
</head>
<body>
  <h1>Optional Word Breaks</h1>

  <div class="example">
    <p>
      Visit
      https://www<wbr>.html5andcss3<wbr>.org/tutorials<wbr>/html
      to learn modern HTML.
    </p>

    <p>
      ThisIsAReallyLong<wbr>ProductName<wbr>ThatCanWrapSafely
    </p>
  </div>
</body>
</html>

Make the preview narrow and the URL and the long product name break only at the <wbr> positions. On a wide screen, nothing changes.

wbr or CSS?

<wbr> gives exact control over where a break may happen. When you do not know the text in advance, for example user names or URLs from a database, CSS is easier: overflow-wrap: anywhere lets the browser break any long string that does not fit. See Text Wrapping.

Good to know

  • No hyphen is added at the break. For words that should get a hyphen, use the soft hyphen entity &shy; instead.
  • In a URL, a good place for <wbr> is before a dot or slash, so the break looks natural.
  • Copying the text gives the original string without any breaks.

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

HTML <wbr> Tag exercises

Allow a break

Write the word superconductivity in a paragraph, and allow the browser to break it between super and conductivity if the line is too short.

Result

Check your answer to see it here.