Trusted answers to developer questions

How to add a space in HTML

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

svg viewer

HTML Entities

Some characters are reserved for coding in HTML (ex: <, >, "). If these characters are to be included in your text, it can’t be written like the rest of it. HTML Entities allow us to add the characters reserved for coding HTML into our text. To add an HTML Entity, you need to write a & followed by the characters code.

For example, to add a less than sign (<), you can write &lt or &#60. Here lt is the Entity Name and #60 is the Entity Number.

CAUTION: Entity names are case sensitive.

Similarly, there is an Entity to add extra space: &npsp (non-breaking space) or &#160.

Adding an extra space in HTML

Look at the sentence below:

No matter how many physical spaces we add, HTML always renders it as a single space.

There are two ways to add an extra space :

  1. Use the HTML Entity &nbsp/&#160.
  2. Use the preformatted tag <pre>. As the name implies, the text is displayed as it is coded.

NOTE: The <pre> tag displays text with a fixed-width font (usually Courier).

RELATED TAGS

html
blank space
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?