Unit2 Final Notes
Unit2 Final Notes
Example
<!DOCTYPE html>
<html>
<head>
<title>Nested Elements Example</title>
</head>
<body>
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
</body>
</html>
This will display the following result –
HTML - Attributes
We have seen few HTML tags and their usage like heading tags <h1>,
<h2>, paragraph tag <p> 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 <p> 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
<!DOCTYPE html>
<html>
<head>
<title>Align Attribute Example</title>
</head>
<body>
<p align = "left">This is left aligned</p>
<p align = "center">This is center aligned</p>
<p align = "right">This is right aligned</p>
</body>
</html>
This will display the following result –
HTML - Basic Tags
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 <h1>, <h2>, <h3>, <h4>, <h5>, and <h6>. While
displaying any heading, browser adds one line before and one line after
that heading.
Example
<!DOCTYPE html>
<html>
<head>
<title>Heading Example</title>
</head>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
This will produce the following result –
Paragraph Tag
The <p> tag offers a way to structure your text into different paragraphs.
Each paragraph of text should go in between an opening <p> and a
closing </p> tag as shown below in the example −
Example
<!DOCTYPE html>
<html>
<head>
<title>Paragraph Example</title>
</head>
<body>
<p>Here is a first paragraph of text.</p>
<p>Here is a second paragraph of text.</p>
<p>Here is a third paragraph of text.</p>
</body>
</html>
This will produce the following result –
Line Break Tag
Whenever you use the <br /> 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 <br /> 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
<br> it is not valid in XHTML.
Example
<!DOCTYPE html>
<html>
<head>
<title>Line Break Example</title>
</head>
<body>
<p>Hello<br />
You delivered your assignment ontime.<br />
Thanks<br />
Mahnaz</p>
</body>
</html>
This will produce the following result –
Centering Content
You can use <center> tag to put any content in the center of the page or
any table cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>Centring Content Example</title>
</head>
<body>
<p>This text is not in the center.</p>
<center>
<p>This text is in the center.</p>
</center>
</body>
</html>
This will produce following result –
Horizontal Lines
Horizontal lines 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 in
the given example below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Horizontal Line Example</title>
</head>
<body>
<p>This is paragraph one and should be on top</p>
<hr />
<p>This is paragraph two and should be at bottom</p>
</body>
</html>
This will produce the following result –
Again <hr /> 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 <hr /> element has a space between the characters hr and the
forward slash. If you omit this space, older browsers will have trouble
rendering the horizontal line, while if you miss the forward slash character
and just use <hr> 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 these cases, you can use the
preformatted tag <pre>.
Any text between the opening <pre> tag and the closing </pre> tag will
preserve the formatting of the source document.
Example
<!DOCTYPE html>
<html>
<head>
<title>Preserve Formatting Example</title>
</head>
<body>
<pre>
function testFunction( strText ){
alert (strText)
}
</pre>
</body>
</html>
This will produce the following result –
Try using the same code without keeping it inside <pre>...</pre> 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
<!DOCTYPE html>
<html>
<head>
<title>Nonbreaking Spaces Example</title>
</head>
<body>
<p>An example of this technique appears in the movie
"12 Angry Men."</p>
</body>
</html>
This will produce the following result –
Example
<!DOCTYPE html>
<html>
<head>
<title>Bold Text Example</title>
</head>
<body>
<p>The following word uses a <b>bold</b> typeface.</p>
</body>
</html>
This will produce the following result –
Italic Text
Anything that appears within <i>...</i> element is displayed in italicized
as shown below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Italic Text Example</title>
</head>
<body>
<p>The following word uses an <i>italicized</i> typeface.</p>
</body>
</html>
This will produce the following result –
Underlined Text
Anything that appears within <u>...</u> element, is displayed with
underline as shown below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Underlined Text Example</title>
</head>
<body>
<p>The following word uses an <u>underlined</u> typeface.</p>
</body>
</html>
This will produce the following result –
Strike Text
Anything that appears within <strike>...</strike> element is displayed
with strikethrough, which is a thin line through the text as shown below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Strike Text Example</title>
</head>
<body>
<p>The following word uses a <strike>strikethrough</strike>
typeface.</p>
</body>
</html>
This will produce the following result –
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>Monospaced Font Example</title>
</head>
<body>
<p>The following word uses a <tt>monospaced</tt> typeface.</p>
</body>
</html>
This will produce the following result –
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>Superscript Text Example</title>
</head>
<body>
<p>The following word uses a <sup>superscript</sup> typeface.</p>
</body>
</html>
This will produce the following result –
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>Subscript Text Example</title>
</head>
<body>
<p>The following word uses a <sub>subscript</sub> typeface.</p>
</body>
</html>
This will produce the following result –
Inserted Text
Anything that appears within <ins>...</ins> element is displayed as
inserted text.
Example
<!DOCTYPE html>
<html>
<head>
<title>Inserted Text Example</title>
</head>
<body>
<p>I want to drink <del>cola</del> <ins>pepsy</ins></p>
</body>
</html>
This will produce the following result –
I want to drink cola pepsy
Deleted Text
Anything that appears within <del>...</del> element, is displayed as
deleted text.
Example
<!DOCTYPE html>
<html>
<head>
<title>Deleted Text Example</title>
</head>
<body>
<p>I want to drink <del>cola</del> <ins>pepsy</ins></p>
</body>
</html>
This will produce the following result –
I want to drink cola pepsy
Larger Text
The content of the <big>...</big> element is displayed one font size
larger than the rest of the text surrounding it as shown below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Larger Text Example</title>
</head>
<body>
<p>The following word uses a <big>big</big> typeface.</p>
</body>
</html>
This will produce the following result –
Smaller Text
The content of the <small>...</small> element is displayed one font
size smaller than the rest of the text surrounding it as shown below −
Example
<!DOCTYPE html>
<html>
<head>
<title>Smaller Text Example</title>
</head>
<body>
<p>The following word uses a <small>small</small> typeface.</p>
</body>
</html>
This will produce the following result –
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>Div Tag Example</title>
</head>
<body>
<div id = "menu" align = "middle" >
<a href = "/index.htm">HOME</a> |
<a href = "/about/contact_us.htm">CONTACT</a> |
<a href = "/about/index.htm">ABOUT</a>
</div>
<div id = "content" align = "left" >
<h5>Content Articles</h5>
<p>Actual content goes here.....</p>
</div>
</body>
</html>
This will produce the following result –
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.
Example
<!DOCTYPE html>
<html>
<head>
<title>Span Tag Example</title>
</head>
<body>
<p>This is the example of <span style = "color:green">span
tag</span>
and the <span style = "color:red">div tag</span> alongwith CSS</p>
</body>
</html>
This will produce the following result –
These tags are commonly used with CSS to allow you to attach a style to a
section of a page.
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 using bgcolor attribute.
The <body> tag has following attributes which can be used to set
different colors −
bgcolor − sets a color for the background of the page.
text − sets a color for the body text.
alink − sets a color for active links or selected links.
link − sets a color for linked text.
vlink − sets a color for visited links − that is, for linked text
that you have already clicked on.
HTML Color Coding Methods
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 makes up the color.
Color decimal or percentage values − This value is
specified using the rgb( ) property.
HTML Colors - Color Names
You can specify direct a color name to set text or background color. W3C
has listed 16 basic color names that will validate with an HTML validator
but there are over 200 different color names supported by major
browsers.
Note − Check a complete list of HTML Color Name.
W3C Standard 16 Colors
Here is the list of W3C Standard 16 Colors names and it is recommended
to use them.
Example
Here are the examples to set background of an HTML tag by color name −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Name</title>
</head>
</html>
#000000
#FF0000
#00FF00
#0000FF
#FFFF00
#00FFFF
#FF00FF
#C0C0C0
#FFFFFF
Example
Here are the examples to set background of an HTML tag by color code in
hexadecimal −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by Hex</title>
</head>
rgb(0,0,0)
rgb(255,0,0)
rgb(0,255,0)
rgb(0,0,255)
rgb(255,255,0)
rgb(0,255,255)
rgb(255,0,255)
rgb(192,192,192)
rgb(255,255,255)
Example
Here are the examples to set background of an HTML tag by color code
using rgb() values −
<!DOCTYPE html>
<html>
<head>
<title>HTML Colors by RGB code</title>
</head>
</html>
<div> Tag
Example
A <div> section in a document that is styled with CSS:
<html>
<head>
<style>
.myDiv {
border: 5px outset red;
background-color: lightblue;
text-align: center;
}
</style>
</head>
<body>
<div class="myDiv">
<h2>This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>
</body>
</html>
Output:
<span> Tag
Example
A <span> element which is used to color a part of a text:
<p>My mother
has <span style="color:blue">blue</span> eyes.</p>
Program:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output:
Definition and Usage
The <span> tag is an inline container used to mark up a part of a
text, or a part of a document.
The <span> tag is much like the <div> element, but <div> is a
block-level element and <span> is an inline element.
HTML Tables
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 <table> tag in which the <tr> tag
is used to create table rows and <td> tag is used to create data cells. The
elements under <td> are regular and left aligned by default
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Tables</title>
</head>
<body>
<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>
</body>
</html>
This will produce the following result –
Here, the border is an attribute of <table> 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 <th> tag. This tag will be put to
replace <td> 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 <th> element in any row. Headings, which are defined in <th>
tag are centered and bold by default.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Header</title>
</head>
<body>
<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>
</body>
</html>
This will produce the following result –
Cellpadding and Cellspacing Attributes
There are two attributes called cellpadding and cellspacing which you will
use to adjust the white space in your table cells. The cellspacing attribute
defines space between table cells, while cellpadding represents the
distance between cell borders and the content within a cell.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Cellpadding</title>
</head>
<body>
<table border = "1" cellpadding = "5" cellspacing = "5">
<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>
</body>
</html>
This will produce the following result –
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
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Colspan/Rowspan</title>
</head>
<body>
<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>
</body>
</html>
This will produce the following result –
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.
Note − The bgcolor, background, and bordercolor attributes deprecated
in HTML5. Do not use these attributes.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" bgcolor = "yellow">
<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>
</body>
</html>
This will produce the following result –
<head>
<title>HTML Table Background</title>
</head>
<body>
<table border = "1" bordercolor = "green" background =
"/images/test.png">
<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>
</body>
</html>
This will produce the following result.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Width/Height</title>
</head>
<body>
<table border = "1" width = "400" height = "150">
<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>
</body>
</html>
This will produce the following result –
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 deprecated in newer version
of HTML/XHTML.
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Caption</title>
</head>
<body>
<table border = "1" width = "100%">
<caption>This is the caption</caption>
<tr>
<td>row 1, column 1</td><td>row 1, columnn 2</td>
</tr>
<tr>
<td>row 2, column 1</td><td>row 2, columnn 2</td>
</tr>
</table>
</body>
</html>
This will produce the following result –
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
−
<thead> − to create a separate table header.
<tbody> − to indicate the main body of the table.
<tfoot> − to create a separate table footer.
A table may contain several <tbody> elements to indicate different
pages or groups of data. But it is notable that <thead> and <tfoot> tags
should appear before <tbody>
Example
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border = "1" width = "100%">
<thead>
<tr>
<td colspan = "4">This is the head of the table</td>
</tr>
</thead>
<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>
</body>
</html>
This will produce the following result –
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.
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>
This will produce the following result −
Beetroot
Ginger
Potato
Radish
<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>
This will produce the following result −
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>
This will produce the following result −
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>
This will produce the following result −
o Beetroot
o Ginger
o Potato
o Radish
<head>
<title>HTML Ordered List</title>
</head>
<body>
<ol>
<li>Beetroot</li>
<li>Ginger</li>
<li>Potato</li>
<li>Radish</li>
</ol>
</body>
</html>
This will produce the following result −
1. Beetroot
2. Ginger
3. Potato
4. Radish
<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>
This will produce the following result −
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>
This will produce the following result −
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>
This will produce the following result −
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>
This will produce the following result −
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>
This will produce the following result −
a. Beetroot
b. Ginger
c. Potato
d. Radish
<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>
This will produce the following result −
iv. Beetroot
v. Ginger
vi. Potato
vii. Radish
<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>
This will produce the following result −
HTML
This stands for Hyper Text Markup Language
HTTP
This stands for Hyper Text Transfer Protocol
HTML IMAGES
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" ... attributes-list/>
The <img> tag is an empty tag, which means that, it
can contain only list of attributes and it has no closing
tag.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src = "bookimage.jpg" alt = "Test Image" />
</body>
</html>
This will produce the following result –
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 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 "C:\Amitha\
Documents", try the following example −
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src =” C:\Users\Documents\bookimage.jpg" alt = "Test
Image" />
</body>
</html>
This will produce the following result –
<body>
<p>Setting image width and height</p>
<img src =” C:\Users\Amitha\Documents\bookimage.jpg " alt
= "Test Image" width = "150" height = "100"/>
</body>
</html>
This will produce the following result –
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<img src = “C:\Users\Amitha\Documents\bookimage.jpg " alt
= "Test Image" border = "3"/>
</body>
</html>
This will produce the following result –
<head>
<title>Set Image Alignment</title>
</head>
<body>
<p>Setting image Alignment</p>
<img src = "/html/images/test.png" alt = "Test Image" border = "3" align
= "right"/>
</body>
</html>
HTML - Iframes
You can define an inline frame with HTML tag <iframe>. The <iframe>
tag is not somehow related to <frameset> tag, instead, it can appear
anywhere in your document. The <iframe> tag defines a rectangular
region within the document in which the browser can display a separate
document, including scrollbars and borders. An inline frame is used to
embed another document within the current HTML document.
The src attribute is used to specify the URL of the document that occupies
the inline frame.
Example
Following is the example to show how to use the <iframe> −
<!DOCTYPE html>
<html>
<head>
<title>HTML Iframes</title>
</head>
<body>
<p>Document content goes here...</p>
</html>
This will produce the following result –
1 src
This attribute is used to give the file name that should be loaded in the
frame. Its value can be any URL. For example, src = "/html/top_frame.htm"
will load an HTML file available in html directory.
2 name
This attribute allows you to give a name to a frame. It is used to indicate
which frame a document should be loaded into. This is especially important
when you want to create links in one frame that load pages into an another
frame, in which case the second frame needs a name to identify itself as
the target of the link.
3 frameborder
This attribute specifies whether or not the borders of that frame are shown;
it overrides the value given in the frameborder attribute on the <frameset>
tag if one is given, and this can take values either 1 (yes) or 0 (no).
4 marginwidth
This attribute allows you to specify the width of the space between the left
and right of the frame's borders and the frame's content. The value is given
in pixels. For example marginwidth = "10".
5 marginheight
This attribute allows you to specify the height of the space between the top
and bottom of the frame's borders and its contents. The value is given in
pixels. For example marginheight = "10".
6 height
This attribute specifies the height of <iframe>.
7 scrolling
This attribute controls the appearance of the scrollbars that appear on the
frame. This takes values either "yes", "no" or "auto". For example scrolling
= "no" means it should not have scroll bars.
8 longdesc
This attribute allows you to provide a link to another page containing a long
description of the contents of the frame. For example longdesc =
"framedescription.htm"
9 width
This attribute specifies the width of <iframe>.
HTML iframes
HTML Iframe is used to display a nested webpage (a webpage within a
webpage). The HTML <iframe> tag defines an inline frame, hence it is
also called as an Inline frame.
An HTML iframe embeds another document within the current HTML
document in the rectangular region.
The webpage content and iframe contents can interact with each other
using JavaScript.
Iframe Syntax
An HTML iframe is defined with the <iframe> tag:
<iframe src="URL"></iframe>
Here, "src" attribute specifies the web address (URL) of the inline frame
page.
Example: (Pixels)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes example</h2>
<p>Use the height and width attributes to specify the size of the ifram
e:</p>
<iframe src="https://www.javatpoint.com/" height="300" width
="400"></iframe>
</body>
</html>
OUTPUT:
Example: (Percentage)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of t
he iframe:</p>
<iframe src="https://www.javatpoint.com/" height="50%" width
="70%"></iframe>
</body>
</html>
OUTPUT:
You can also use CSS to set the height and width of the iframe.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>Use the CSS height and width properties to specify the size of the i
frame:</p>
<iframe src="https://www.javatpoint.com/" style
="height:300px;width:400px"></iframe>
</body>
</html>
OUTPUT:
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Remove the Iframe Border</h2>
<p>This iframe example doesn't have any border</p>
<iframe src="https://www.javatpoint.com/" style="border:none;"></
iframe>
</body>
</html>
OUTPUT:
You can also change the size, color, style of the iframe's border.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Custom Iframe Border</h2>
<iframe src="https://www.javatpoint.com/" style="border:2px solid to
mato;"></iframe>
</body>
</html>
OUTPUT:
Iframe Target for a link
You can set a target frame for a link by using iframe. Your specified target
attribute of the link must refer to the name attribute of the iframe.
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Output
HTML Semantic
Elements
What are Semantic Elements?
A semantic element clearly describes its meaning to both the browser and
the developer.
In HTML there are some semantic elements that can be used to define
different parts of a web page:
<article>
<aside>
<details>
<figcaption>
<figure>
<footer>
<header>
<main>
<mark>
<nav>
<section>
<summary>
<time>
Chapters
Introduction
News items
Contact information
A web page could normally be split into sections for introduction, content,
and contact information.
Example
Two sections in a document:
<section>
<h1>WWF</h1>
<p>The World Wide Fund for Nature (WWF) is an international
organization working on issues regarding the conservation,
research and restoration of the environment, formerly named
the World Wildlife Fund. WWF was founded in 1961.</p>
</section>
<section>
<h1>WWF's Panda symbol</h1>
<p>The Panda has become the symbol of WWF. The well-known
panda logo of WWF originated from a panda named Chi Chi that
was transferred from the Beijing Zoo to the London Zoo in the
same year of the establishment of WWF.</p>
</section>
Output:
Forum posts
Blog posts
User comments
Product cards
Newspaper articles
Example
Three articles with independent, self-contained content:
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google,
released in 2008. Chrome is the world's most popular web
browser today!</p>
</article>
<article>
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by
Mozilla. Firefox has been the second most popular web browser
since January, 2018.</p>
</article>
<article>
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft,
released in 2015. Microsoft Edge replaced Internet
Explorer.</p>
</article>
Output:
Example 2
Use CSS to style the <article> element:
<html>
<head>
<style>
.all-browsers {
margin: 0;
padding: 5px;
background-color: lightgray;
}
.browser {
background: white;
}
<article class="all-browsers">
<h1>Most Popular Browsers</h1>
<article class="browser">
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser developed by Google,
released in 2008. Chrome is the world's most popular web
browser today!</p>
</article>
<article class="browser">
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed
by Mozilla. Firefox has been the second most popular web
browser since January, 2018.</p>
</article>
<article class="browser">
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft,
released in 2015. Microsoft Edge replaced Internet
Explorer.</p>
</article>
</article>
</body>
</html>
Output:
Note: You can have several <header> elements in one HTML document.
However, <header> cannot be placed within a <footer>, <address> or
another <header> element.
Example
A header for an <article>:
<article>
<header>
<h1>What Does WWF Do?</h1>
<p>WWF's mission:</p>
</header>
<p>WWF's mission is to stop the degradation of our planet's
natural environment,
and build a future in which humans live in harmony with
nature.</p>
</article>
Output:
authorship information
copyright information
contact information
sitemap
back to top links
related documents
Example
A footer section in a document:
<footer>
<p>Author: Hege Refsnes</p>
<p><a href="mailto:[email protected]">[email protected]</a></p
>
</footer>
Output:
Notice that NOT all links of a document should be inside a <nav> element.
The <nav> element is intended only for major blocks of navigation links.
Browsers, such as screen readers for disabled users, can use this element
to determine whether to omit the initial rendering of this content.
Example
A set of navigation links:
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
Output:
<p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
<aside>
<h4>Epcot Center</h4>
<p>Epcot is a theme park at Walt Disney World Resort featuring
exciting attractions, international pavilions, award-winning
fireworks and seasonal special events.</p>
</aside>
Output:
Example 2
Use CSS to style the <aside> element:
<html>
<head>
<style>
aside {
width: 30%;
padding-left: 15px;
margin-left: 15px;
float: right;
font-style: italic;
background-color: lightgray;
}
</style>
</head>
<body>
<p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
<aside>
<p>The Epcot center is a theme park at Walt Disney World
Resort featuring exciting attractions, international
pavilions, award-winning fireworks and seasonal special
events.</p>
</aside>
<p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
<p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
</body>
</html>
Output:
new.hmtl output code:
<!DOCTYPE html>
<html>
<head>
<style>
p{ font-size: 50px;
color: red;}
</style>
</head>
<body style="background-color: #c7f15e;">
<p>This is a link below the ifarme click on link to open new iframe.
</p>
</body>
</html>
HTML Links
Links are found in nearly all web pages. Links allow users to click their
way from page to page.
When you move the mouse over a link, the mouse arrow will turn into a
little hand.
Note: A link does not have to be text. A link can be an image or any other
HTML element!
The most important attribute of the <a> element is the href attribute,
which indicates the link's destination.
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.
Example
This example shows how to create a link to W3Schools.com:
<!DOCTYPE html>
<html>
<body>
<h1>HTML Links</h1>
</body>
</html>
Output:
By default, links will appear as follows in all browsers:
Example
Use target="_blank" to open the linked document in a new browser
window or tab:
<!DOCTYPE html>
<html>
<body>
<h2>The target Attribute</h2>
<p>If target="_blank", the link will open in a new browser window or tab.</p>
</body>
</html>
o/p:
A local link (a link to a page within the same website) is specified with
a relative URL (without the "https://www" part):
Example
<h2>Absolute URLs</h2>
<p><a href="https://www.w3.org/">W3C</a></p>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
Ex:
<!DOCTYPE html>
<html>
<body>
<h2>Absolute URLs</h2>
<p><a href="https://www.w3.org/">W3C</a></p>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
</body>
</html>
o/p:
Example
<a href="default.asp">
<img src="smiley.gif" alt="HTML
tutorial" style="width:42px;height:42px;">
</a>
Ex:
<!DOCTYPE html>
<html>
<body>
<h2>Image as a Link</h2>
</body>
</html>
o/p:
Example
<a href="mailto:[email protected]">Send email</a>
Ex:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
o/p: