HTML Formatting Tags


If the written text in a website is important than structuring of that text is also very important. Aspeople have trouble reading wide, long, paragraphs of text on Web sites unless they are broken up well.


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.2.1.      Creating Headings –  The < Hn> 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.


Example:

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

This will display following result:


Figure :- 1

Headings are useful when you want to organize text  into named sections. These are preformatted tags.  In all there are six headings of form  <hn>, where n  is any number between 1 and 6; since the browser  must know the beginning and ending words for the  heading, closing tags of the form  </hn> are needed  to close the six different heading tags.Applying heading tags to text causes that text to  have a predetermined size and format. H1 is the  largest, and H6 is the smallest.

1.2.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 second paragraph of text.</p> 
<p>Here is a third paragraph of text.</p>


This will produce following result:



Figure :2


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 jutified. This works when you have multiple lines in your paragraph and you want to justfy all the lines so that they can look more nice.</p>

This will produce following result:





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.  The <br> tag forces a line break wherever you place it. It is similar to single spacing in a document.

This Code
Would Display
<p>This <br> is a para<br> graph with line breaks</p>

Hello<br />

You come most carefully upon your hour.<br /> Thanks<br />
Mahnaz

This is a para graph with line breaks.

Output :
Hello

You come most carefully upon your hour.

Thanks

Mahnaz





1.2.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.

Example:


<p>This is not in the center.</p> <center>
<p>This is in the center.</p> </center>


This will produce following result:


This is not in the center.

This is in the center.

<center> </center>
The <center> </center> tag works for paragraphs, tables, headings, and images. Everything between the tags will be centered horizontally on the page.


1.2.5.      Nonbreaking Spaces

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:


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 nonbreaking space entity (&nbsp;) 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&nbsp;Angry&nbsp;Men."</p>

&nbsp;
The &nbsp; creates a non breaking space. It is used to add extra spaces without adding an extra line, or to add a blank character between letters while keeping the text together.


2.9.6.   Soft Hyphens


Occasionally, you will want to allow a browser to hyphenate long words to better justify a paragraph. For example, consider the following code and its resulting output.


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


In cases where you want a client browser to be able to hyphenate a word if necessary, use the soft hyphen entity (&shy;) 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&shy;skai&shy;deka&shy;phobia, has plagued some important historic figures like Mahamiya and Nanao.</p>
This will produce following result:


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

NOTE: This may notwork with some web browsers.


2.9.7. 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.

<pre>

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


This will produce following result:

function testFunction( strText ){ alert (strText) }


Figure 3




No comments:

Post a Comment