0
0
HtmlConceptBeginner · 3 min read

What is &nbsp in HTML: Explanation and Usage

  in HTML stands for a non-breaking space, which is a space character that prevents line breaks at its position. It is used to keep words or elements together on the same line instead of letting the browser break them apart.
⚙️

How It Works

Think of   as a special kind of space that acts like glue between words or elements. Normally, browsers break lines wherever there is a regular space to fit content nicely. But when you use  , it tells the browser, "Don't break the line here." This keeps the connected words or items on the same line, just like holding hands so they don’t separate.

This is useful when you want to keep things like a person's first and last name, or a number and its unit, together without splitting them across lines. It works behind the scenes as a space character but with the extra rule of no line break allowed.

💻

Example

This example shows normal spaces versus non-breaking spaces. Notice how the non-breaking space keeps the words together on the same line.

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Non-breaking Space Example</title>
  <style>
    body { max-width: 300px; font-family: Arial, sans-serif; }
  </style>
</head>
<body>
  <p>Normal space: This is a test of line breaking.</p>
  <p>Non-breaking space: This&nbsp;is&nbsp;a&nbsp;test&nbsp;of&nbsp;line&nbsp;breaking.</p>
</body>
</html>
Output
Normal space: This is a test of line breaking. Non-breaking space: This is a test of line breaking.
🎯

When to Use

Use   when you want to keep certain words or numbers together on the same line to improve readability. For example, keep a person's full name, dates, or measurements like "100 km" from splitting across lines.

It is also helpful in formatting things like phone numbers, addresses, or any text where breaking the line would confuse the reader or look untidy.

Key Points

  •   creates a space that prevents line breaks.
  • It helps keep related words or numbers together.
  • It improves text readability and layout control.
  • Use it sparingly to avoid awkward spacing.

Key Takeaways

  is a non-breaking space that stops line breaks at its position.
It keeps words or elements together on the same line for better readability.
Use it to prevent splitting names, dates, measurements, or important text.
It looks like a normal space but acts like glue between words.
Avoid overusing it to keep your text natural and easy to read.