Friday, 10 August 2012

HTML Images:


Insert image – The <img> Element:

You will insert any image in tour web page by using <img> tag. Following is the simple syntax to use this tag.

<img src= “image URL” attr_name=”attr_value” … more attributes />

Image Attributes:

Following are most frequently used attributes for <img> tag.

·         Width: sets width of the image. This will have a value like 10 pr 20% etc.
·         Height: sets height of the image. This will have a value like 10 or 20% etc.
·         Border: sets a border around the image. This will have a value like 1 or 2 etc.
·         Src: specifies URL of the image file.
·         Alt: this is an alternate text which will be displayed if image is missing.
·         Align: this sets horizontal alignment of the image and takes value either left, right or center.
·         Valign: this sets vertical alignment of the image and takes value either top, bottom or center.
·         Hspace: horizontal space around the image. This will have a value like 10 or 20% etc.
·         Vspace: Vertical space around the image. This will have a value like 10 or 20% etc.
·         Name: name of the image with in the document.
·         Id: id of the image within the document.
·         Style: this will be used if you are using CSS.
·         Title: specifies a text title. The browser, perhaps flashing the title when the mouse passes over the link.
·         ismap and usemap: These attributes for the <img> tag tell the browser that the image is a special mouse-selectable visual map of one or more hyperlinks, commonly known as an image map.

HTML Marquees


A HTML marquee is a scrolling piece of text displayed either horizontally across or vertically down your web site page depending on the settings. This is created by using HTML tag <marquee>.

Syntax:
A simple syntax to use marquee is as follows:

<marquee attribute_name = “attribute_value”….more attributes>

One or more lines or text message or image.

</marquee>

Attributes:

A HTML marquee can have following attributes:
·         Width: how wide the marquee is. This will have a value like 10 or 20 % etc.
·         Height: how tall the marquee is. This will have a value like 10 or 20%etc.
·         Direction: which direction the marquee should scroll. This will have value either up, down, left or right.
·         Behaviour: what type of scrolling. This will have value scroll, slid and alternate.
·         Scrolldelay: how long to delay between each jump. This will have  a value like 10 etc.
·         Scrollamount: how far to jump. This will have a value like 10 etc.
·         Loop: how many times to loop. The default value is INFINITE, which names that the marquee loops endlessely.
·         Bgcolor: background color. This will have a value like 10 or 20% etc.
·         Vspace: vertical space around the marquee. This will have a value like 10 or 20% etc.
·         Hspace: horizontal space around the marquee. This will have a value like 10 or 20% etc.

HTML Comments


Comments are piece of code which is ignored by an web browser. It is good practice to comment your code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code.
HTML Comment lines are indicated by the special beginning tag <!—and ending tag --> placed  at the beginning and end of EVERY line to be treated as a comment.
Comments do not nest, and the double-dash sequence “--” may not appear inside a comment except as part of the closing --> tag. You must also make sure that there are no spaces in the start-of-comment string.

For example: Given line is a valid comment in HTML.

<!--    This is commented out  -->

But following line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angle bracket and the exclamation mark.

<!--        This is commented out  -->


Multiline Comments:
You have seen how to comment a single line in HTML. You can comment multiple lines by the special beginning tag <!--  and ending tag --> placed before the first line and end of the lastline to be treated as a comment.

For example:

<!-- 
This is a multiline comment <br />
And can span through as many as lines you like.
-->

Conditional Comments:
Conditional comments only work as follows:
<!—[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

·         Their basic structure is the same as an HTML comment (<!-- -->). Therefore all other browsers will see them as normal comments and will ignore them entirely.
·         Explorer Windows, though, has been programmed to recognize the special <!—[if IE]> syntax, resolves the if and parses the content of the conditional comment as if it were normal page content.
·         Since conditional comments use the HTML comment structure, they can only be included in HTML files.

Using Comment tag:

There are few browsers who supports <comment> tag to comment a part of code.

<p>This is <comment> not </comment> Internet Explorer. </p>

Commenting Scripts and Style Sheets:

If you are using Java script or VB in your HTML code then it is recommended to put that script code inside proper HTML Comments to make old browser works properly.

For example:
<script>
<!—
Document.write(“Hello World!”)
//-->
</script>

Similarly if you are using Casecading Style Sheet in your HTML code then it is recommended to put that style sheet code inside proper HTML Comments to make old browser works properly.

For example:
<style>
<!—
Img{
Border:0px;
}
</style>



HTML Phrase Tags


Emphasized Text – The <em> Element:

The content of an <em> element is intended to be a point of emphasis in your document, and it is usually displayed in italicized text. The kind of emphasis intended is on words such as  “must” in the following sentence:

<p>You <em>must</em> remember to close elements in XHTML.</p>


Strong Text – The <strong> Element:

The <strong> element is intended to show strong emphasis for its content; stronger emphasis than the <em> element. As with the <em>element, the <strong> element should be used only when you want to add strong emphasis to part of a document.

<p>You <strong>must</strong> remember to close elements in XHTML.</p>


Text Abbreviation – The <abbr> Element:

You can indicate when you are using an abbreviated form by placing the abbreviation between opening <abbr> and closing </abbr> tags.

<p>I have a friend called <abbr title = “Abhishek”>Abhy</abbr>.</p>

This will produce following result:

I have a friend called Abhy.

Using Acronym – The <acronym> Element:

The <acronym> element allows you to indicate that the text between an opening <acronym> and closing </acronym> element is an acronym.

When possible use a title attribute whose value is the full version of the acronyms on the <acronym> element, and if the acronym is in a different language, include an xml:lang attribute in XHTML documents.

<p>This chapter covers marking up text in <acronym title = “Extensible Hypertext Markup Language”>XHTML</acronym>


Special Terms – The <dfn> Element:

The <dfn> Element allows you to specify that you are introducing a special term. Its use is similar to the words that are in italics in the midst of paragraphs in this book when new key concepts are introduced.
Typically, you would use the <dfn> element the first time you introduce a key term and only in that instance. Most recent browser render the content of a <dfn> element in an italic font.

<p>This tutorial teaches you how mark up your documents for the web using <dfn> XHTML</dfn>.</p>


Quoting Text – The <blockquote> Element:

When  you want to quote a passage from another source, you should use the <blockquote> element.

Text inside a <blockquote>element is usually indented from the left and right edges of the surrounding text, and sometimes uses an italicized font.


<p>The following description of XHTML is taken from the website :</p>

<blockquote> XHTML 1.0 is the  first Recommendation for XHTML, following on from earlier work on HTML 4.01, HTML 4.0, HTML 3.2, and HTML 2.0 </blockquote>

Short Quotation – The <q> Element:

The <q> element is intended to be  used when you want to add a quote within a sentence rather than as an indented block on its own.

<p>Amit is in Spain, <q> He is their at my home. I think I am wrong</q>.</p>

Citations – The <cite>Element:

 If you are quotation a text, you can indicate the source placing it between an opening <cite> tag and closing </cite> tag. As you would expect in a print publication, the content of the <cite> element is rendered in italicized text by default.

<p>This HTML Tutorial is derived from <cite> World Wide Web Standard for HTML </cite>.</p>

Computer Code – The <code> Element:

Any code to appear on a Web Page should be placed inside a <code> element. Usually the content of the <code> element is presented in a monospaced font, just like the code in most programming books.

Keyboard Text – The <kbd> Element:

When you are talking about computers, if you want to tell a reader to enter some text, you can use the <kbd> element to indicate.

The content of a <kbd>  element is usally represented in a monspaced font rather like the content of the <code> element.

<h1> <kbd> This is inside kbd element</kbd></h1>

Programming variables – The <var> Element:

This element is usually in conjunction with the <pre> and <code> elements to indicate that the content of that element is a variable that can be supplied by a user.

<p><code> document.write(“<var>user-name</var>”)</code></p>

This will produce following result:

document.write (“user-name”)

Program Output – The <samp> Element:

The  <samp> element indicates sample output from  a program, script, or like. Again, it is mainly used when documenting programming concepts.
For example:

<p>Result produced by the program is <ssamp> Hello World</samp></p>

This will produce following result:

Result produced by the program is Hello World



Addresses – The <address>Element:

The <address> element is used to contain any address. For example:

<address>304, Menna Colony, Hyderabad – INDIA, 500032 </address>

This will produce following result:

304, Menna Colony, Hyderabad – INDIA, 500032

Block and Inline Elements:

We can categories all the elements into two sections:

·         block-level elements – block-level elements appear on the screen  as if they have a carriage return or line break before and after them. For example the <p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <ul>, <ol>, <dl>, <pre>, <hr />, <blockquote>, and anything that follows them appears on its own new line.

·         Inline elements – Inline elements, on the other hand, can appear within sentences and do not have to appear on a new line of their own. The <b>, <i>, <u>, <em>, <strong>, <sup>, <sub>, <big>, <small>,  <li>,  <ins>, <del>, <code>, <cite>, <dfn>, <kbd>, and <var> elements are all inline elements.

Presentational Tags:


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>

This will produce following result:
The Following word uses a bold typeface.

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>

This will produce following result:
The following word uses a italicized typeface

Underlined Text – The <u> Element:
Anything that appears in a <u>…..</u> element is displayed in italicized, like the word italicized here:
<p>The following word uses a <u>underlined</u>typeface</p>

This will produce following result:
The following word uses a underlined typeface

Strike Text – The <strike> Element:
Anything that appears in a <strike>…..</strike> element is displayed in italicized, like the word italicized here:
<p>The following word uses a <strike>strikethrough</strike>typeface</p>

This will produce following result:
The following word uses a strikethrough typeface

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. In a monospaced font, each letter is the same width.

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

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 characters height above the other characters.

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

This will produce following result:

The following word uses a superscript typeface.

Subscript Text – The <sub>Element:

The content of a <sub> element is written in subscript; the font size used is the same as the characters surrounding it, but is displayed half a characters height beneath the other characters.

<p>The following word uses a <sub>subscript<sub>typeface.</p>

This produce the following result:

The following word uses a subscript typeface.

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.


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>


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


This will produce following result:

                                                HOME |  CONTACT  | ABOUT
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 style=”color:purple”>div tag </span> alongwith CSS </p></div>

This will produce following result:

This is the example of span tag and the div tag alongwith CSS.



The xml:lang Attribute:


The xml:lang attribute is the XHTML replacement for the lang attribute. The value of the xml:lang attribute should be an ISO-639 country code.

Generic Attributes:
attribute
Options
Function
align
Right, left, center
Horizontal aligns tags
valign
Top, middle, bottom
Vertically aligns tags within an HTML element
bgcolor
Numeric, hexadecimal, RGB values
Places a background color behind an element.
background
URL
Places an background image behind an element.
Id
User Defined
Names an element for use with Cascading Style Sheets.
Class
User Defined
Classfies an element for use with Cascading Style Sheets.
Width
Numeric value
Specifies the height of tables, images, or table cells.
height
Numeric value
Specifies the height of tables, images, or table cells.
title
User Defined
“Pop-up” title for your elements.


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

Create Paragraph – The <p> Element:
The <p> element offer a way to structure your text. Each paragraph of text should go in between an opening <p> and closing </p> tag.
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:

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


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
Example:
Hello<br />
You come most carefully upon your hour.<br />
Thanks<br />
Codearms

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&nbp;Men.”</p>

Preserve Formatting - The <pre> Element:
Sometimes we want our text to follow the exact format of how it is written in the HTML document. In those cases, we 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 (strTest)
}

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 on bottom </p>


HTML Attributes


Attributes are another important part of HTML markup. An attribute is used to define the characteristics of an element and is placed inside the element’s opening tag. All attributes are made up of two parts: a name and a value:
·         The name is the property you want to set. For example, the <font> element in the example carries an attribute whose name is face, which typeface you want the text to appear in.
·         The value is what you want the value of the property to be. The first example was supposed to use the Arial typeface, so the value of the face attribute is Arial.
The value of the attribute should be put in double quotation marks, and is separated from the name by the equals sign. You can see that a color for the text has been specified as well as the typeface in this <font>element:
<font face=”arial” color=”#CC0000”>

Core Attributes:
The four core attributes that can be used on the majority of HTML elements are:
·         Id
·         Title
·         Class
·         Style

The id Attribute:
The id attribute can be used to uniquely identify any element within a page (or style sheet).
There are two primary reasons that you might want to use an id attribute on an element:
·         If an element carries an id attribute as a unique identifier it is possible to identify just that element and its content.
·         If you have two elements of the same name within a Web page(or style sheet), you can use the id attribute to distinguish between elements that have the same name.
<p id=”html”>This para explains what is HTML</p>
<p id=”css”>This para explains what is Cascading Style</p>
Note that there are some special rules for the value of the id attribute, it must:
·         Begin with a letter (A,Z or a,z) and can then be followed by any number of letters, digits(0,9), hyphens, underscores, colons and periods.
·       Remain unique within that document; no two attributes may have the same value within that HTML document.
The title Attribute:
The title attribute gives a suggested title for the element.
The behaviour of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip or while the element is loading.
<h4 title=”Hello HTML!”>Titled Heading Tag Example</h4>

The class Attribute:
The class attribute is used to associate an element with a style sheet and specifies the class of element. The value of the attribute may also be a space-separated list of class names. For example:
Class=”className1 className2 className3”

The style Attribute:
The Style attribute allows you to specify CSS  rules within the element. For example:
<p style=”font-family:arial; color:#FF0000;”>Some text…</p>

Internationalization Attributes:
There are three internationalization attributes, which are available to most XHTML elements.
·         dir
·         lang      
·         xml:lang

The dir Attribute:
The dir attribute allows you to indicate to the browser the direction in which the text should flow. The dir attribute can take one of two values, as you can see in the table that follows:
Value
Meaning
Itr
Left to right(the default value)
Rtl
Right to left(for languages such as Hebrew or Arabic that are read right or left)

Example:
<html dir=rtl>
<head>
<title>Display Directions</title>
</head>
<body>
This is how IE 5 renders right-to-left directed text.
</body>
</html>

When dir attribute is used within the <html> tag, it determines how text  will be presented within the entire document. When used within another tag, it controls the text’s direction for just the content of that tag.

The lang Attribute:
The lang attribute allows you to indicate the main language used in a document, but this attribute was kept in HTML only for backwards compatibility with earlier versions of HTML. This attribute has been replaced by the xml:lang attribute in new XHTML documents.
When included within the <html> tag, the lang attribute specifies the language you’ve generally used within the document. When used within other tags, the lang attribute specifies the language you used within that tag’s content.

Example:
<html lang=en>
<head>
<title>English Language Page</title>
</head>
<body>
This page is using English Language
</body>
</html>