HTML
HTML
</body>
</html>
Explanation
The <html> element is the root element of an
HTML page
The <head> element contains meta
information about the document
The <title> element specifies a title for the
document
The <body> element contains the visible
page content
The <h1> element defines a large heading
The <p> element defines a paragraph
HTML basic Tags and Structure
HTML Tags
HTML tags are element names surrounded by angle
brackets:
<tagname>content goes here...</tagname>
Logical vs Physical tags
The differences between logical and physical tags
is one of the fundamental concepts in HTML that,
when understood, can have a huge impact on a web
designer's way of doing things.
Logical Tags:
In HTML there are both logical tags and physical
tags. Logical tags are designed to describe (to the
browser) the enclosed text's meaning. An example of
a logical tag is the <strong> </strong> tag. By
placing text in between these tags you are telling the
browser that the text has some greater importance.
By default all browsers make the text appear bold
when in between the <strong> and </strong> tags,
but the point to take away from this is that the strong
tag implies that importance of that text.
Logical vs Physical tags
Physical Tags:
Physical tags on the other hand provide specific
instructions on how to display the text they
enclose. Examples of physical tags include:
<b> : Makes the text bold.
<big> : Makes the text usually one size bigger
than what's around it.
<font> : Used to apply a font-face (like Arial or
Helvetica) and font-color.
<i> : Makes text italic.
Physical tags are more straightforward; <i>
makes the text italic, <b> makes text bold and
<font> is used to set the font face and color for
the text.
HTML Formatting Tags
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.
Header - <h?> </h?> There are 6 levels of headings
available, from h1 for the largest and most important
heading, down to h6 for the smallest heading.
Bold - <b> </b> The text in between the tags will be
bold, and stand out against text around it, the same as
in a word processor.
Italic - <i> </i> Also working the same way as a word
processor, italics displays the text at a slight angle.
Underline - <u> </u> Again, the same as underline in
a word processor.
White Space and Flow
With only a few exceptions, HTML treats
whitespace characters (spaces, tabs, and
newlines) differently from ordinary characters.
In general, a single whitespace character–
including newlines–or a sequence of
whitespace characters are treated as a single
space and leading/trailing whitespace is
eliminated. This is known as ‘collapsing
whitespace’. Therefore the following two
paragraphs are treated as if they were identical
Normal flow is the way that elements are
displayed in a Web page in most circumstances.
All elements in HTML are inside boxes which
are either inline boxes or block boxes.
Heading.
The <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>
elements are used to create headings in descending
order of importance where <h1> is the most
important and <h6> the least. It add one line before
and after in each heading.
Search engines use the headings to index the
structure and content of your web pages.
<h1>Heading level 1</h1>
<h2>Heading level 2</h2>
<h3>Heading level 3</h3>
<h4>Heading level 4</h4>
<h5>Heading level 5</h5>
<h6>Heading level 6</h6>
Paragraph Tag
The <p> tag defines a paragraph.
Browsers automatically add some space
(margin) before and after each <p> element.
The HTML <p> element represents a
paragraph of text. Paragraphs are usually
represented in visual media as blocks of text
that are separated from adjacent blocks by
vertical blank space and/or first-line
indentation.
Tag Description
<p> Defines a paragraph
<br> Inserts a single line break
<pre> Defines pre-formatted text
<p>
This paragraph
contains a lot of lines
in the source code,
but the browser
ignores it.
</p>
<p>
This paragraph
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
Break Line Tag
The HTML <br> element produces a line
break in text (carriage-return). It is useful for
writing a poem or an address, where the
division of lines is significant.
Permitted content:- None, it is an
empty element.
Tag omission:- Must have a start tag, and must
not have an end tag. In XHTML documents,
write this element as <br />.
Mozilla Foundation<br />
1981 Landings Drive<br />
Building K<br />
Mountain View, CA 94043-0801<br />
USA
Center Tag
The HTML <center> tag is used for
centering the content enclosed with
this tag. It can be in side body, table
cell.
<p>not center this paragraph.</p>
<center>This text will be centered.
<p>So will this paragraph.</p>
</center>
Body and its Attributes
The <body> element may be the
most important HTML element there
is. The contents of the <body>
element are what actually get
displayed to the user visiting your
web page or viewing your document.
And yet, it is very simple. The
<body> must be a direct child of
<html>, it must come after <head>
(if <head> is present, which it
doesn’t have to be), there can be
Attribute
Attribute Value Description
Specifies the color of an active link in a
alink color
document
Specifies a background image for a
background URL
document
Specifies the background color of a
bgcolor color
document
Specifies the color of unvisited links in a
link color
document
Specifies the color of the text in a
text color
document
Specifies the color of visited links in a
vlink color
document
Example
<html>
<head>
<title>Body tags</title>
</head>
</body>
</html>
Marquee Tag
The HTML <marquee> element is used to insert a
scrolling area of text. You can control what happens
when the text reaches the edges of its content area
using its attributes.
Attributes
behavior Sets how the text is scrolled within the
marquee. Possible values are scroll, slide and alternate.
If no value is specified, the default value is scroll.
bgcolor Sets the background color through color name
or hexadecimal value.
direction Sets the direction of the scrolling within the
marquee. Possible values are left, right, up and down. If
no value is specified, the default value is left.
height Sets the height in pixels or percentage value.
hspace Sets the horizontal margin
Marquee Tag
loop Sets the number of times the marquee will
scroll. If no value is specified, the default value is
−1, which means the marquee will scroll
continuously.
scrollamount Sets the amount of scrolling at each
interval in pixels. The default value is 6.
scrolldelay Sets the interval between each scroll
movement in milliseconds. The default value is 85.
Note that any value smaller than 60 is ignored and
the value 60 is used instead, unless truespeed is
specified.
width Sets the width in pixels or percentage value.
But not supported by many browser.
Example
<marquee>This text will scroll from right to
left</marquee>
<marquee direction="up">This text will scroll
from bottom to top</marquee>
<marquee direction="down" width="250"
height="200" behavior="alternate"
style="border : solid">
<marquee behavior="alternate"> This text will
bounce </marquee>
</marquee>
HTML Comments
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.
HTML Comments
Valid vs Invalid Comments
Comments do not nest which means a comment
cannot 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.
<html>
<head> <title>Valid Comment Example</title>
</head>
<body> <!-- This is valid comment -->
<p>Document content goes here.....</p>
</body> </html>
Multiline Comments
<html>
<head>
You can comment <title>Multiline
multiple lines by Comments</title>
</head>
the special
beginning tag <!-- <body>
<!--
and ending tag -- This is a multiline comment
> placed before and it can
the first line and span through as many as
lines you like.
end of the last line -->
as shown in the
<p>Document content goes
given example here.....</p>
below. </body>
</html>
The HTML <hr> tag is used for creating a
horizontal line. This is also called Horizontal
Rule in HTML that act as divider between
sections.
Horizontal rule does not have a closing tag.
Attribute Value Description
left
align center Specifies the alignment of a <hr> element
right
Specifies that a <hr> element should render in
noshade noshade one solid color (noshaded), instead of a shaded
color
size pixels Specifies the height of a <hr> element
pixels
width Specifies the width of a <hr> element
%
Red, blue,
color Set shade of Horizontal line
#000FFF etc
HTML Formatting Tags
Bold Text
Anything that appears within <b>...</b> element.
Italic Text
Anything that appears within <i>...</i> element is
displayed in italicized.
Underlined Text
Anything that appears within <u>...</u> element,
is displayed with underline.
Strike Text
Anything that appears within <strike>...</strike>
element is displayed with strikethrough, which is a
thin line through the text
HTML Formatting Tags
Monospaced Font
The content of a <tt>...</tt> 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.
Superscript Text
The content of a <sup>...</sup> 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.
HTML Formatting Tags
Subscript Text
The content of a <sub>...</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.
Inserted Text
Anything that appears within <ins>...</ins>
element is displayed as inserted text.
Deleted Text
Anything that appears within <del>...</del>
element, is displayed as deleted text.
HTML Formatting Tags
Larger Text
The content of the <big>...</big> element
is displayed one font size larger than the rest
of the text surrounding
Smaller Text
The content of the <small>...</small>
element is displayed one font size smaller
than the rest of the text surrounding
Phrase Tags
Strong Text
The HTML <strong> tag gives text a strong emphasis
which traditionally means that the text is displayed as bold
by the browser.
Anything that appears within <strong>...</strong>
element is displayed as important text.
Text Abbreviation
You can abbreviate a text by putting it inside opening
<abbr> and closing </abbr> tags. If present, the title
attribute must contain this full description and nothing else.
Acronym Element
The <acronym> element allows you to indicate that the
text between <acronym> and </acronym> tags is an
acronym.
At present, the major browsers do not change the
appearance of the content of the <acronym> element.
Phrase Tags
Quoting Text
When you want to quote a passage from another source,
you should put it in between <quote>...</quote> tags.
Text inside a <quote> element is usually indented from
the left and right edges of the surrounding text, and
sometimes uses an italicized font.
The HTML <blockquote> tag is used for indicating long
quotations (i.e. quotations that span multiple lines).
Emphasized Text
The HTML <em> tag marks text that has stress
emphasis which traditionally means that the text is
displayed in italics by the browser.
Anything that appears within <em>...</em> element is
displayed as emphasized text.
Phrase Tags
Abbreviation
An abbreviation and an acronym are both shortened
versions of something else. Both are often
represented as a series of letters.
Marking up abbreviations can give useful information
to browsers, translation systems and search-engines.
Acronym
The HTML Acronym Element (<acronym>) allows
authors to clearly indicate a sequence of characters
that compose an acronym or abbreviation for a word.
The HTML <acronym> tag is used for indicating an
acronym.
Phrase Tags
Blockquote
The <blockquote> element defines a block of
text that is a direct quotation. The <quote>
element should be used when a quotation is
presented inline with the surrounding text, but
when the quotation is presented as a separate
paragraph, <blockquote> is the appropriate
element to use to identify the quotation.
The HTML <blockquote> tag is used for
indicating long quotations (i.e. quotations that
span multiple lines).
Phrase Tags
Grouping Content
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 <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 <span> 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 <span> element as follows.
<abbr title="HyperText Markup
Language">HTML</abbr>
<p>The <acronym title="World Wide
Web">WWW</acronym> is only a component of the
Internet.</p>
<blockquote><p>This is a longer block quote.</p>
<p>It uses paragraph elements.</p>
</blockquote>
<p><em>Stress emphasized text goes
here</em></p>
<p>WWF's goal is to:
<q>Build a future where people live in harmony
with nature.</q>
We hope they succeed.</p>
HTML Lists
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.
HTML Unordered Lists
An unordered list is a collection of related
items that have no special order or
sequence. This list is created by using
HTML <ul> tag. Each item in the list is
marked with a bullet.
<body>
<ul> <li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li> </ul>
</body>
The type Attribute
You can use type attribute for <ul> tag to
specify the type of bullet you like. By
default, it is a disc. Following are the
possible options −
<ul type = "square">
<ul type = "disc">
<ul type = "circle">
HTML Ordered Lists
If you are required to put your items in a
numbered list instead of bulleted, then HTML
ordered list will be used. This list is created by
using <ol> tag. The numbering starts at one and
is incremented by one for each successive ordered
list element tagged with <li>.
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
The type Attribute
You can use type attribute for <ol> tag to
specify the type of numbering you like. By
default, it is a number. Following are the
possible options −
<ol type = "1"> - Default-Case Numerals.
<ol type = "I"> - Upper-Case Numerals.
<ol type = "i"> - Lower-Case Numerals.
<ol type = "A"> - Upper-Case Letters.
<ol type = "a"> - Lower-Case Letters.
The start Attribute
You can use start attribute for <ol> tag to specify
the starting point of numbering you need.
Following are the possible options −
<ol type = "1" start = "4"> - Numerals starts with
4.
<ol type = "I" start = "4"> - Numerals starts with
IV.
<ol type = "i" start = "4"> - Numerals starts with
iv.
<ol type = "a" start = "4"> - Letters starts with d.
<ol type = "A" start = "4"> - Letters starts with D.
HTML Definition Lists
HTML and XHTML supports a list style
which is called definition lists where
entries are listed like in a dictionary or
encyclopedia. The definition list is the ideal
way to present a glossary, list of terms, or
other name/value list.
Definition List makes use of following three
tags.
<dl> − Defines the start of the list
<dt> − A term
<dd> − Term definition
</dl> − Defines the end of the list
Example
<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 - Fonts
Fonts play a very important role in making a
website more user friendly and increasing content
readability. Font face and color depends entirely
on the computer and browser that is being used
to view your page but you can use
HTML <font> tag to add style, size, and color to
the text on your website. You can use
a <basefont> tag to set all of your text to the
same size, face, and color.
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 webpage, simply use the <font> tag.
The text that follows will remain changed until
you close with the </font> tag.
Set Font Size
You can set content font size using size attribute.
The range of accepted values is from 1(smallest) to
7(largest). The default size of a font is 3.
<body>
<font size = "1">Font size = "1"</font><br />
<font size = "2">Font size = "2"</font><br />
<font size = "3">Font size = "3"</font><br />
<font size = "4">Font size = "4"</font><br />
<font size = "5">Font size = "5"</font><br />
<font size = "6">Font size = "6"</font><br />
<font size = "7">Font size = "7"</font>
</body>
Relative Font Size
You can specify how many sizes larger or how
many sizes smaller than the preset font size
should be. You can specify it like <font size =
"+n"> or <font size = "−n">
<body>
<font size = "-1">Font size =
"-1"</font><br />
<font size = "+1">Font size =
"+1"</font><br />
<font size = "+2">Font size =
"+2"</font><br />
<font size = "+3">Font size =
"+3"</font><br />
<font size = "+4">Font size = "+4"</font>
Setting Font Face
You can set font face using face attribute but be aware
that if the user viewing the page doesn't have the font
installed, they will not be able to see it. Instead user will
see the default font face applicable to the user's
computer.
<body>
<font face = "Times New Roman" size = "5">Times
New Roman</font><br />
<font face = "Verdana" size =
"5">Verdana</font><br />
<font face = "Comic sans MS" size =" 5">Comic Sans
MS</font><br />
<font face = "WildWest" size =
"5">WildWest</font><br />
<font face = "Bedrock" size =
"5">Bedrock</font><br />
Specify alternate font faces
A visitor will only be able to see your font if
they have that font installed on their computer.
So, it is possible to specify two or more font
face alternatives by listing the font face names,
separated by a comma.
<font face = "arial, helvetica">
<font face = "Lucida Calligraphy, Comic Sans
MS, Lucida Console">
When your page is loaded, their browser will
display the first font face available. If none of
the given fonts are installed, then it will display
the default font face Times New Roman.
Setting 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.
<body>
<font color = "#FF00FF">This text is in
pink</font><br />
<font color = "red">This text is red</font>
</body>
The <basefont> Element
The <basefont> element is supposed to set a
default font size, color, and typeface for any
parts of the document that are not otherwise
contained within a <font> tag. You can use
the <font> elements to override the
<basefont> settings.
The <basefont> tag also takes color, size and
face attributes and it will support relative
font setting by giving size a value of +1 for a
size larger or −2 for two sizes smaller.
HTML Images and Links
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 <img> tag. Following is the simple
syntax to use this tag.
<img src = "Image URL" Attr_name=
"Attr_value" ... attributes-list />
Attribute Value Description
<tfoot>
<tr>
<td colspan = "4">This is the foot of the
table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
HTML Frames
Frames allow you to have multiple sections of the
browser window, called frames, each showing their
own .html file within the frame. This used to be
common practice when trying to show separate
sections of a site in separate sections of the browser
window, such as a header at the top, navigation at
the side, and the rest was page content that
someone could scroll down without making the
header and navigation disappear.
Frame sets are rarely used these days, as the
introduction of server side scriping languages such
as php and asp allow you to create content pages
dynamically. The introduction of HTML5 has also
provided new methods of doing page layouts without
having to use frames.
Frame Set - <frameset>
Used instead of the body tag, the frameset tag
defines a group of frames. Setting
the rows and cols attribute allow you to create the
number of frames needed for your layout.
rows="??,??" - To set up multiple frames in rows,
replace the question marks by the size of each row,
either in pixels or as a percentage. A * can be used
as a wild card, for instance: rows="100,*" would
give you a top frame of 100 pixels high, and a
bottom frame using the rest of the screen.
cols="??,??" - Similar to rows, a number of frames
can be set out in columns.
border="?" - Frame border thickness in pixels.
bordercolor="?" - Colour of border between frames.
Frame - <frame>
Each frame within a set will need a frame tag to
tell it which web page to load in the frame. It
uses the attribute:
src="url" - Filename or URL of page to show in
the frame
noresize="noresize" - The frame will not be able
to be resized by a visitor
scrolling="auto" - Each frame will have vertical
and horizontal scroll bars appear automatically
when needed. You can change this by setting
the scrolling attribute to yes, no, or auto.
frameborder="auto" - Individual Frame Border.
Set to 0, 1 to specify whether or not that frame
must have a border.
Unframed Content - <noframes>
Very old browsers are unable to display
frames, and in this case we need to specify
what these browsers should display instead of
the frames. Even though this is not much of a
problem anymore, it is still suggested that
you specify unframed content when using
frames. Anything between the noframes tags
will not be shown in modern browsers that
show framed content.
<html>
<head>
<title>Example - Frames</title>
</head>
<frameset rows="100,*">
<frame name="top" src="frames_top.html">
<frameset cols="50,*,50">
<frame name="left" src="frames_left.html">
<frame name="mid"
src="frames_middle.html">
<frame name="right"
src="frames_right.html">
</frameset>
<noframes>
<i>error to display to those who cannot see
frames</i>
</noframes>
<frameset cols="*,*,*">
<frame
src="frame_1.html">
<frameset rows="*,*">
<frame
src="frame_2.html">
<frame
src="frame_3.html">
</frameset>
<frameset cols="*,*">
<frame
<frame src="frame_1.html">
src="frame_4.html">
<frameset rows="*,*">
</frameset>
<frame src="frame_2.html">
<frameset cols="*,*">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</frameset>
</frameset>
IFrame (Inline Frame)
An IFrame (Inline Frame) is an HTML document
embedded inside another HTML document on a
website. The IFrame HTML element is often used
to insert content from another source, such as an
advertisement, into a Web page.
Iframe – set source
The src attribute specifies the URL(web address) of
the inline frame page.
Iframe – set Height and Width
Use to height and width attribute to specify the size
of the iframe.
The attribute value are specifies in pixels by
default, but they can also be in percent(like “80%”)
Examples
<iframe src="demo_iframe.htm" height="20
0" width="300"></iframe>
Iframe - Remove the Border
By default, an iframe has a border around it.
<iframe width="560" height="315"
src="https://www.youtube.com/embed/owsfdh
4gxyc" frameborder="0"
allowfullscreen></iframe>
HTML Layer
The HTML <layer> tag is used to position
and animate (through scripting) elements in
the page. A layer can be through of as a
separate document that reside on the top of
the main one, all existing within one
windows.
The tag has support in Netscape 4 and
higher versions of it.
Example
<body>
<layer id=“layer1” top=“250” lift=“50” width=“200”
height=“ 200” bgcolor=“red”>
<p> layer 1</p>
</layer>
<layer id=“layer2” top=“350” lift=“150” width=“200”
height=“ 200” bgcolor=“blue”>
<p> layer 2</p>
</layer>
<layer id=“layer3” top=“450” lift=“200” width=“200”
height=“ 200” bgcolor=“green”>
<p> layer 3</p>
</layer>
Layer Attributes
Attribut Value Description
e
Above Layer The name of the inline layer that will
name be position directly above the current
layer in Z-order.