1. Home
  2. Computing & Technology
  3. Web Design / HTML

Why don't space characters show on Web pages?

By , About.com Guide

Question: Why don't space characters show on Web pages?

One of the first challenges that a Web designer has when building a Web page is that Web pages don't handle white space characters the same way that word processors do. But once you understand how white space works on the Web, things will be much easier.

Answer:

White space refers to the empty spaces in a design. In HTML there are three characters that act as white space:

  • space
  • tab
  • carriage return (line feed)

White Space in HTML Collapses

When you write your HTML, you can add any number of these white space characters into your HTML. But when you view that HTML in a Web page - all but one disappear! This is very different from a word processor.

In a word processor if you hit your space bar 10 times, the pointer moves over 10 spaces, and text begins 10 spaces from the preceding text. But if you paste that same text into an HTML document, and view it in a Web browser, only 1 space appears. Try it for yourself, type the following into your HTML document, be sure to include all the spaces, and then view it in your Web browser:

<p>There are  two spaces here,    four spaces here, and          10 spaces here!</p>

Try it with carriage returns too:

<p>Two carriage returns

Three carriage returns


And so on...</p>

How to Get Whitespace to Display

In order for those spaces to display in your Web browsers you have to use special codes and HTML tags.

To get a single space, use the non-breaking space. Type &nbsp; where ever you want an extra space.

To get a carriage return, use the <br /> HTML element.

Explore Web Design / HTML
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. HTML and XHTML
  5. Beginning HTML Tutorials
  6. Why don't space characters show on Web pages - White space is condensed in HTML>

©2009 About.com, a part of The New York Times Company.

All rights reserved.