×

What is NBSP (Non-Breaking Space)?

NBSP (Non-Breaking Space), also known as Hard space or Fixed space, is an HTML entity used to add blank spaces in the content. NBSP does not allow the browsers to add an automatic line break and separate the content into different lines at the position where it is used.

An HTML entity is characters that are already reserved to write source code and display it in the browser. For example- This “<” is an HTML entity used to represent less than a symbol in HTML.

The blank spaces which are added using nbsp get displayed both on the source code as well as on the browser, unlike blank spaces, which only appear on the source code when added simply by hitting the spacebar.

Using nbsp developers can add multiple blank spaces to the content but doing this may make the source code look very messed up, so instead of using &nbsp, one can use its alternatives which we are going to discuss later in this section.

Why is NBSP used?

When we want to add a space in between our content while typing on the computer, it seems really simple. You just hit the spacebar, and the space appears, but while displaying your content on the browser, you may find that the content is not displayed according to what you actually typed.

Example

<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8" />
    <meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>NBSP</title>
</head>


<body>
    <h1>Lorem ipsum dolor sit amet               consectetur adipisicing elit. Excepturi hic, architecto minima ratione distinctio commodi
    reiciendis asperiores      quod magnam officiis natus ullam quisquam iste. Repudiandae       unde doloremque minus        dolorum
    tenetur?</h1>
</body>


</html>

Output

What is NBSP (Non-Breaking Space)

Also, talking about another scenario, suppose you want two words in your content, say a number, and its unit to remain side by side when it’s being displayed by the browser. But when the content is displayed on smaller devices, for example, mobile or tablets, the browser automatically adds a line break, and it may be possible that the words which you wanted to remain side by side get broken in such a way that the two words appear in separate lines.

Example

<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8" />
    <meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>NBSP</title>
</head>


<body>
    <h1>The car was at a speed of 5 km/hr;</h1>
</body>


</html>

Output

What is NBSP (Non-Breaking Space)

So to avoid this type of scenario, nbsp plays a very vital role where it provides liberty to the developer by allowing them to set the content according to their choice.

How to use NBSP?

NBSP can be mainly used for two purposes that are first, to add multiple blank spaces, and the next one is to prevent automatic line breaks provided by browsers.

Let’s see how nbsp can be used in these two cases separately in the following section.

1) To add multiple blank spaces

First of all, let’s see how your code will look if you try to add blank space without using nbsp.

Example

<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8" />
    <meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>NBSP</title>
</head>


<body>
    <h1>Lorem       ipsum dolor sit amet consectetur adipisicing elit.                     Reprehenderit quibusdam,                                           et hic omnis explicabo ducimus
        in maxime unde </h1>
</body>
</html>

Output

What is NBSP (Non-Breaking Space)

By seeing the output for the source code above, it's clear that the browser ignores the blank spaces added using the spacebar.

Now let’s see how we can display the content exactly in the same way it’s been written in the source code.

To use nbsp, write “&nbsp;” at the position where you want to add a blank space. To add multiple blank spaces, write "&nbsp;" the number of times you want.

Example

<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8" />
    <meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>NBSP</title>
</head>


<body>
    <h1>Lorem&nbsp;&nbsp;&nbsp;&nbsp;ipsum dolor sit amet consectetur&nbsp;&nbsp;adipisicing elit.&nbsp;&nbsp;Reprehenderit quibusdam,&nbsp;&nbsp;et hic omnis explicabo ducimusin maxime&nbsp;&nbsp;&nbsp;&nbsp;unde </h1>
</body>
</html>

Output

What is NBSP (Non-Breaking Space)

Here, the output clearly shows blank spaces that are added using nbsp in the source code.

2) To prevent line break

First of all, let’s see how your code will look when the browser automatically adds a line break when showing the content on the smaller devices.

Source Code

<!DOCTYPE html>
<html lang="en">


<head>
<meta charset="UTF-8" />
<meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NBSP</title>
</head>
<body>
<h1>Keep the goods quantity less because the maximum load it can bear is 1 kg</h1>
</body>
</html>

Output

What is NBSP (Non-Breaking Space)

Here the output shows how the content will be seen on smaller devices where the line break added by the browser makes the two words "1", and "Kg" gets broken in such a way that it gets separated into two lines.

Now let us see how we can prevent this with the help of nbsp.

NBSP is very useful in this type of case as at the position where it is used, it makes sure that the two words have a blank space between them, but they are not displayed on separate lines.

Example

<!DOCTYPE html>
<html lang="en">


<head>
<meta charset="UTF-8" />
<meta HTTP-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NBSP</title>
</head>


<body>
<h1>
Keep the goods quantity less because the maximum load it can bear is 1&nbsp; kg
</h1>
</body>


</html>

Output

What is NBSP (Non-Breaking Space)

Here the output shows the same content being displayed on the much smaller device as mentioned above, but here you can clearly see the difference of using nbsp. Using &nbsp between the two words "1" and "Kg" does not allow the browser to add a line break between them, no matter on which device the content is being displayed.

Where should &nbsp not be used?

NBSP is one of the most used HTML entities used by developers due to its nature.NBSP is very useful for making pages responsive and displaying the content according to how the developer wants it to be seen on different devices. But as everything has some positive as well as some negative aspects so using nbsp for every scenario might not be suitable.

Let’s understand it with an example say you have HTML content and you want to add multiple blank spaces between the words. You might think that nbsp would be the better option to achieve this but think a bit that to add multiple blank spaces to the content, you need to specify several times &nbsp, which would make your code look very messed up, and it would be not easy to read and understand the code for you as well as your team members if you are working on a project as a team.

Also, the screen sizes and screen resolution vary a lot depending from the device to device, so there is a chance that using multiple times &nbsp sometimes might not give you the result that you wanted and can become collapsed in an undesirable way.

 NBSP is meant to keep words together and add a few blank spaces in the content. So it’s a good practice to just use it for such specific purposes only and not make it a habit of using it in order to make pages responsive.

How to create fixed space on my application program?

There are keyboard shortcuts that allow you to create a fixed space on your application program, but using one particular keyboard shortcut will not always work.

Every Operating System and application program has its own keyboard shortcuts to achieve this. According to your operating system and software, you can choose which keyboard shortcut to apply from the below section.

Operating System and Application ProgramKeyboard Shortcut
Microsoft WindowsCtrl + Alt + Spacebar or Ctrl + Spacebar or Alt + 0160 or Alt + 255
macOSOption + Spacebar
Linux or UnixSpace or AltGr + Space
AmigaOSAlt + space
Mac Adobe InDesignOption + Cmd + X
Python‘\N{NO-BREAK SPACE}’
GNU EmacsCtrl + X 8 Space
VimCtrl + K or Shift + N or Shift + S
Microsoft WordCtrl + Shift + Space
LibreOfficeCtrl + Shift + Space
AutoCADCtrl + Shift + Space
DreamweaverCtrl + Shift + Space
FrameMakerCtrl + Space
WordPerfectCtrl + Space

What to use if you want to add multiple blank spaces?

As we have already discussed above that, using &nbsp is not feasible when you want to add multiple blank spaces. So in the following table, we have provided some commonly used HTML entities that you can choose according to the number of spaces you desire to add to your content.

HTML entityNumber of spaces
&nbsp;Use to add only one space
&ensp;Use to add two non-breaking spaces
&emsp;Use to add four non-breaking spaces

Related Topics

What is automation?

Automation means the use of machinery and technologies to make tasks operate automatically and without human involvement. It uses electrical and computer-controlled technologies to replace manual tasks. For example, robots...

6 minutes read.

My computer is running slow, what steps can i do to fix it?

It’s your time to work on your computer, and it just remains hanged, not letting you switch to other programs; in other words, your computer is in a state of...

4 minutes read.

Augmented Reality

Augmented reality, or simply AR, is an alternate or enhanced version of the world we see around us with the help of some technologies. AR is like a new trend...

3 minutes read.

Top 10 Internet tips and tricks

Internet, in a word, can be defined as global networking, which provides world-class facilities for communication and all other things. It is a vast network that connects things all over...

5 minutes read.

Computer: Registers Memory

Registers in Computer The Registers are the type of computer memory, which is used to accept, store quickly, and transfer the data and instructions that are immediately used by the CPU (Control Processing...

5 minutes read.

Computer Cleaning Information and Steps

Clean computing refers to the upkeep of a clean computer, including its hardware and software. According to one estimate, a computer's average age is five and a half years. During that...

9 minutes read.

What is Back Quote?

A back quote, also known as a grave accent or backtick, is a punctuation mark used in various programming languages to denote a literal string or command in the command...

6 minutes read.

What is Back Panel?

The back panel of any computer is where you can attach devices like display, microphone, keyboard, and touchpad. The back panel is on the motherboard's border, as shown in the...

3 minutes read.

What is Optical Disk?

The optical disk is an electronic data storage medium that reads and writes data by using optical storage techniques and technology. There are mostly three types of optical disk available...

9 minutes read.

What is a CSV file?

A plain text file known as a "Comma Separated Values" (CSV) file holds data by separating data items with commas. When data has to be interoperable with a wide range...

5 minutes read.

What is a Silicon Chip?

A silicon chip is a microscopic silicon component found inside computers. It has electronic circuits holding much data or conducting logical or mathematical computations. An integrated circuit comprised mostly of...

4 minutes read.

What is an Icon?

The majority of people nowadays use the word "icon" to refer to a small, selectable or unselectable image that appears on a computer's graphical user interface (GUI) or the web...

3 minutes read.

What is a Punch Card?

Paper cards with holes punched into them to represent computer data and instructions are known as punch cards (or "punched cards"), Hollerith cards, or IBM cards. They were a common...

6 minutes read.

What is Case Badge?

A case badge is a small label or symbol fixed to the outside of a computer case, typically on the front panel that displays the manufacturer's name or logo. Some...

6 minutes read.

What is Operating System?

Operating System An operating system is an interface between a user and computer hardware. The operating system's main aim is to provide a suitable environment to a user so that a...

11 minutes read.

What is a Copyright?

In modern times, copyright is becoming more important because of content thieves, who steal information and uses it for the benefit of money. When the Copyright feature came into existence,...

4 minutes read.

What is a LED Monitor?

An LED monitor, also known as an LED display, is a computer or television with a flat panel and a screen that emits light. The most advanced computer display technology...

5 minutes read.

Generation of Computer

History of computer The abacus was initially used for the mathematical tasks in the history of the computer. It is also known as counting frame and a calculating tool that was used in Europe, China,...

6 minutes read.

What Are Bottom Row Keys?

The bottom row keys, also known as the "home row" keys, are important for several reasons: The bottom row keys are where the fingers rest when not typing and are the...

7 minutes read.

What is AIMBOT?

In shooter games, an AIMBOT is any cheating software or game hack that enables a player to aim automatically and, in some circumstances, auto-shoot (trigger bot). In first-person shooter games,...

4 minutes read.