What is the WBR HTML5 Tag, & How Do You Use It?

2 min read

The <wbr> HTML element is an invisible line break that does not affect the layout of the content but allows browsers to insert a line break if needed due to space constraints. It’s useful for creating multiline input fields or preserving certain elements of a web page in case it has to be displayed on smaller screens.

Here’s an example of how you can use <wbr>:

<p>Please enter your name: <input type="text" id="name" value="" size="10"><wbr></p>

In this example, the input field has a width of 10 characters. If the user enters more than 10 characters, the browser will automatically insert line breaks to prevent any overflow.

The <wbr> tag has one attribute:

  • clear – This sets whether the break should clear all floating elements before it or not. The possible values for this attribute are “left”, “right” and “none”.

Here’s an example of how you can use the clear attribute:

<p>Please enter your name: <input type="text" id="name" value="" size="10"><wbr clear="left"></p>

In this example, if a line break is inserted before the input field due to space constraints, it will clear all floating elements on its left side.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Carlos Baez

Subscribe now to keep reading and get access to the full archive.

Continue Reading