×

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 Keyboard?

In modern times, computer is one of the most important digital technologies for any human being. People will also efficiently correlate these new technologies with the increasing daily-by-day technology. Today’s environment, all...

7 minutes read.

Fourth Generation of Computer

The period of the fourth generation was from 1971- 1980. The (VLSI) huge scale integrated circuits are used in the computers of this generation. These circuits have 5000 transistors and...

4 minutes read.

Binary Subtraction using 2’s Complement

There are a total of four binary operations; binary subtraction is one of them. The binary subtraction is carried out by applying the subtraction procedure to two binary values (numbers...

3 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 RDIMM?

Servers use the RDIMM (registered memory) kind of memory chip most frequently. By reducing the electrical strain on a memory controller, it helps systems running on a server be more...

3 minutes read.

What is Myspace?

Myspace is a social networking platform where users may create web pages, communicate with others, and share content, including music, photos, and blogs. Chat rooms, newsgroups, forums, categorised classified ads,...

7 minutes read.

What is a boot device?

A boot device would be any machinery containing the files required to launch a system. A hard disk, an optical disk drive, a CD - ROMS drive, a Storage device,...

3 minutes read.

What are the disadvantages of the Internet?

Disadvantages of the Internet Every invention has two aspects, good and bad. However, for all its advantages and positive perspectives, every technology has its obscure and nasty side.  Similarly, the Internet...

5 minutes read.

What is an AC Adapter?

An AC adapter is an external power source that changes the direct current (DC) required by an electronic device from the alternating current (AC) supplied by a wall outlet. So,...

4 minutes read.

Uses of Computer

What is the use of computer in our daily life? 10 uses of Computer in Different Fields 1. Education The computer is playing a key role in modern education. In these days, Students...

5 minutes read.

What is a Software Suite?

A software suite is a grouping of computer programs and applications with comparable user interfaces that work together. It is a set of two or more software packages or programs...

3 minutes read.

How to open a Microsoft .wps or Works file in Word

The WPS file format is a legacy one for Microsoft Works. Until 2007, when Office 2010 took its place, Microsoft Works, the company's first office suite, was released. The .wps...

3 minutes read.

What is Multitasking?

Multiple programs can be run simultaneously, thanks to this logical expansion of a multiprogramming system. In a contemporary computer system, the word "multitasking" is employed. The ability to multitask in...

4 minutes read.

What are the currently available antivirus programs?

An antivirus program or software is a kind of software used to detect viruses in the system and protect the computer or network from attacks. Whenever the virus gets into the...

4 minutes read.

What is Windows?

Microsoft created the desktop operating system called Windows. An operating system is a type of software that acts as an interface between the user and the hardware of a computer....

18 minutes read.

What is a Device?

Generally, when we hear this term named "Device", we have a perspective that it may either be some kind of electronic equipment or a machine built to work for a...

3 minutes read.

What is a Dynamic Website?

There are two types of websites. First static and second dynamic website, but before we go for dynamic, we should know about the static website so that you can easily...

4 minutes read.

Parts of Computers Names, Definitions and Images

Computer: A computer is an electronic device, which is made up of using various hardware. The computer processes data, performs calculations, and communicates with other devices and systems. Hardware refers...

14 minutes read.

Features of Multimedia

Multimedia consists of two words. One is "multi", and another is "media". Multi means more than one, and media means medium.  So, we can say that Multimedia is a type of...

3 minutes read.

What is a Dialog Box?

Dialog boxes are a standard computer software element that allows users to interact with the program by entering or selecting information. They often appear as small windows that can be...

5 minutes read.