HTML Formatting Tags
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.
Create Headings – The 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
,
,
,
,
, and
. While displaying any heading, browser adds one line before and after
that heading.
Example:
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
|
This will display following result:
This is heading 1
This is heading 2
This is heading 3
This is heading 4
This is heading 5
This is heading 6
|
Create Paragraph – The Element:
The element offers a way to structure your text. Each paragraph of text should
go in between an opening and closing
tag as shown below in the example:
Here is a paragraph of text.
Here is a second paragraph of text.
Here is a third paragraph of text.
|
This will produce following result:
Here is a paragraph of text.
Here is a second paragraph of text.
Here is a third paragraph of text.
|
You can use align attribute to align your paragraphs.
This is left aligned.
This is center aligned.
This is right aligned.
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.
|
This will produce following result:
This is left aligned.
This is center aligned.
This is right aligned.
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.
|
Create Line Breaks – The
Element:
Whenever you use the
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
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
it
is not valid XHTML
Example:
Hello You come most carefully upon your hour. Thanks Hamza
|
This will produce following result:
Hello
You come most carefully upon your hour.
Thanks
Hamza
|
Centring Content – The
Element:
You can use
tag to put any content in the center of the page or any table
cell.
Example:
This is not in the center.
This is in the center.
|
This will produce following result:
This is not in the center.
This is in the center.
|
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 ( ) instead of a normal space. For example, when coding
the "12 Angry Men" paragraph, you would use something similar to the following code:
A good example of this technique appears in the movie “12 Angry Men.”
|
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.
The morbid fear of the number 13, or
triskaidekaphobia, has plagued some important historic figures like
Mahamiya and Nanao.
|
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:
Example for soft hyphen - The morbid
fear of the number 13, or triskaidekaphobia, has plagued
some important historic figures like Mahamiya and Nanao.
|
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.
Preserve Formatting – The 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 ().
Any text between the opening tag and the closing
tag will preserve the
formatting of the source document.
function testFunction( strText ){
alert (strText)
}
|
This will produce following result:
function testFunction( strText ){
alert (strText)
}
|
Horizontal Rules – The
Element
Horizontal rules are used to visually break up sections of a document. The
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:
This is paragraph one and should be on top
This is paragraph two and should be at bottom
|
This will produce following result:
This is paragraph one and should be on top
This is paragraph two and should be at bottom
|
Again
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
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
it is not valid XHTML
Presentational Tags:
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.
Bold Text – The Element:
Anything that appears in a ... element is displayed in bold, like the word
bold here:
The following word uses a bold typeface.
|
This will produce following result:
The following word uses a bold typeface.
|
Italic Text – The Element:
Anything that appears in a ... element is displayed in italicized, like the
word italicized here:
The following word uses a italicized typeface.
|
This will produce following result:
The following word uses a italicized typeface.
|
Underlined Text – The Element:
Anything that appears in a ... element is displayed with underline, like the
word underlined here:
The following word uses a underlined typeface.
|
This will produce following result:
The following word uses a underlined typeface.
|
Strike Text – The Element:
Anything that appears in a ... element is displayed with
strikethrough, which is a thin line through the text:
The following word uses a strikethrough typeface.
|
This will produce following result:
The following word uses a strikethrough typeface.
|
Monospaced font – The Element:
The content of a 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.
The following word uses a monospaced typeface.
|
This will produce following result:
The following word uses a monospaced typeface.
|
Superscript Text – The Element:
The content of a 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.
The following word uses a superscript typeface.
|
This will produce following result:
The following word uses a superscript typeface.
|
Subscript Text – The Element:
The content of a element is written in subscript; the font size used is the
same as the characters surrounding it, but is displayed half a character.s height
beneath the other characters.
The following word uses a subscript typeface.
|
This will produce following result:
The following word uses a subscript typeface.
|
Larger Text – The Element:
The content of the element is displayed one font size larger than the rest of
the text surrounding it.
The following word uses a big typeface.
|
This will produce following result:
The following word uses a
big
typeface.
|
Smaller Text – The Element:
The content of the element is displayed one font size smaller than the rest of
the text surrounding it.
The following word uses a small typeface.
|
This will produce following result:
The following word uses a small typeface.
|
Grouping – The
and Elements :
The
and 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
element to indicate that all of the elements within that
element relate to the
footnotes. You might then attach a style to this
element so that they appear
using a special set of style rules.
The
element is used to group block-level elements together:
Content Articles
Actual content goes here.....
|
This will produce following result:
Content Articles
Actual content goes here…..
|
The 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 element.
This is the example of
span tag
and the div tag
alongwith CSS
|
This will produce following result:
This is the example of span tag and the div tag alongwith CSS
|
These tags are commonly used with CSS to allow you to attach a style to a section of
a page
No comments:
Post a Comment