×

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 a Ring Topology?

The word topology defines the relationship or arrangement of its component elements. A ring network is an architecture of a network where each node is connected to precisely two other...

4 minutes read.

How to find out how much hard drive space is available?

A certain kind of non-volatile data storage device is a hard disc (called a hard drive, HD, or HDD). It is frequently installed inside a computer and attached directly to...

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.

Why can’t I open any web pages when connected to the internet

You can follow the instructions below if you are able to connect to the Internet, you are unable to access any websites. Ping an Internet Address You need to open the Command...

4 minutes read.

What is an Online Service?

An entity that offers online access to various types of data for diverse purposes is known as an online service. Online banking, education, news, shopping, dating, computer support websites, social networking...

3 minutes read.

What is a Header?

A document or data packet's header is a section that contains metadata or other information required for processing the main material. In information technology, "supplemental data" is frequently used to describe...

3 minutes read.

What Hardware Device Drivers should be Updated?

Our recommended hardware for updates is shown below. Driver and other component updates for your computer can resolve problems, improve functionality, and boost stability. How Frequently Should Your Drivers Be Updated? Consider...

6 minutes read.

Difference between Website and Webpage

Website A website is a collection of attached web pages, typically supplied from a single web domain, accessible via the Internet. A website is hosted on a computer system known as...

6 minutes read.

What is Hard Disk Drive (HDD)?

HDD is an electro-mechanical device that enables the user to store data for future use. The device has magnetic storage that is responsible for storing the information. And, this stored...

7 minutes read.

Difference between hardware and software

Computer Hardware Hardware refers to the actual parts of a PC or a machine that we can see and contact. An actual part is utilized in various ways to assemble a...

3 minutes read.

What is a Memory Slot?

The memory slot, often known as a RAM slot, is what enables computer memory chips or sticks to be inserted in computer. It helps in determining the type of RAM to be used...

11 minutes read.

What are the Disadvantages of Computers?

Although there are various advantages to using a computer, there are also hazards and disadvantages (like most things in life). Computers, if not used properly, can create a variety of...

6 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 is network Interface card (NIC)?

A network interface card is a hardware part of a computer, which is used to connect the internet in the system. The latest network interface card gives functionality to the...

6 minutes read.

Why my computer monitor shows no display or black screen

Often, people face the problem of getting a blank screen or no display on their computer monitor. There might be multiple causes to this, but it all lies around the...

6 minutes read.

What is Modem?

A modem is a device that is responsible for modulating and demodulating the signals in a computer network. The modem is an abbreviation for Modulator - Demodulator. It allows the...

7 minutes read.

What is Account Sharing?

Account sharing is the way of allowing multiple people to use a same account by sharing their username and password with others. For instance, to avoid having to pay for...

7 minutes read.

What are Toggle keys?

keys that are used to turn on or off a function or the keys used to switch between two functions is called the Toggle key. The caps lock key, scroll...

3 minutes read.

How to installation or uninstallation Microsoft Paint

Instead of Microsoft Paint, we can also call it MS paint. Sometimes, it is also known as Paint. Dan McCabe programmed the first version of Microsoft Paint and also introduced...

3 minutes read.

What is a Program

A program can be defined as an application used to perform a specific function. It constitutes stepwise instructions to perform a dedicated task. Multiple programs working together can form a...

4 minutes read.