In HTML, the non-breaking space character, represented by  , is used to insert a space between elements or within text content that prevents the browser from merging consecutive spaces into a single space. This can be particularly useful for maintaining spacing or formatting in situations where regular spaces might be ignored.
Add Non-breaking Spaces in HTML with
- The browser displays only one blank space even if we put hundreds of spaces in our code, HTML has the character entity. Using it one can display multiple blank spaces.
- By inserting between words or elements, you can prevent line breaks from occurring at specific points, ensuring that certain content stays together on the same line.
- This is particularly useful for maintaining formatting in situations where line breaks could disrupt the layout.
- In some cases, is used as a placeholder within HTML elements that cannot have content, such as <td> elements in tables or <button> elements. This ensures that these elements are not collapsed or ignored by the browser.
Example: The example below shows how to Add a Non-breaking Space with the  .
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>
</head>
<body>
<p>This is a non-breaking space example.</p>
<p>This is a non-breaking space example.</p>
<p>
Non-breaking space can be used
to maintain spacing between words
or elements.
</p>
<p>
This is a
line with multiple
non-breaking spaces.
</p>
</body>
</html>
Output:
Recommended Articles
3. HTML nbsp