If you want people to read what you have written, then structuring your text well is even more important on the Web than when writing for print. People have trouble reading wide, long, paragraphs of text on Web sites unless they are broken up well.
This section will teach you basic text formatting elements like heading elements and paragraph elements.
Whitespace and Flow:
Before you start to mark up your text, it is best to understand what HTML does when it comes across spaces and how browsers treat long sentences and paragraphs of text.
You might think that if you put several consecutive spaces between two words, the spaces would appear between those words onscreen, but this is not the case; by default, only one space will be displayed. This is known as white space collapsing. So you need to use special HTML tags to create multiple spaces.
Similarly, if you start a new line in your source document, or you have consecutive empty lines, these will be ignored and simply treated as one space. So you need to use special HTML tags to create more number of empty lines.
1. Create Headings – The <h> Elements:
Any documents starts with a heading. You use different sizes for your headings. HTML also have six levels of headings, which use the elements <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>. While displaying any heading, browser adds one line before and after that heading.
<h1>This is heading 1</h1>
<h6>This is heading 6</h6>
This will display following result:
This is heading 1
This is heading 6
2. Create Paragraph – The <p> Element:
The <p> element offers a way to structure your text. Each paragraph of text should go in between an opening <p> and closing </p> tag as shown below in the example:
<p>Here is a paragraph of text.</p>
<p>Here is a third paragraph of text.</p>
This will produce following result:
Here is a paragraph of text.
Here is a third paragraph of text.
3. Create Line Breaks – The <br /> Element:
Whenever you use the <br /> element, anything following it starts on the next line. This tag is an example of an empty element, where you do not need opening and closing tags, as there is nothing to go in between them.
Note: The <br /> element has a space between the characters br and the forward slash. If you omit this space, older browsers will have trouble rendering the line break, while if you miss the forward slash character and just use <br> it is not valid XHTML
4. Centring Content – The <center> Element:
You can use <center> tag to put any content in the center of the page or any table cell.
<p>This is not in the center.</p>
5. Preserve Formatting – The <pre> Element:
Sometimes you want your text to follow the exact format of how it is written in the HTML document. In those cases, you can use the preformatted tag (<pre>).
Any text between the opening <pre> tag and the closing </pre> tag will preserve the formatting of the source document.
6. Horizontal Rules – The <hr /> Element:
Horizontal rules are used to visually break up sections of a document. The <hr> tag creates a line from the current position in the document to the right margin and breaks the line accordingly.
For example you may want to give a line between two paragraphs as follows:
<p>This is paragraph one and should be on top</p>
<p>This is paragraph two and should be at bottom</p>
If you use a word processor, you are familiar with the ability to make text bold, italicized, or underlined; these are just three of the ten options available to indicate how text can appear in HTML and XHTML.
1. Bold Text – The <b> Element:
Anything that appears in a <b>…</b> element is displayed in bold, like the word bold here:
|<p>The following word uses a <b>bold</b> typeface.</p>|
2. Italic Text – The <i> Element:
Anything that appears in a <i>…</i> element is displayed in italicized, like the word italicized here:
|<p>The following word uses a <i>italicized</i> typeface.</p>|
3. Underlined Text – The <u> Element:
Anything that appears in a <u>…</u> element is displayed with underline, like the word underlined here:
|<p>The following word uses a <u>underlined</u> typeface.</p>|
618 total views, 6 views today