HTML Blank Space: Spaces,   and CSS Spacing

Examples of blank space in HTML

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&nbsp;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.

Best practice: do not build page layout by repeating &nbsp;. Use CSS margin, padding, gap or an appropriate layout system instead.

Why Multiple Spaces Collapse Top ↑

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.

Using &nbsp; for a Non-Breaking Space Top ↑

&nbsp; 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&nbsp;km</p>
<p>₹500&nbsp;only</p>

Can I repeat &nbsp; to make a wider gap? Top ↑

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&nbsp;&nbsp;&nbsp;Link2</p>

For visual separation between links, controls or blocks, prefer CSS.

Create Blank Space with CSS Top ↑

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.

Padding Top ↑

<span style="padding-left: 20px;">This text starts 20px from the left.</span>

Margin Top ↑

<div style="margin-left: 20px;">
  Indented block-level element.
</div>

Gap between a group of items Top ↑

<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.

Indenting the First Line of Text Top ↑

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.

Preserving Spaces and Line Breaks with <pre> Top ↑

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.

Blank Lines and Line Breaks Top ↑

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.

Legacy Technique: Transparent Spacer Images Top ↑

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
Legacy only: spacer images should not be used for modern layout. They add unnecessary markup and make responsive spacing harder to maintain. Use CSS margin, padding or gap instead.

Common HTML Spacing Mistakes Top ↑

Repeating &nbsp; for layout Top ↑

Use non-breaking spaces because the content must not wrap there, not because you need an arbitrary visual gap.

Typing many regular spaces in the source Top ↑

Normal HTML collapses them. Use CSS when the desired result is visual spacing.

Using repeated <br> tags for vertical spacing Top ↑

Line breaks are content, not a layout system. Use CSS margin or padding between blocks.

Using <pre> to align structured data Top ↑

If the content is a real table or list, use the corresponding semantic HTML element instead of spaces.

Using spacer images Top ↑

This historical technique is unnecessary in modern HTML/CSS and makes responsive layouts harder to maintain.

Frequently Asked Questions Top ↑

Q1: Why do multiple spaces in HTML become one space?

Normal HTML text collapses consecutive spaces, tabs and line breaks into a single displayed space.

Q2: What does &nbsp; mean in HTML?

It represents a non-breaking space, which creates a space where the browser does not normally break the line.

Q3: Should I use several &nbsp; entities to position elements?

No. Use CSS margin, padding, gap or an appropriate layout system for visual spacing.

Q4: How do I preserve several spaces and line breaks?

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.

Q5: Should I use br tags to create vertical space?

No. Use br when a line break is meaningful within the content; use CSS margin or padding for layout spacing.

Q6: Are transparent spacer images still recommended?

No. Spacer images are a legacy layout technique. Modern pages should use CSS for spacing.


Font Colour INS tag for inserted text Managing Font Size and Style




plus2net.com







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

&nbsp--------- 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



We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer