Overview
HTML <nobr> Tag
The <nobr> element tried to keep its text on a single line — the browser would not wrap at spaces inside it, which can force horizontal scrolling.
Learn it only to recognize legacy pages. For every new project, use CSS white-space: nowrap on a <span> (or other element) instead.
Deprecated / Non-standard.Do not use <nobr> in new HTML. It was never standard HTML. Prefer white-space: nowrap.
CSS replacement.<span class="nobreak">…</span> with .nobreak { white-space: nowrap; } is the clear, conforming approach.
Syntax
HTML Syntax
Both tags were used historically. Modern equivalent: <span style="…"> is fine for demos; prefer a class + white-space: nowrap in real stylesheets.
Reference
Attributes
<nobr> has no element-specific attributes. Prefer CSS instead of the tag:
| Attribute / approach | Description | Try it |
|---|
| (none specific) | Legacy tag only — no tag-only attributes | Try it |
class + CSS | Correct today — white-space: nowrap on a class | Try it |
<wbr> | Opposite idea: mark a preferred break opportunity inside long text | Try it |
Also supported
Global Attributes
The <nobr> tag also supports the Global Attributes in HTML (legacy recognition only — do not ship new markup).
Try it
Live Preview
Toggle white-space: nowrap (the modern replacement) inside a narrow box.
Code
HTML Examples
Short, copy-ready snippets. Prefer the CSS examples. Use Try It Yourself for a live editor.
Example 1 — Legacy <nobr> (Study Only)
Historical markup. Prefer CSS in new work even if a browser still renders this.
<!-- Deprecated / non-standard — do not use in new pages -->
<p>
<nobr>This long phrase should stay on one line.</nobr>
</p>
This long phrase should stay on one line.
How It Works
- Wrap the phrase in
<nobr>…</nobr> (legacy only). - Browser intent: avoid wrapping at spaces inside the element.
- Side effect: narrow viewports may need horizontal scroll.
- Replace with CSS when you update the page.
Example 2 — CSS white-space: nowrap
The recommended replacement for <nobr>.
<p class="nobreak">
This long phrase should stay on one line.
</p>
<!-- In CSS: .nobreak { white-space: nowrap; } -->
This long phrase should stay on one line.
How It Works
- Keep semantic HTML (a
<p> or <span>). - Add a class such as
nobreak. - Set
white-space: nowrap in CSS. - Test overflow on small screens before shipping.
Example 3 — Prefer Breaks with <wbr>
When text is long but may wrap, mark a soft break — the opposite of forbidding wraps.
<p>
https://example.com/docs/<wbr>guides/<wbr>html/nobr
</p>
https://example.com/docs/guides/html/nobr
How It Works
- Do not use
nobr when you want controlled wrapping. - Insert
<wbr> where a break is acceptable. - Browser wraps there only if the line would otherwise overflow.
- Pair with CSS (
overflow-wrap, etc.) when URLs or codes still spill.
Watch out
Edge Cases & Pitfalls
standardsNever standard HTML
Wide support does not make <nobr> conforming. Validators flag it; use CSS.
mobileHorizontal overflow
Long nowrap phrases can break layouts on phones. Reserve nowrap for short strings.
a11yZoom and reflow
Users who enlarge text need wrapping. Forced one-line text can become hard to read.
contrastnobr vs wbr
One forbids breaks; the other suggests them. Pick based on whether wrapping helps.
nbsp is different
A non-breaking space glues two words. nowrap keeps a whole run on one line.
prePreformatted text
For code blocks, prefer <pre> / white-space variants over nobr.
Compatibility
Browser Support
The <nobr> element is non-standard / deprecated HTML. It is not recommended for authors and is not a Node.js, Deno, or Bun API.
✓ Deprecated · Use CSS
<nobr>
Never standard HTML. Many browsers still render it for legacy pages, but authors should use white-space: nowrap instead.
0% Authoring use (new pages)
Google Chrome Legacy render
Deprecated
Mozilla Firefox Legacy render
Deprecated
Apple Safari Legacy render
Deprecated
Microsoft Edge Legacy render
Deprecated
Opera Legacy render
Deprecated
Samsung Internet Legacy render
Deprecated
Internet Explorer Legacy
Deprecated<nobr> Do not use
Bottom line: Recognize it in old documents; ship white-space: nowrap for new UI. Prefer wbr when soft breaks help.
Remember
Key Takeaways
Fact: <nobr> is deprecated and was never standard HTML.
Replace: white-space: nowrap on a normal element.
Contrast: use <wbr> when a soft break is better than no break.
Practice: avoid forcing long one-line text on mobile.
One line: skip <nobr> — use CSS white-space: nowrap when you truly need a single line.
UA style
Default CSS Settings
Engines that still recognize <nobr> typically treat it like nowrap text. Approximate idea:
/* legacy mapping idea — do not rely on the tag */
nobr {
white-space: nowrap;
}
/* preferred author CSS */
.nobreak {
white-space: nowrap;
}
Author with the class form so your HTML stays standard even if the UA rule for nobr changes.
Frequently Asked Questions
nobr kept its text on one line so the browser would not wrap at spaces. Users might need to scroll horizontally to read long phrases.
No. It was never standard HTML and is deprecated / obsolete. Do not use it in new pages.
Use CSS white-space: nowrap on a span or other element. That is the MDN-recommended replacement.
nobr tried to forbid wrapping. wbr marks a preferred opportunity to break a long word or string when needed.
Many engines still render it for legacy pages, but that is not a reason to use it. Prefer CSS so your markup stays conforming.
Yes. Long nowrap text can force horizontal overflow. Use it sparingly (short labels, codes) and test narrow viewports.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
10 people found this page helpful