HTML Notes
HTML Notes
HTML or Hypertext Markup Language, is the most widely used language on Web.
Technically, HTML is not a programming language, but rather a markup language.
This tutorial gives a complete understanding on HTML.
Before you begin, it's important that you know Windows or Unix. A working knowledge
of Windows or Unix makes it much easier to learn HTML.
Introducing HTML:
HTML stands for Hypertext Markup Language, and it is the most widely used language to
write Web Pages. As its name suggests, HTML is a markup language.
Hypertext refers to the way in which Web pages (HTML documents) are
linked together. When you click a link in a Web page, you are using hypertext.
Markup Language describes how HTML works. With a markup language, you
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.
All you need to do to use HTML is to learn what type of markup to use to get the results
you want.
<html>
<head>
<title>This is document title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>Document description goes here.....</p>
</body>
</html>
Now you have created one HTML page and you can use a Web Browser to open this HTML
file to see the result. Hope you understood that Web Pages are nothing but they are simple
HTML files with some content which can be rendered using Web Browsers.
Here <html>, <head>,...<p>, <h1> etc. are called HTML tags. HTML tags are building blocks
of an HTML document nd we will learn all the HTML tags in subsequent chapters.
NOTE: One HTML file can have extension as .htm or .html. So you can use either of them
based on your comfort.
An HTML document starts and ends with <html> and >/html> tags. These tags tell the
browser that the entire document is composed in HTML. Inside these two tags, the document
is split into two sections:
Every tag consists of a tag name, sometimes followed by an optional list of tag attributes ,
all placed between opening and closing brackets (< and >). The simplest tag is nothing more
than a name appropriately enclosed in brackets, such as <head> and <i>. More complicated
tags contain one or more attributes , which specify or modify the behaviour of the tag.
According to the HTML standard, tag and attribute names are not case-sensitive. There's
no difference in effect between <head>, <Head>, <HEAD>, or even <HeaD>; they are all
equivalent. But with XHTML, case is important: all current standard tag and attribute names
are in lowercase.
HTML is Forgiving?
A very good quality associated with all the browsers is that they would not give any error if
you have not put any HTML tag or attribute properly. They will just ignore that tag or
attribute and will apply only correct tags and attributes before displaying the result.
We cann ot say, HTML is forgiving because this is just a markup language and required
to format documents.
HTML Basic Tags
The basic structure for all HTML documents is simple and should include the following
minimum elements or tags:
Remember that before an opening <html> tag, an XHTML document can contain the
optional XML declaration, and it should always contain a DOCTYPE declaration indicating
which version of XHTML it uses.
Now we will explain each of these tags one by one. In this tutorial you will find the
terms element and tag are used interchangeably.
Each <head> element should contain a <title> element indicating the title of the
document.
You should specify a title for every page that you write inside the <title> element. This
element is a child of the <head> element). It is used in several ways:
Therefore it is important to use a title that really describes the content of your site. The
<title> element should contain only the text for the title and it may not contain any other
elements.
Example:
<head>
<title>HTML Basic tags</title>
</head>
The <body> Element:
The <body> element appears after the <head> element and contains the part of the Web page
that you actually see in the main browser window, which is sometimes referred to as
body content.
A <body> element may contain anything from a couple of paragraphs under a heading to
more complicated layouts containing forms and tables.
Most of what you will be learning in this and the following five chapters will be written
between the opening <body> tag and closing </body> tag.
Example:
<body>
<p>This is a paragraph tag.</p>
</body>
<html>
<head>
<title>HTML Basic tags</title>
</head>
<body>
<p>This is a paragraph tag.</p>
</body>
</html>
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 you can use to indicate
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:
Many HTML tags have a unique set of their own attributes. These will be discussed as each
tag is introduced throughout the tutorial. Right now we want to focus on a set of generic
attributes that can be used with just about every HTML Tag in existence.
Generic Attributes:
Here's a table of some other attributes that are readily usable with many of HTML's tags.
valign top, middle, bottom Vertically aligns tags within an HTML element.
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.
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 <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:
This is heading 4
This is heading 5
This is heading 6
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 <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>
Mahnaz
Thanks
Mahnaz
Example:
<pre>
*
* *
* * *
</pre>
*
* *
* * *
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:
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
Anything that appears in a <b>...</b> element is displayed in bold, like the word bold here:
Anything that appears in a <i>...</i> element is displayed in italicized, like the word
italicized here:
Anything that appears in a <u>...</u> element is displayed with underline, like the
word underlined here:
superscript
The following word uses a 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 character.s height beneath the other
characters.
The content of the <big> element is displayed one font size larger than the rest of the
text surrounding it.
The content of the <small> element is displayed one font size smaller than the rest of the
text surrounding it.
While some of these phrase elements are displayed in a similar manner to the <b>, <i>,
<pre>, and <tt> elements you have already seen, they are designed for specific purposes.
For example, the <em> and <strong> elements give text emphasis and strong emphasis
respectively and there are several elements for marking up quotes.
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:
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.
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.
But following line is not a valid comment and will be displayed by the borwser. This is
because there is a space between the left angle bracket and the exclamation mark.
Be careful if you use comments to "comment out" HTML that would otherwise be shown to
the user, since some older browsers will still pay attention to angle brackets inside the
comment and close the comment prematurely -- so that some of the text that was supposed
to be inside the comment mistakenly appears as part of the document.
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.
-->
There are few browsers who supports <comment> tag to comment a part of code.
Font face and color depends entirely on the computer and browser that is being used to
view your page. But the <font> tag is used to add style, size, and color to the text on your
site. The font tag is having three attributes called size, color, and face to customize your fonts.
To change any of the font attributes at any time within your page, simply use the <font>
tag. The text that follows will remain changed until you close with the </font> tag. You can
change any or all of the font attributes at the one time, by including all the required changes
within the one <font> tag.
Font Size:
You can set the size of your font with size attribute. The range of accepted values is
from 1(smallest) to 7(largest). The default size of a font is 3.
Example:
Font size="1"
Font size="2"
Font size="3"
Font size="4"
Font size="5"
Font size="6"
Font size="7"
SPECIFY THE RELATIVE FONT SIZE. <font size="+n"> or <font size="-n">: You can
specify how many sizes larger or how many sizes smaller than the preset font size should
be.
Example:
Font Color:
You can set any font color you like using color attribute. You can specify the color that you
want by either the color name or hexadecimal code for that color.
Example:
<font color="#FF00FF">This text is hexcolor #FF00FF</font>
<font color="red">This text is red</font>
Image Attributes:
Following are most frequently used attributes for <img> tag.
width: sets width of the image. This will have a value like 10 or 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.
title: specifies a text title. The browser, perhaps flashing the title when the
mouse passes over the link.
A Simple Example:
<img src="apple.jpg" alt="HTML Tutorial" />
<img src=" apple.jpg " alt="Apple Image" width="100" height="100" border="2" align="right"
title="Apple" />
A link is specified using the <a> element. This element is called anchor tag as well. Anything
between the opening <a> tag and the closing </a> tag becomes part of the link and a user
can click that part to reach to the linked document.
A Simple Example:
This will produce following result, Click and come back to proceed with rest of the tutorial:
You can create text link to make your PDF, or DOC or ZIP files downloadable. This is
very simple; you just need to give complete URL of the downloadable file as follows:
This will produce following link and will be used to download a file.
Download File
HTML Tables
Tables are very useful to arrange in HTML and they are used very frequently by almost all
web developers. Tables are just like spreadsheets and they are made up of rows and columns.
You will create a table in HTML/XHTML by using <table> tag. Inside <table> element the
table is written out row by row. A row is contained inside a <tr> tag . which stands for table
row. And each cell is then written inside the row element using a <td> tag . which stands for
table data.
Example:
<table border="1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
</tr>
</table>
NOTE: In the above example border is an attribute of <table> and it will put border across
all the cells. If you do not need a border, then you can use border="0". The border attribute
and other attributes also mentioned din this session are deprecated and they have been
replaced by CSS. So it is recommended to use CSS instead of using any attribute directly.
<table border="1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>
<tr>
<td>Shabbir Hussein</td>
<td>7000</td>
</tr>
</table>
This will produce following result. You can see its making heading as a bold one:
Name Salary
NOTE: Each cell must, however, have either a <td> or a <th> element in order for the table
to display correctly even if that element is empty.
There are two attribiutes called cellpadding and cellspacing which you will use to adjust
the white space in your table cell. Cellspacing defines the width of the border, while
cellpadding represents the distance between cell borders and the content within. Following
is the example:
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.
Following is the example:
<table border="1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr><td rowspan="2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td><td>Row 1 Cell 3</td></tr>
<tr><td>Row 2 Cell 2</td><td>Row 2 Cell 3</td></tr>
<tr><td colspan="3">Row 3 Cell 1</td></tr>
</table>
Tables Backgrounds
You can set table background using of the following two ways:
Using bgcolor attribute - You can set background color for whole table or just for
one cell.
Using background attribute - You can set background image for whole table or just
for one cell.
NOTE: You can set border color also using bordercolor attribute.
You can set a table width and height using width and height attrubutes. You can specify
table width or height in terms of integer value or in terms of percentage of available
screen area. Following is the example:
The caption tags will serve as a title or explanation and show up at the top of the table. This
tag is deprecated in newer version of HTML/XHTML.
<table border="1">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
</table>
HTML Colors
Colors are very important to give a good look and feel to your website. You can specify
colors on page level using <body> tag or you can set colors for individual tags.
The <body> tag has following attributes which can be used to set different colors:
There are following three different methods to set colors in your web page:
Color names: You can specify color names directly like green, blue or red.
Hex codes: A six-digit code representing the amount of red, green, and blue that
make up the color.
Here is the list of W3C Standard 16 Colors names and it is recommended to use them.
Each hexadecimal code will be preceded by a pound or hash sign #. Following are the
examples to use Hexadecimal notation.
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
HTML offers web authors three ways for specifying lists of information. All lists must contain one or
more list elements. Lists may contain:
<ul> - An unordered list. This will list items using plain bullets.
<ol> - An ordered list. This will use different schemes of numbers to list your items.
<dl> - A definition list. This arranges your items in the same way as they are arranged in a
dictionary.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
<ul type="square">
<ul type="disc">
<ul type="circle">
Example
Following is an example where we used <ul type="square">
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="square">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
Example
Following is an example where we used <ul type="disc"> :
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="disc">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Beetroot
Ginger
Potato
Radish
Example
Following is an example where we used <ul type="circle"> :
<!DOCTYPE html>
<html>
<head>
<title>HTML Unordered List</title>
</head>
<body>
<ul type="circle">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ul>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
Example
Following is an example where we used <ol type="1">
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="1">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
1. Beetroot
2. Ginger
3. Potato
4. Radish
Example
Following is an example where we used <ol type="I">
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="I">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
I. Beetroot
II. Ginger
III. Potato
IV. Radish
Example
Following is an example where we used <ol type="i">
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="i">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
i. Beetroot
ii. Ginger
iii. Potato
iv. Radish
Example
Following is an example where we used <ol type="A">
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="A">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
A. Beetroot
B. Ginger
C. Potato
D. Radish
Example
Following is an example where we used <ol type="a">
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="a">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
a. Beetroot
b. Ginger
c. Potato
d. Radish
Example
Following is an example where we used <ol type="i" start="4" >
<!DOCTYPE html>
<html>
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol type="i" start="4">
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
iv. Beetroot
v. Ginger
vi. Potato
vii. Radish
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Definition List</title>
</head>
<body>
<dl>
<dt><b>HTML</b></dt>
<dd>This stands for Hyper Text Markup Language</dd>
<dt><b>HTTP</b></dt>
<dd>This stands for Hyper Text Transfer Protocol</dd>
</dl>
</body>
</html>