Miscellaneous Formatting
<br> | Line break |
| Non-breaking space token |
<p align="position"> | Text alignment |
<!-- Comments --> | Hidden comment line |
Along with or in place of block elements, you can use the
br element to force a line break at will. Conversely, there may be times where you want to insure that the flow of text does not break between two words. For this you will use non-breaking space token ( ). No doubt, you will also want to know how to align your text to the left, right or in the center of your web page. And last but not least, you may be interested in how to place text in your HTML source code that remains hidden behind the scenes of the resulting web page.These are all covered in more detail below:
Forcing a Line Break
<br>The all-purpose
br element forces a line break anytime you want without having to place the text within a block level element. The br element is known as an 'empty' element because unlike other HTML elements, it typically contains no content or text between a start and end tag, and moreover does not even have an end tag. Hence the br element is rendered in HTML simply as <br>. Put as many of them as you like. Each instance of the <br> tag creates the equivalent of one line break on your web page. The
<br> tag is versatile and lends itself to numerous applications. For example, you could simulate paragraphing without using the p element by putting two <br><br> tags whenever you wish to begin a new paragraph. Or you could create extra blank space by stringing 3 or more <br> tags together. Example:Example 1 - SOURCE CODE
This is the first line.<br><br><br><br>The next line appears here after creating some vertical blank space using a string of 'br' elements.About the Non-breaking Space Token
As well as ignoring line breaks, web browsers also ignore all extra inter-word white space that appears in the source code. Hence if you are typing some text in your HTML source code and you press the spacebar on your keyboard three times attempting to create an extra long space in between words, the result on your web page will still only be a single inter-word space.
To create extra horizontal or inter-word space, many web authors will string together a bunch of non-breaking space tokens
in the source code although this is not what this was originally intended for. As the name implies, the original purpose of the non-breaking space token is to prevent the flow of text breaking to the next line in between two words that the author wishes to be displayed on the same line no matter what. For example, if the author was referring to the name Pepsi Cola and he wanted to be certain that the Cola part didn't break to the next line on the web page he would type Pepsi Cola in the source code.Aligning Text
<p align="position">By default, all text is aligned to the left margin of the web page or the left margin of the block element containing the text. You may, however, explicitly set the alignment of your text in various other manners. This accomplished by using the
align attribute in the start tag of the block element containing the text and then using either left, right, center or justify as the value. This will apply the following effects respectively:-
left- The beginning of each new line of text is aligned flush with the left margin of the block element. -
right- The end of each line of text is aligned flush with the right margin of the block element. -
center- Each line of text is aligned in the center of the block element. -
justify- Each line of text is aligned flush to both the left and right margins of the block element. (For example, most of the text on the web page you are currently viewing is justified to both margins.)
Example 2 - SOURCE CODE
<p align="right">In this paragraph, the text is aligned to the right.</p>
Comment Lines
As your web pages become more and more complex so will the source code you write to produce said web pages. You may eventually find it difficult to navigate your way around what has become a confusing mess of color-coded markup interspersed with your visible text. In this predicament, it will help to place titles and 'signposts' in and about your HTML source code to help you locate important sections that you frequently edit. Using special 'comment'
<!-- --> delimiters allows you to place text in the source code that web browsers will ignore when displaying the resulting web page.In the example below, the words "INTRODUCTORY PARAGRAPH" will not appear on the resultant web page:
Example 3 - SOURCE CODE
<!-- INTRODUCTORY PARAGRAPH --><p><font face="verdana" size="2">This section will introduce the aspiring web author to fundamentals of writing Hypertext Markup Language...</font></p>
Next, let's learn an easy way to create headings and subheadings on your web page...
| <~BACK | TOP | NEXT ~> |
