Skip to content

HTML <nobr> Tag

The <nobr> tag prevents text from wrapping to multiple lines. It keeps the content on a single line. Because the text cannot wrap, a horizontal scrollbar may appear if the container is too narrow to display the full line.

Usually, when text exceeds the width of its container, the browser automatically breaks it to the next line. The <nobr> tag prevents this automatic line breaking.

DANGER

The <nobr> is a non-standard element. Although it may still work in some browsers, its use is discouraged since it can be removed at any time. Use the CSS white-space property instead.

Syntax

The <nobr> tag comes in pairs. The content is written between the opening (<nobr>) and closing (</nobr>) tags.

Example of the HTML <nobr> tag:

An ordinary and very long text in one line | Example of the HTML <nobr> tag

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <nobr>
     Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
    </nobr>
  </body>
</html>

Result

nobr example

You can use the CSS white-space property instead of the <nobr> element and achieve the same result.

Example of the CSS white-space property instead of the <nobr> tag:

Example of using the CSS property white-space with the HTML <nobr> tag|W3Docs

html
<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      p.a {
        white-space: nowrap;
      }
    </style>
  </head>
  <body>
    <h1>Example of using the CSS property white-space</h1>
    <p class="a">
      It is an ordinary and very long text that is very inconvenient to read, as it is written in one line, and you have to scroll horizontally to read it.
    </p>
  </body>
</html>

Attributes

The <nobr> tag supports the Global Attributes and the Event Attributes.

How to use global attributes with the HTML <nobr> tag

html
<nobr id="my-text" class="highlight">
  This text will stay on one line and can be targeted or styled using global attributes.
</nobr>

Practice

What is the function of the 'nobr' tag in HTML?

Do you find this helpful?

Dual-run preview — compare with live Symfony routes.