Showing posts with label Web Development. Show all posts
Showing posts with label Web Development. Show all posts

Saturday, July 25, 2015

1. HTML Tutorial

 HTML Tutorial

HTML stands for Hyper Text Markup Language, which is the most widely used language on Web to develop web pages.
HTML was created by Berners-Lee in late 1991 but "HTML 2.0" was the first standard HTML specification which was published in 1995. HTML 4.01 was a major version of HTML and it was published in late 1999. Though HTML 4.01 version is widely used but currently we are having HTML-5 version which is an extension to HTML 4.01, and this version was published in 2012.

Audience

This tutorial is designed for the aspiring Web Designers and Developers with a need to understand the HTML in enough detail along with its simple overview, and practical examples. This tutorial will give you enough ingredients to start with HTML from where you can take yourself at higher level of expertise.

Prerequisites

Before proceeding with this tutorial you should have a basic working knowledge with Windows or Linux operating system, additionally you must be familiar with:
  • Experience with any text editor like notepad, notepad++, or Editplus etc.
  • How to create directories and files on your computer.
  • How to navigate through different directories.
  • How to type content in a file and save them on a computer.
  • Understanding about images in different formats like JPEG, PNG format.

Try HTML Online

For most of the examples given in this tutorial you will find Try it option available, so just make use of it to see the output of your code and enjoy your learning.
Try following example using Try it option available at the top right corner of the below sample code box:



   

Hello World!

2. HTML Overview

 HTML Tutorial

HTML stands for Hypertext Markup Language, and it is the most widely used language to write Web Pages.
  • Hypertext refers to the way in which Web pages (HTML documents) are linked together. Thus the link available on a webpage are called Hypertext.
  • As its name suggests, HTML is a Markup Language which means you use HTML to simply "mark up" a text document with tags that tell a Web browser how to structure it to display.
Originally, HTML was developed with the intent of defining the structure of documents like headings, paragraphs, lists, and so forth to facilitate the sharing of scientific information between researchers.
Now, HTML is being widely used to format web pages with the help of different tags available in HTML language.

Basic HTML Document

In its simplest form, following is an example of an HTML document:



</span><span class="pln">This is document title</span><span class="tag">

This is a heading Document content goes here..... Either you can use Try it option available at the top right corner of the code box to check the result of this HTML code, or let's save it in an HTML file test.htm using your favorite text editor. Finally open it using a web browser like Internet Explorer or Google Chrome, or Firefox etc. It must show the following output:
HTML Hello World

HTML Tags

As told earlier, HTML is a markup language and makes use of various tags to format the content. These tags are enclosed within angle braces . Except few tags, most of the tags have their corresponding closing tags. For example has its closing tag
and tag has its closing tag tag etc. Above example of HTML document uses folloiwng tags:
TagDescription
This tag defines the document type and HTML version.
This tag encloses the complete HTML document and mainly comprises of document header which is represented by ... and document body which is represented by ... tags.
This tag represents the document's header which can keep other HTML tags like , <link> etc.</td></tr> <tr><td><title></td><td>The <b><title></b> tag is used inside the <head> tag to mention the document title.</td></tr> <tr><td><body></td><td>This tag represents the document's body which keeps other HTML tags like <h1> , <div> , <p> etc.</td></tr> <tr><td><h1> </td><td>This tag represents the heading.</td></tr> <tr><td><p> </td><td>This tag represents a paragraph.</td></tr> </tbody></table> <p> To learn HTML, you will need to study various tags and understand how do they behave while formatting a textual document. Learning HTML is simple as users have to learn the usage of different tags in order to format the text or images to make a beautiful webpage.</p> <p> World Wide Web Consortium (W3C) recommends to use lowercase tags starting from HTML 4.</p> <h2> HTML Document Structure</h2> <p> A typical HTML document will have following structure:</p> <pre class="result">Document declaration tag </pre> <pre class="result" style="margin-top:5px;"><html> <head> Document header related tags </head> <body> Document body related tags </body> </html> </pre> <p> We will study all the header and body tags in subsequent chapters, for now let's see what is document declaration tag.</p> <h2> The <!DOCTYPE> Declaration</h2> <p> The <!DOCTYPE> declaration tag is used by the web browser to understand the version of the HTML used in the document. Current version of HTML is 5 and it makes use of the following declaration:</p> <pre style="" class="prettyprint prettyprinted"><span class="dec"><!DOCTYPE html></span></pre> <p> There are many other declaration types which can be used in HTML document depending on what version of HTML is being used. We will see more details on this while discussing <!DOCTYPE...> tag along with other HTML tags.</p>

3. HTML Basic Tags

 HTML Tutorial

 Heading Tags

Any document starts with a heading. You can use different sizes for your headings. HTML also has six levels of headings, which use the elements

,

,

,

,

, and
. . While displaying any heading, browser adds one line before and one line after that heading.

Example </span><span class="pln">Heading Example</span><span class="tag">


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 produce following result:
HTML Heading Tags

Paragraph Tag

The tag offers a way to structure your text into different paragraphs. Each paragraph of text should go in between an opening and a closing
tag as shown below in the example:

Example




</span><span class="pln">Paragraph Example</span><span class="tag">
Here is a first 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 first paragraph of text.
Here is a second paragraph of text.
Here is a third paragraph of text.

Line Break Tag

Whenever you use the
element, anything following it starts from 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
tag 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 in XHTML

Example




</span><span class="pln">Line Break  Example</span><span class="tag">
Hello
/> You delivered your assignment ontime.
/> Thanks
/> Mahnaz
This will produce following result:
Hello
You delivered your assignment ontime.
Thanks
Mahnaz

Centering Content

You can use
tag to put any content in the center of the page or any table cell.

Example




</span><span class="pln">Centring Content Example</span><span class="tag">
This text is not in the center.
This text is in the center. This will produce following result:
This text is not in the center.
This text is in the center.

Horizontal Lines

Horizontal lines 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 in the given example below:

Example




</span><span class="pln">Horizontal Line Example</span><span class="tag">
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 the empty element, where you do not need opening and closing tags, as there is nothing to go in between them.
The

element has a space between the characters hr and the forward slash. If you omit this space, older browsers will have trouble rendering the horizontak line, while if you miss the forward slash character and just use

it is not valid in XHTML

Preserve Formatting

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.

Example




</span><span class="pln">Preserve Formatting Example</span><span class="tag">




function testFunction( strText ){
   alert (strText)
}



This will produce following result:
function testFunction( strText ){
   alert (strText)
}
Try using same code without keeping it inside
...
tags

Nonbreaking Spaces

Suppose you want to use the phrase "12 Angry Men." Here you would not want a browser to split the "12, Angry" and "Men" across two lines:
An 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" in a paragraph, you should use something similar to the following code:

Example




</span><span class="pln">Nonbreaking Spaces Example</span><span class="tag">
An example of this technique appears in the movie "12 Angry Men."

4. HTML Elements

 HTML Tutorial

An HTML element is defined by a starting tag. If the element contains other content, it ends with a closing tag, where the element name is preceded by a forward slash as shown below with few tags:
Start TagContentEnd Tag
This is paragraph content.

This is heading content.
This is division content.



So here ....
is an HTML element,

...

is another HTML element. There are some HTML elements which don't need to be closed, such as ,

and
elements. These are known as void elements.
HTML documents consist of a tree of these elements and they specify how HTML documents should be built, and what kind of content should be placed in what part of an HTML document.

HTML Tag vs. Element

An HTML element is defined by a starting tag. If the element contains other content, it ends with a closing tag.
For example is starting tag of a paragraph and
is closing tag of the same paragraph but This is paragraph is a paragraph element.

Nested HTML Elements

It is very much allowed to keep one HTML element inside another HTML element:

Example




</span><span class="pln">Nested Elements Example</span><span class="tag">

This is italic heading This is underlined paragraph This will display following result:

This is italic heading

This is underlined paragraph

5. HTML Attributes

 HTML Tutorial

We have seen few HTML tags and their usage like heading tags

,

, paragraph tag and other tags. We used them so far in their simplest form, but most of the HTML tags can also have attributes, which are extra bits of information.
An attribute is used to define the characteristics of an HTML 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 paragraph element in the example carries an attribute whose name is align, which you can use to indicate the alignment of paragraph on the page.
  • The value is what you want the value of the property to be set and always put within quotations. The below example shows three possible values of align attribute: left, center and right.
Attribute names and attribute values are case-insensitive. However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation.

Example



Align Attribute  Example


This is left aligned
This is center aligned
This is right aligned
This will display following result:
This is left aligned
This is center aligned
This is right aligned

Core Attributes

The four core attributes that can be used on the majority of HTML elements (although not all) are:
  • id
  • title
  • class
  • style

The id Attribute

The id attribute of an HTML tag can be used to uniquely identify any element within an HTML page. 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.
We will discuss style sheet in separate tutorial. For now, let's use the id attribute to distinguish between two paragraph elements as shown below.

Example

This para explains what is HTML
This para explains what is Cascading Style Sheet

The title Attribute

The title attribute gives a suggested title for the element. They syntax for the title attribute is similar as explained for id attribute:
The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip when cursor comes over the element or while the element is loading.

Example



The title Attribute Example


Titled Heading Tag Example

This will produce following result:

Titled Heading Tag Example

Now try to bring your cursor over "Titled Heading Tag Example" and you will see that whatever title you used in your code is coming out as a tooltip of the cursor.

The class Attribute

The class attribute is used to associate an element with a style sheet, and specifies the class of element. You will learn more about the use of the class attribute when you will learn Cascading Style Sheet (CSS). So for now you can avoid it.
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 Casecading Style Sheet (CSS) rules within the element.


The style Attribute


Some text...
This will produce following result:
Some text...
At this point of time, we are not learning CSS, so just let's proceed without bothering much about CSS. Here you need to understand what are HTML attributes and how they can be used while formatting content.

Internationalization Attributes

There are three internationalization attributes, which are available for most (although not all) 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:
ValueMeaning
ltrLeft to right (the default value)
rtlRight to left (for languages such as Hebrew or Arabic that are read right to left)

Example



Display Directions


This is how IE 5 renders right-to-left directed text.


This will produce following result:
This is how IE 5 renders right-to-left directed text.
When dir attribute is used within the 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.
The values of the lang attribute are ISO-639 standard two-character language codes. Check HTML Language Codes: ISO 639 for a complete list of language codes.

Example



English Language Page


This page is using English Language


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 as mentioned in previous section.

Generic Attributes

Here's a table of some other attributes that are readily usable with many of the HTML tags.
AttributeOptionsFunction
alignright, left, centerHorizontally aligns tags
valigntop, middle, bottomVertically aligns tags within an HTML element.
bgcolornumeric, hexidecimal, RGB valuesPlaces a background color behind an element
backgroundURLPlaces a background image behind an element
idUser DefinedNames an element for use with Cascading Style Sheets.
classUser DefinedClassifies an element for use with Cascading Style Sheets.
widthNumeric ValueSpecifies the width of tables, images, or table cells.
heightNumeric ValueSpecifies the height of tables, images, or table cells.
titleUser Defined"Pop-up" title of the elements.
We will see related examples as we will proceed to study other HTML tags. For a complete list of HTML Tags and related attributes please check reference to HTML Tags List

6. HTML Formatting

 HTML Tutorial

If you use a word processor, you must 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

Anything that appears within ... element, is displayed in bold as shown below:

Example




</span><span class="pln">Bold Text Example</span><span class="tag">
The following word uses a bold typeface. This will produce following result:
The following word uses a bold typeface.

Italic Text

Anything that appears within ... element is displayed in italicized as shown below:

Example




</span><span class="pln">Italic Text Example</span><span class="tag">
The following word uses a italicized typeface. This will produce following result:
The following word uses a italicized typeface.

Underlined Text

Anything that appears within ... element, is displayed with underline as shown below:

Example




</span><span class="pln">Underlined Text Example</span><span class="tag">
The following word uses a underlined typeface. This will produce following result:
The following word uses a underlined typeface.

Strike Text

Anything that appears within ... element is displayed with strikethrough, which is a thin line through the text as shown below:

Example




</span><span class="pln">Strike Text Example</span><span class="tag">
The following word uses a strikethrough typeface. This will produce following result:
The following word uses a strikethrough typeface.

Monospaced Font

The content of a ... element is written in monospaced font. Most of the 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 has the same width.

Example




</span><span class="pln">Monospaced Font Example</span><span class="tag">
The following word uses a monospaced typeface. This will produce following result:
The following word uses a monospaced typeface.

Superscript Text

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.

Example




</span><span class="pln">Superscript Text Example</span><span class="tag">
The following word uses a superscript typeface. This will produce following result:
The following word uses a superscript typeface.

Subscript Text

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.

Example




</span><span class="pln">Subscript Text Example</span><span class="tag">
The following word uses a subscript typeface. This will produce following result:
The following word uses a subscript typeface.

Inserted Text

Anything that appears within ... element is displayed as inserted text.

Example




</span><span class="pln">Inserted Text Example</span><span class="tag">
I want to drink cola wine This will produce following result:
I want to drink
colawine

Deleted Text

Anything that appears within ... element, is displayed as deleted text.

Example




</span><span class="pln">Deleted Text Example</span><span class="tag">
I want to drink cola wine This will produce following result:
I want to drink
colawine

Larger Text

The content of the ... element is displayed one font size larger than the rest of the text surrounding it as shown below:

Example




</span><span class="pln">Larger Text Example</span><span class="tag">
The following word uses a big typeface. This will produce following result:
The following word uses a big typeface.

Smaller Text

The content of the ... element is displayed one font size smaller than the rest of the text surrounding it as shown below:

Example




</span><span class="pln">Smaller Text Example</span><span class="tag">
The following word uses a small typeface. This will produce following result:
The following word uses a small typeface.

Grouping Content

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.

Example




</span><span class="pln">Div Tag Example</span><span class="tag">

id="content" align="left" bgcolor="white">
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 have a part of a sentence or paragraph which you want to group together, you could use the element as follows

Example




</span><span class="pln">Span Tag Example</span><span class="tag">
This is the example of style="color:green">span tag and the style="color:red">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.

7. HTML Phrase Tags

 HTML Tutorial

The phrase tags have been designed for specific purposes, though they are displayed in a similar way as other basic tags like , ,
, and , you have seen in previous 
chapter. This chapter will take you through all the important phrase 
tags, so let's start seeing them one by one.

Emphasized Text

Anything that appears within ... element is displayed as emphasized text.

Example



Emphasized Text Example


The following word uses a emphasized typeface.




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

Marked Text

Anything that appears with-in ... element, is displayed as marked with yellow ink.

Example



Marked Text Example


The following word has been marked with yellow




This will produce following result:
The following word has been marked with yellow.

Strong Text

Anything that appears within ... element is displayed as important text.

Example



Strong Text Example


The following word uses a strong typeface.




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

Text Abbreviation

You can abbreviate a text by putting it inside opening and closing
tags. If present, the title attribute must contain this full description and nothing else.

Example



Text Abbreviation


My best friend's name is  Abhy.




This will produce following result:
My best friend's name is Abhy.

Acronym Element

The element allows you to indicate that the text between and tags is an acronym.
At present, the major browsers do not change the appearance of the content of the element.

Example



Acronym Example


This chapter covers marking up text in XHTML.




This will produce following result:
This chapter covers marking up text in XHTML.

Text Direction

The ... element stands for Bi-Directional Override and it is used to override the current text direction.

Example



Text Direction Example


This text will go left to right.


This text will go right to left.




This will produce following result:
This text will go left to right.
This text will go right to left.

Special Terms

The ... element (or HTML Definition Element) allows you to specify that you are introducing a special term. It's usage is similar to italic words in the midst of a paragraph.
Typically, you would use the element the first time you introduce a key term. Most recent browsers render the content of a element in an italic font.

Example



Special Terms Example


The following word is a special term.




This will produce following result:
The following word is a special term.

Quoting Text

When you want to quote a passage from another source, you should put it in between
...
tags.
Text inside a
element is usually indented from the left and right edges of the surrounding text, and sometimes uses an italicized font.

Example



Blockquote Example


The following description of XHTML is taken from the W3C Web site:



XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.
This will produce following result:
The following description of XHTML is taken from the W3C Web site:
XHTML 1.0 is the W3C's first Recommendation for XHTML, following on from earlier work on HTML 4.01, HTML 4.0, HTML 3.2 and HTML 2.0.

Short Quotations

The ... element is used when you want to add a double quote within a sentence.

Example



Double Quote Example


Amit is in Spain, I think I am wrong.




This will produce following result:
Amit is in Spain, I think I am wrong.

Text Citations

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

Example



Citations Example


This HTML tutorial is derived from W3 Standard for HTML.




This will produce following result:
This HTML tutorial is derived from W3 Standard for HTML.

Computer Code

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

Example



Computer Code Example


Regular text. This is code. Regular text.




This will produce following result:
Regular text. This is code. Regular text.

Keyboard Text

When you are talking about computers, if you want to tell a reader to enter some text, you can use the ... element to indicate what should be typed in, as in this example.

Example



Keyboard Text Example


Regular text. This is inside kbd element Regular text.




This will produce following result:
Regular text. This is inside kbd element Regular text.

Programming Variables

This element is usually used in conjunction with the


 and  elements to indicate that the content of that element is a variable.

Example



Variable Text Example


document.write("user-name")




This will produce following result:
document.write("user-name")

Program Output

The ... element indicates sample output from a program, and script etc. Again, it is mainly used when documenting programming or coding concepts.

Example



Program Output Example


Result produced by the program is Hello World!




This will produce following result:
Result produced by the program is Hello World!

Address Text

The
...
element is used to contain any address.

Example



Address Example


388A, Road No 22, Jubilee Hills - Hyderabad
This will produce following result:
388A, Road No 22, Jubilee Hills - Hyderabad

8. HTML Meta Tags

 HTML Tutorial

HTML lets you specify metadata - additional important information about a document in a variety of ways. The META elements can be used to include name/value pairs describing properties of the HTML document, such as author, expiry date, a list of keywords, document author etc.
The tag is used to provide such additional information. This tag is an empty element and so does not have a closing tag but it carries information within its attributes.
You can include one or more meta tags in your document based on what information you want to keep in your document but in general, meta tags do not impact physical appearance of the document so from appearance point of view, it does not matter if you include them or not.

Adding Meta Tags to Your Documents

You can add metadata to your web pages by placing tags inside the header of the document which is represented by and
tags. A meta tag can have following attributes in addition to core attributes:
AttributeDescription
NameName for the property. Can be anything. Examples include, keywords, description, author, revised, generator etc.
contentSpecifies the property's value.
schemeSpecifies a scheme to interpret the property's value (as declared in the content attribute).
http-equivUsed for http response message headers. For example http-equiv can be used to refresh the page or to set a cookie. Values include content-type, expires, refresh and set-cookie.

Specifying Keywords

You can use tag to specify important keywords related to the document and later these keywords are used by the search engines while indexing your webpage for searching purpose.

Example

Following is an example where we are adding HTML, Meta Tags, Metadata as important keywords about the document.


Meta Tags Example



Hello HTML5!




This will produce following result:
Hello HTML5!

Document Description

You can use tag to give a short description about the document. This again can be used by various search engines while indexing your webpage for searching purpose.

Example



Meta Tags Example




Hello HTML5!




Document Revision Date

You can use tag to give information about when last time the document was updated. This information can be used by various web browsers while refreshing your webpage.

Example



Meta Tags Example





Hello HTML5!




Document Refreshing

A tag can be used to specify a duration after which your web page will keep refreshing automatically.

Example

If you want your page keep refreshing after every 5 seconds then use the following syntax.


Meta Tags Example






Hello HTML5!




Page Redirection

You can use tag to redirect your page to any other webpage. You can also specify a duration if you want to redirect the page after a certain number of seconds.

Example

Following is an example of redirecting current page to another page after 5 seconds. If you want to redirect page immediately then do not specify content attribute.


Meta Tags Example






Hello HTML5!




Setting Cookies

Cookies are data, stored in small text files on your computer and it is exchanged between web browser and web server to keep track of various infromation based on your web application need.
You can use tag to store cookies on client side and later this information can be used by the Web Server to track a site visitor.

Example

Following is an example of redirecting current page to another page after 5 seconds. If you want to redirect page immediately then do not specify content attribute.


Meta Tags Example






Hello HTML5!




If you do not include the expiration date and time, the cookie is considered a session cookie and will be deleted when the user exits the browser.
Note: You can check PHP and Cookies tutorial for a complete detail on Cookies.

Setting Author Name

You can set an author name in a web page using meta tag. See an example below:

Example



Meta Tags Example





Hello HTML5!




Specify Character Set

You can use tag to specify character set used within the webpage.

Example

By default, Web servers and Web browsers use ISO-8859-1 (Latin1) encoding to process Web pages. Following is an example to set UTF-8 encoding:


Meta Tags Example






Hello HTML5!




To serve the static page with traditional Chinese characters, the webpage must contain a tag to set Big5 encoding:


Meta Tags Example






Hello HTML5!





9. HTML Comments

 HTML Tutorial

Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.

HTML comments are placed in between tags. So any content placed with-in tags will be treated as comment and will be completely ignored by the browser.

Example



  

Document content goes here..... This will produce following result without displaying the content given as a part of comments:
Document content goes here.....

Valid vs Invalid Comments

Comments do not nest which means a comment can not be put inside another comment. Second 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.

Example

Here given comment is a valid comment and will be wiped off by the browser.




Document content goes here..... 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 not a valid comment --> Document content goes here..... This will produce following result:
< !-- This is not a valid comment --> Document content goes here.....

Multiline Comments

So far we have seen single line comments, but HTML supports multi-line comments as well.
You can comment multiple lines by the special beginning tag placed before the first line and end of the last line as shown in the given example below.

Example


  

Document content goes here..... This will produce following result:
Document content goes here.....

Conditional Comments

Conditional comments only work in Internet Explorer (IE) on Windows but they are ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to give conditional instructions to different versions of IE.

Example


  




Document content goes here..... You will come across a situation where you will need to apply a different style sheet based on different versions of Internet Explorer, in such situation conditional comments will be helpful.

Using Comment Tag

There are few browsers that support tag to comment a part of HTML code.

Example




This is not Internet Explorer. If you are using IE then it will produce following result:
This is Internet Explorer.
But if you are not using IE, then it will produce following result:
This is not Internet Explorer.

Commenting Script Code

Though you will learn Javascript with HTML, in a separate tutorial, but here you must make a note that if you are using Java Script or VB Script in your HTML code then it is recommended to put that script code inside proper HTML comments so that old browsers can work properly.

Example




--> Hello , World! This will produce following result:
Hello World!
Hello , World!

Commenting Style Sheets

Though you will learn using style sheets with HTML in a separate tutorial, but here you must make a note that if you are using Casecading Style Sheet (CSS) in your HTML code then it is recommended to put that style sheet code inside proper HTML comments so that old browsers can work properly.

Example




-->
class="example">Hello , World!
This will produce following result:
Hello , World!

10. HTML Images

 HTML Tutorial

Images are very important to beautify as well as to depict many complex concepts in simple way on your web page. This tutorial will take you through simple steps to use images in your web pages.

Insert Image

You can insert any image in your web page by using tag. Following is the simple syntax to use this tag.
attributes
-list/> The tag is an empty tag, which means that it can contain only list of attributes and it has no closing tag.

Example

To try following example, let's keep our HTML file test.htm and image file test.png in the same directory:


Using Image in Webpage


Simple Image Insert


Test Image


This will produce following result:
Simple Image Insert
Test Image
You can use PNG, JPEG or GIF image file based on your comfort but make sure you specify correct image file name in src attribute. Image name is always case sensitive.
The alt attribute is a mandatory attribute which specifies an alternate text for an image, if the image cannot be displayed.

Set Image Location

Usually we keep our all the images in a separate directory. So let's keep HTML file test.htm in our home directory and create a subdirectory images inside the home directory where we will keep our image test.png.

Example

Assuming our image location is "image/test.png", try the following example:


Using Image in Webpage


Simple Image Insert


Test Image


This will produce following result:
Simple Image Insert
Test Image

Set Image Width/Height

You can set image width and height based on your requirement using width and height attributes. You can specify width and height of the image in terms of either pixels or percentage of its actual size.

Example



Set Image Width and Height


Setting image width and height


Test Image


This will produce following result:
Setting image width and height
Test Image

Set Image Border

By default image will have a border around it, you can specify border thickness in terms of pixels using border attribute. A thickness of 0 means, no border around the picture.

Example



Set Image Border


Setting image Border


Test Image


This will produce following result:
Setting image Border
Test Image

Set Image Alignment

By default image will align at the left side of the page, but you can use align attribute to set it in the center or right.

Example



Set Image Alignment


Setting image Alignment


Test Image


This will produce following result:
Setting image Alignment
Test Image

Free Web Graphics

For Free Web Graphics including patterns you can look into Free Web Graphics

11. HTML Tables

 HTML Tutorial

The HTML tables allow web authors to arrange data like text, images, links, other tables, etc. into rows and columns of cells.
The HTML tables are created using the
tag in which the tag is used to create table rows and tag is used to create data cells.

Example




</span><span class="pln">HTML Tables</span><span class="tag">
border="1"> Row 1, Column 1
Row 1, Column 2 Row 2, Column 1 Row 2, Column 2 This will produce following result:
Row 1, Column 1 Row 1, Column 2
Row 2, Column 1 Row 2, Column 2
Here border is an attribute of
tag and it is used to put a border across all the cells. If you do not need a border then you can use border="0".

Table Heading

Table heading can be defined using tag. This tag will be put to replace
tag, which is used to represent actual data cell. Normally you will put your top row as table heading as shown below, otherwise you can use
element in any row.


Example




</span><span class="pln">HTML Table Header</span><span class="tag">
border="1"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

Cellpadding and Cellspacing Attributes

There are two attribiutes called cellpadding and cellspacing which you will use to adjust the white space in your table cells. The cellspacing attribute defines the width of the border, while cellpadding represents the distance between cell borders and the content within a cell.

Example




</span><span class="pln">HTML Table Cellpadding</span><span class="tag">
border="1" cellpadding="5" cellspacing="5"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

Colspan and Rowspan Attributes

You will use colspan attribute if you want to merge two or more columns into a single column. Similar way you will use rowspan if you want to merge two or more rows.

Example




</span><span class="pln">HTML Table Colspan/Rowspan</span><span class="tag">
border="1"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result:
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1

Tables Backgrounds

You can set table background using one of the following two ways:
  • bgcolor attribute - You can set background color for whole table or just for one cell.
  • background attribute - You can set background image for whole table or just for one cell.
You can also set border color also using bordercolor attribute.

Example




</span><span class="pln">HTML Table Background</span><span class="tag">
border="1" bordercolor="green" bgcolor="yellow"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result:
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1
Here is an example of using background attribute. Here we will use an image available in /images directory.



</span><span class="pln">HTML Table Background</span><span class="tag">
border="1" bordercolor="green" background="/images/test.png"> Column 1
Column 2 Column 3
rowspan="2">Row 1 Cell 1
Row 1 Cell 2Row 1 Cell 3 Row 2 Cell 2Row 2 Cell 3 colspan="3">Row 3 Cell 1
This will produce following result. Here background image did not apply to table's header.
Column 1 Column 2 Column 3
Row 1 Cell 1 Row 1 Cell 2Row 1 Cell 3
Row 2 Cell 2Row 2 Cell 3
Row 3 Cell 1

Table Height and Width

You can set a table width and height using width and height attrubutes. You can specify table width or height in terms of pixels or in terms of percentage of available screen area.

Example




</span><span class="pln">HTML Table Width/Height</span><span class="tag">
border="1" width="400" height="150"> Row 1, Column 1
Row 1, Column 2 Row 2, Column 1 Row 2, Column 2 This will produce following result:
Row 1, Column 1 Row 1, Column 2
Row 2, Column 1 Row 2, Column 2

Table Caption

The caption tag will serve as a title or explanation for the table and it shows up at the top of the table. This tag is depracated in newer version of HTML/XHTML.

Example




</span><span class="pln">HTML Table Caption</span><span class="tag">
border="1" width="100%"> This is the caption
row 1, column 1row 1, columnn 2 row 2, column 1row 2, columnn 2 This will produce following result:
This is the caption
row 1, column 1row 1, columnn 2
row 2, column 1row 2, columnn 2

Table Header, Body, and Footer

Tables can be divided into three portions: a header, a body, and a foot. The head and foot are rather similar to headers and footers in a word-processed document that remain the same for every page, while the body is the main content holder of the table.
The three elements for separating the head, body, and foot of a table are:
  • - to create a separate table header.
  • - to indicate the main body of the table.
  • - to create a separate table footer.
A table may contain several elements to indicate different pages or groups of data. But it is notable that and tags should appear before

Example




</span><span class="pln">HTML Table</span><span class="tag">
border="1" width="100%">
colspan="4">This is the head of the table

colspan="4">This is the foot of the table
Cell 1 Cell 2 Cell 3 Cell 4 This will produce following result:
This is the head of the table
This is the foot of the table
Cell 1 Cell 2 Cell 3 Cell 4

Nested Tables

You can use one table inside another table. Not only tables you can use almost all the tags inside table data tag
.

Example

Following is the example of using another table and other tags inside a table cell.



</span><span class="pln">HTML Table</span><span class="tag">
border="1" width="100%">
border="1" width="100%"> Name
Salary Ramesh Raman 5000 Shabbir Hussein 7000 This will produce following result:
Name Salary
Ramesh Raman 5000
Shabbir Hussein 7000

 
Designed by Kakada Akkarak Surakkiat
Technology: របៀប​ដំឡើង Windows 10 នៅ​លើ​កុំព្យូទ័រ!: អ្នកត្រូវដឹងឲ្យ ច្បាស់ពី Windows ដែលអ្នកយក ទៅដំឡើង ដោយសារមាន Windows ខ្លះមានការ crack រួច ឬខ្លះត្រូវការ Product key ភ្លាម និងខ្លះទៀត អាចត្រូវ skip កន្លែងវាយលេខ Product key បាន តែត្រូវ Activate តាមក្រោយ ទើបប្រើប្រាស់បាន។ Technology: ដំណោះ​ស្រាយ Error 80240020 នៅ​ពេល​តម្លើង Windows 10 Free តាម​រយៈ​ការ Upgrade : មាន បញ្ហាមួយចំនួន ទាក់ទងនឹង ការតម្លើង Windows 10 នេះផងដែរ ប៉ុន្តែបញ្ហានោះ កើតឡើង ទៅលើតែកុំព្យូទ័រ មួយចំនួនប៉ុណ្ណោះ គឺខណៈពេល ដែលអ្នក ប្រើប្រាស់ បានទាញយក Windows 10 ចប់ហើយ វាបាន បង្ហាញនូវ ផ្ទាំង error មួយ ដែលមានលេខ សំគាល់ error នោះគឺ 80240020។ ដូចនេះដើម្បី ដោះស្រាយ នូវបញ្ហា មួយនេះ សូមលោកអ្នក តាមដានអាន ជាមួយយើងខ្ញុំ ទាំងអស់គ្នា !!