HTML NBSP

HTML   is an HTML entity for non-breaking space. It prevents two words from being rendered at different lines. For example,

<p>
    The World population as of 2022 has reached 7.837&nbsp;billion.
</p>

Browser Output

HTML nbsp

Here, 7.837 and billion will render on the same line on all screen sizes.


Example of &NBSP;

We use &nbsp; when we need two words together without breaking the line. For example,

<p style="font-size: 30px">
     The World population as of 2022 has reached 7.837 billion.
</p>

Browser Output


In the above example, we can see that 7.837 and billion are displayed on separate lines.

However, to display 7.837 and billion without line break regardless of the screen size, we use &nbsp. For example,

<p style="font-size: 30px">
     The World population as of 2022 has reached 7.837&nbsp;billion.
</p>

Browser Output

HTML nbsp

Here, you can see, even on the same screen size, 7.837 and billion now stick together.


&nbsp for extra space

In HTML, multiple consecutive space characters are not treated as multiple spaces. Instead, they are treated as a single space. . For example

<p >This is a long                        paragraph.<p>

Browser Output

HTML nbsp

So, to add more than one space, we can use the &nbsp; entity. For example,

<p >This is a long &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paragraph.</p>

Browser Output

HTML nbsp

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges