Learn HTML : Comments , Spaces and New Lines

Thursday, February 19th, 2009 | Learn HTML

As we begin to write our html pages we will want to format them nicely and add comments into them so that others can understand what we have done. This article looks at how we can add comments, spaces and new lines into our pages to help us design the desired look we need.

So lets look at comments in html files. It is always good to put comments in your files. This allows you to tell others what you have done and when. For example you might have a section in your html file that tells you when the last time it was updated and who updated it. Like most things inside an html file we need to open and close the comments.  The tags to use are <!–  which opens the comment and   –> which closes it. The main thing to note about comments is whatever you type between the open and close tags of your comment will not be displayed on the screen. To see what we mean , type in the following html into a new file and run it in your browser.

<head>
     <title>Comments And Spaces</title>
</head>
     <body>
     This is displayed on the screen <!-- This is a comment and is not seen -->
</body>
</html>

When you run the new file in your browser you should end up with the following.

Adding Comments

Adding Comments

Now that we know how to add comments to our pages we should look at how html handles spaces. HTML will truncate extra spaces in your text. What this means is , if you have two spaces , the browser will turn them into one or if you have ten spaces html will turn them into one. So basically any number of spaces count as one space. So , if we want to have more than one space in our html page you need to use the command &nbsp; for example,

<head>
     <title>Comments And Spaces</title>
</head>
     <body>
     This is displayed on the screen <!-- This is a comment and is not seen -->
The space between the square brackets is 4 spaces [&nbsp;&nbsp;&nbsp;&nbsp;]
     </body>
</html>

When you run the page in your browser you will see ..

Five Spaces

Four Spaces

You will notice that even the new line that we have put in the document has been converted or to a space , so we really need to know the html keyword for a new line. The command is <br /> This is different to the formating we have seen so far, it has an open and close but all inside the same tag. So if we change our code to this  

<head>
     <title>Comments And Spaces</title>
</head>
     <body>
     This is displayed on the screen <!-- This is a comment and is not seen -->
<br />The space between the square brackets is 4 spaces [&nbsp;&nbsp;&nbsp;&nbsp;]
     </body>
</html>

We get the following,

New lines

New lines

Now that we know about space’s, comments and new lines we are ready to move on. The next article that will be coming shortly will tell us how to format our text.

No comments yet.

Leave a comment

Categories

Blog Counts

Search

Archives

PHP Notice: A feed could not be found at http://twitter.com/statuses/friends_timeline/16449757.rss in F:\hshome\anncoona\smarterdimensions.com\Blog\wp-content\plugins\external-rss-reader\inc\simplepie.inc on line 1780