Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

HTML

Learn step by step



HTML Formatting Tags

To make your content more readable structure of your text plays a very important role. Users have trouble reading wide, long, paragraphs of text on Web sites unless they are broken up well.
Below 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 good 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 it would replicate the same onscreen, but this is not the case; by default, only one space will be displayed. This is known as white space collapsing. So special HTML tags are required to create multiple spaces.
Similarly, if you have a new line in your source document, or you have consecutive empty lines, these will be ignored and simply treated as one space. So even for this you need to use special HTML tags to create more number of empty lines.


Create Headings - The <hn> Elements:

Every document starts with a heading. You use different sizes for your headings. HTML has six levels/types of heading, which use the elements <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>. While displaying any heading, browser automatically adds one line before and after that heading.


<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
Run

Create Paragraph - The <p> Element:

The <p> element offers a way to structure your text. Each text of a paragraph 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 second paragraph of text.</p>
<p>Here is a third paragraph of text.</p>

Run

You can use align attribute to align your paragraphs.

<p align="left">This is left aligned.</p>
<p align="center">This is center aligned.</p>
<p align="right">This is right aligned.</p>
<p align="justify">This is justified. This works when you have multiple lines in your paragraph and you want to justify all the lines so that they can look more nice.</p>
Run

Create Line Breaks - The <br /> Element:

Whenever you use the <br /> element, anything following it starts on the next line. This tag is an empty element, which doesn't 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.


Hello<br />
You should write well formatted code.<br />
Thanks<br />
Davis

Run

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>
<center>
<p>This is in the center.</p>
</center>

Run

Non-breaking Spaces:
<p> Suppose you were to use the phrase "12 Angry Men." Here you would not want a browser to split the "12" and "Angry" across two lines: </p>
A good example of this technique appears in the movie "12 Angry Men."

In cases where you do not want the client browser to break text, you should use a non-breaking space entity ( ) instead of a normal space. For example, when coding the "12 Angry Men" paragraph, you would use something similar to the following code:

<p>A good example of this technique appears in the movie "12 Angry Men</p>
Soft Hyphens:

<p>Occasionally, you will want to allow a browser to hyphenate long words to better justify a 9vparagraph. For example, consider the following code and its resulting output.</p>

<p style="text-align: justify;"> The morbid fear of the number 13, or triskaidekaphobia, has plagued some important historic figures like Mahamiya and Nanao.&1t;/p>

In cases where you want a client browser to be able to hyphenate a word if necessary, use the soft hyphen entity (­) to specify where a word should be hyphenated. So above example should be written as follows:


<p style="text-align: justify;"> Example for soft hyphen - The morbid fear of the number 13, or tri­skai­deka­phobia, has plagued some important historic figures like Mahamiya and Nanao.</p>

Output

Example for soft hyphen - The morbid fear of the number 13, or tri-skaiŽdekaŽphobia, has plagued some important historic figures like Mahamiya and Nanao.

NOTE:This may not work with some web browsers.
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 pre-formatted tag (<pre>).
Any text between the opening <pre> tag and the closing </pre> tag will preserve the formatting of the source document.


<pre> function testFunction( strText ){ alert (strText) } </pre>

Output

function testFunction( strText ){
alert (strText)
}
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>
<hr />
<p>This is paragraph two and should be at bottom</p>
Run

Again <hr /> 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 <hr /> 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 <hr> it is not valid XHTML

Presentational Tags:

If you have used a word processor, you would be 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.

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

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

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

Strike Text - The <strike> Element:

Anything that appears in a <strike>...</strike> element is displayed with strikethrough, which is a thin line through the text


<p>The following word uses a <strike>strikethrough</strike> typeface.</p>
Run

Monospaced font - The <tt> Element:

The content of a <tt> element is written in monospaced font. Most fonts are known as variable-width fonts because different letters are of different widths (for example, the letter m is wider than the letter i). In a monospaced font, however, each letter is the same width.


<p>The following word uses a <tt>monospaced</tt> typeface.</p>
Run

Superscript Text - The <sup> Element:

The content of a <sup> element is written in superscript; the font size used is the same size as the characters surrounding it but is displayed half a character.s height above the other characters.


<p>The following word uses a <sup>superscript</sup> typeface.</p>
Run

Larger Text - The <big> Element:

The content of the <big> element is displayed one font size larger than the rest of the text surrounding it.


<p>The following word uses a <big>big</big> typeface.</p>
Run

Smaller Text - The <small> Element:

The content of the <small> element is displayed one font size smaller than the rest of the text surrounding it.


<p>The following word uses a <small>small</small> typeface.</p>
Run

Grouping - The <div> and <span> Elements

The <div> and <span> elements allow you to group together several elements to create sections or subsections of a page.
For example, you might want to put all of the footnotes on a page within a <div> element to indicate that all of the elements within that <div> element relate to the footnotes. You might then attach a style to this <div> element so that they appear using a special set of style rules.
The <div> element is used to group block-level elements together:


<div id="menu" align="middle" > <a href="/index.htm">HOME</a> | <a href="/about/contact_us.htm">CONTACT</a> | <a href="/about/index.htm">ABOUT</a> </div> <div id="content" align="left" bgcolor="white"> <h5>Content Articles</h5> <p>Actual content goes here.....</p> </div>
Run

Content Articles

Actual content goes here.....

The <span> element, on the other hand, can be used to group inline elements only. So, if you had a part of a sentence or paragraph you wanted to group together you could use the <span> element.


<div><p>This is the example of <span style="color:green">span tag</span> and the <span style="color:purple">div tag</span> alongwith CSS</p></div>
Run



Related Videos