X

Headline

This is an important message requiring you to make a choice if you're based in the EU.

HTML <nobr> Tag

The <nobr> tag is used to create a text with non-breaking lines. It prevents the text from dividing multiple lines automatically. With the <nobr> tag the text is displayed in a single line, and a horizontal scroll bar appears to make it readable.

Usually, if the text goes outside of the screen, the browser automatically break the text to the next line, but the <nobr> tag does not allow to break the line.

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 closing tag (</nobr>) is required.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <nobr>
      This 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.  
    </nobr>
  </body>
</html>

Result

Let’s take an example where we will use CSS property white-space instead of the <nobr> element.

Example

<!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>

Result

Attributes

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

How to style <nobr> tag

Common properties to alter the visual weight/emphasis/size of text in <nobr> tag:?

  • CSS font-style property sets the style of the font. normal | italic | oblique | initial | inherit
  • CSS font-family property specifies a prioritized list of one or more font family names and/or generic family names for the selected element.
  • CSS font-size property sets the size of the font.
  • CSS font-weight property defines whether the font should be bold or thick. CSS text-transform Property controls text case and capitalization.
  • CSS text-decoration property specifies the decoration added to text, and is a shorthand property for text-decoration-line, text-decoration-color, text-decoration-style

Coloring text in <nobr> tag:

  • CSS color property describes the color of the text content and text decorations
  • CSS background-color property sets the background color of an element.

Text layout styles for <nobr> tag:

  • CSS text-indent property specifies the indentation of the first line in a text block.
  • CSS text-overflow property specifies how overflowed content that is not displayed should be signaled to the user.
  • CSS white-space property specifies how white-space inside an element is handled.
  • CSS word-break property specifies where the lines should be broken.

Other properties worth looking at for <nobr> tag


Browser support



Related Resources

Do you find this helpful?

Related articles