What is &nbsp in HTML?

In HTML,   represents a non-breaking space entity. This character entity is used within HTML to insert a space where standard consecutive spaces are automatically collapsed by web browsers. The acronym nbsp stands for "non-breaking space."

Purpose of   in HTML

  1. Preventing Automatic Collapsing: HTML typically collapses multiple spaces into a single space when rendered in a web browser. The   entity allows you to add multiple spaces that are not collapsed, which can be particularly useful for formatting purposes.

  2. Preventing Text Wrapping: The non-breaking aspect of   prevents text from wrapping or breaking at the space into a new line. This is useful when you want to keep certain elements together on the same line, such as names, dates, or other groups of words.

How to Use  

Here are a few examples of how   is used in HTML:

Example 1: Adding Multiple Spaces

To add multiple spaces in text:

<p>This is a sentence with multiple&nbsp;&nbsp;&nbsp;&nbsp;spaces.</p>

This will render as:

This is a sentence with multiple    spaces.

The four &nbsp; entities ensure that the spaces are maintained in the browser.

Example 2: Preventing Line Breaks

To prevent a line break between titles and names or between numbers that should not be separated:

<p>Mr.&nbsp;John Smith</p> <p>100&nbsp;kg</p>

This ensures "Mr. John Smith" and "100 kg" do not break across lines.

Comparison with Regular Spaces

  • Regular Spaces: Simple spaces are suitable for standard text separation, but they do not prevent line breaks and are collapsed when there are multiple consecutive spaces.
  • Non-Breaking Spaces (&nbsp;): These are used when you need to maintain whitespace that is not collapsed and to prevent automatic line breaks at the space.

When to Use &nbsp;

  • Tabular Data: In cases where tabular data is being formatted without a table structure, and alignment is crucial.
  • Fine-tuning Text: For subtle adjustments to text layout in headers or titles where breaking or collapsing spaces could disrupt the intended design.
  • Unit Associations: Like "50 kg", "100 mph", to ensure units stay with their values.
  • Menu Items or Navigation: To keep navigation items or menu entries from wrapping.

Considerations

  • Overuse: Excessive use of &nbsp; can lead to issues in responsiveness and readability, especially on smaller screens where space is limited, and you might not want to force no-wraps.
  • Accessibility: Overuse can also lead to accessibility issues for screen readers, as &nbsp; is often read as a word rather than a space, which might confuse the interpretation of content.

Conclusion

The &nbsp; HTML entity is a useful tool for managing whitespace in web content, ensuring that spaces are preserved in ways that standard spaces cannot. However, it should be used judiciously to maintain the clarity and flexibility of web pages across different devices and screen sizes.

TAGS
System Design Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What company owns Cloudflare?
What is non-functional requirements vs system requirements?
What is Edge Computing vs. Cloud Computing?
Why is Netflix so popular?
Which framework OpenAI uses?
Which language is used in distributed systems?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.8
(1,192 learners)
Discounted price for Your Region

$123

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.