Skip to main content

HTML <wbr> Tag

As a web developer, you may have encountered situations where you want to control the line breaking of certain words or phrases within your HTML content. This is where the <wbr> tag comes in handy.

The <wbr> tag is an inline element that can be placed within a block of text to indicate a potential line break opportunity. This means that the browser may choose to wrap the text to the next line at the position of the <wbr> tag, depending on the available space and other line-breaking rules.

Here's an example of how you can use the <wbr> tag in your HTML code:

<p>
    With CSS, you can change the color, font, and layout <wbr>of your HTML elements.
</p>

In this example, the <wbr> tag is placed between "layout" and "of" in the sentence. If the available space on the line is not enough to fit the entire sentence, the browser may choose to break the line at the position of the <wbr> tag, resulting in the following output:

With CSS, you can change the color, font, and layout
of your HTML elements.

Note that the <wbr> tag does not guarantee that a line break will occur at its position. It simply provides a hint to the browser that a line break may be appropriate. The actual line breaking is still determined by the browser's line-breaking rules and the available space.

You can also use the <wbr> tag to prevent line breaking at certain points in your text. For example:

<p>This is a very long URL: http://www.example.com/very/long/path/to/a/resource.html. <wbr> You should not break this URL.</p>

In this case, the <wbr> tag is placed within the URL to prevent the browser from breaking the line in the middle of the URL. This can be useful to preserve the integrity of long URLs or other complex strings of text that should not be broken up.