HTML normally collapses consecutive spaces, tabs and source line breaks into a single displayed space. If spacing is only visual, use CSS. Use when you specifically need a non-breaking space that keeps adjacent content together.
<p>Link1 Link2 Link3</p>
<p>Link1 Link2</p>
The first line uses an ordinary space. The second uses a non-breaking space between Link1 and Link2, so the browser avoids breaking the line at that position.
. Use CSS margin, padding, gap or an appropriate layout system instead.In normal HTML text, runs of spaces and other collapsible whitespace are displayed as one space. Adding more spaces in the source therefore does not reliably create a larger visual gap.
<p>Link1 Link2 Link3</p>
The browser normally renders the gaps above as single spaces. This behavior keeps ordinary text formatting independent from source-code indentation.
represents a non-breaking space. It is useful when two pieces of content should stay together on the same line, such as a number and unit or a short label and value.
<p>20 km</p>
<p>₹500 only</p>
You can, and older HTML pages often do this, but repeated non-breaking spaces are usually the wrong tool for layout. The spacing becomes tied to text characters instead of the page layout.
<p>Link1 Link2</p>
For visual separation between links, controls or blocks, prefer CSS.
CSS gives predictable control over visual spacing. Use margin for space outside an element, padding for space inside an element and gap for spacing between flex or grid items.
<span style="padding-left: 20px;">This text starts 20px from the left.</span>
<div style="margin-left: 20px;">
Indented block-level element.
</div>
<nav style="display: flex; gap: 1rem;">
<a href="#one">Link 1</a>
<a href="#two">Link 2</a>
<a href="#three">Link 3</a>
</nav>
For a navigation menu, gap is generally clearer than inserting spaces or separator characters only to push links apart.
If the goal is paragraph indentation rather than generic spacing, use CSS text-indent.
<p style="text-indent: 4em;">
This paragraph begins with a first-line indent.
</p>
text-indent affects the first line of the block. It is not a replacement for margin or padding when the entire element needs to move.
When whitespace itself is meaningful, use the <pre> element. It preserves sequences of spaces and line breaks rather than collapsing them like ordinary HTML text.
<pre>
Name Score
Asha 92
Ravi 88
</pre>
Do not use <pre> merely to position page elements. Use semantic tables, lists or CSS layout when those better describe the content.
The <br> element creates a line break within text. It is appropriate when the line break is part of the content, such as an address or poem.
<p>12 Example Street<br>
Hyderabad<br>
India</p>
Do not add repeated <br> elements just to create vertical page spacing. Use CSS margin or padding for that.
Older web pages sometimes created horizontal gaps by stretching a transparent one-pixel image:
Word 1 <img src="dot.gif" height="1" width="20" alt=""> Word 2
Use non-breaking spaces because the content must not wrap there, not because you need an arbitrary visual gap.
Normal HTML collapses them. Use CSS when the desired result is visual spacing.
Line breaks are content, not a layout system. Use CSS margin or padding between blocks.
If the content is a real table or list, use the corresponding semantic HTML element instead of spaces.
This historical technique is unnecessary in modern HTML/CSS and makes responsive layouts harder to maintain.
Normal HTML text collapses consecutive spaces, tabs and line breaks into a single displayed space.
It represents a non-breaking space, which creates a space where the browser does not normally break the line.
No. Use CSS margin, padding, gap or an appropriate layout system for visual spacing.
Use the pre element when the whitespace is part of the content, or use an appropriate CSS white-space rule for a specific design requirement.
No. Use br when a line break is meaningful within the content; use CSS margin or padding for layout spacing.
No. Spacer images are a legacy layout technique. Modern pages should use CSS for spacing.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| Bill Kisse | 18-01-2010 |
| Short, sweet and to the point. Just what I needed. Thank you! | |
| Ray Su | 20-01-2010 |
| i like men | |
| myspace uh | 27-01-2010 |
| thanks it works fine :) | |
| Selvi | 30-01-2010 |
| It's very nice and useful. Easy to understand. Thank You! | |
| Hansje | 04-02-2010 |
| nice, but what does nbsp mean? | |
| smo | 04-02-2010 |
| nbsp is non breaking space. Without line break browser should display this. | |
| siya | 04-02-2010 |
| Thanks .. this helped a lot | |
| Get on Google | 05-02-2010 |
| Just do a quick search, and I've found this page. Thanks for the code, I always forgot this one symbol. | |
| Colin D | 23-02-2010 |
| Thank you for this, this helped me make my lame excuse for a site's navigation bar look better :) | |
| Orion | 01-03-2010 |
| Thanks. What i have been looking for. :) | |
| Plada | 31-03-2010 |
| Thats really helpfull, thanks. But I still have a question. | |
| Carlos Castillo | 01-06-2010 |
| Be careful when using multiple - Some browsers will ignore more than one and will only display one empty space no matter how many you've defined in your code. To get consistent results (and valid code) use CSS instead and define 'padding' and/or 'margin' for your elements. | |
| Billie Carrington | 21-06-2010 |
| Just like Bill said. Short, sweet and to the point | |
| Smiles | 17-06-2011 |
| Thank you so much! I used this code to decorate my page with pictures by positioning and aligning pictures. It looks perfect now. You rock!! | |
| Phani | 10-03-2012 |
| This helps me a lot ,very useful | |
| Afsana | 30-06-2012 |
| Thanks. it works! | |
| LazarusStr | 07-02-2013 |
| It worked, I could kiss you! Thank you so much! | |
| Aditya Mishra | 09-03-2013 |
|  --------- what is the meaing of &. | |
| M Hamidi | 22-06-2013 |
| Excellent???? Very Helpful | |
| fran | 03-09-2013 |
| great help, simply put, thanks a bunch.. | |
| Jamie jabra | 24-04-2014 |
| Thats amazong thank you! | |
| JUNIX | 19-07-2014 |
| THANK YOU | |
| Anwar Khan | 12-09-2014 |
| How can we add extra spaces between text? | |
| Aravindhan | 02-12-2014 |
| Right on Target......:-) | |
| ehsan | 08-04-2015 |
| thank alllot | |
10-04-2021 | |
| thank you | |