.What Is HTML?: Example Explained
.What Is HTML?: Example Explained
Example Explained
The <!DOCTYPE html> declaration defines this document to be HTML5
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 Styles
<!DOCTYPE html>
<html>
<body>
<p>I am normal</p>
</body>
</html>
I am normal
I am red
I am blue
I am big
HTML Background Color
The background-color property defines the background color for an HTML
element.
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
This is a heading
This is a paragraph.
HTML Fonts
The font-family property defines the font to be used for an HTML element:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
This is a heading
This is a paragraph
<!DOCTYPE html>
<html>
<body>
</body>
</html>
This is a heading
This is a paragraph
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Centered Heading
Centered paragraph.
</body>
</html>
HTML also defines special elements for defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic
text.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The HTML <strong> element defines strong text, with added semantic
"strong" importance.
Example
<!DOCTYPE html>
<html>
<body>
<p>This text is normal.</p>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML Small Formatting
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<html>
<body>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
</blockquote>
</body>
</html>
For 50 years, WWF has been protecting the future of nature. The world's leading
conservation organization, WWF works in 100 countries and is supported by 1.2 million
members in the United States and close to 5 million globally.
Example
<!DOCTYPE html>
<html>
<body>
<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>
</body>
</html>
WWF's goal is to: Build a future where people live in harmony with nature.
The <address> element is usually displayed in italic. Most browsers will add a
line break before and after the element.
Example
<!DOCTYPE html>
<html>
<body>
<p>The HTML address element defines contact information (author/owner) of a document or
article.</p>
<address>
Visit us at:<br>
Example.com<br>
USA
</address>
</body>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The HTML cite element defines the title of a work.
Example
<!DOCTYPE html>
<html>
<body>
<p>If your browser supports bi-directional override (bdo), the next line will be written from
right to left (rtl):</p>
</html>
If your browser supports bi-directional override (bdo), the next line will be written from right to
left (rtl):
HTML Colors
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:red">
Background-color set by using red
</h2>
<h2 style="background-color:orange">
Background-color set by using orange
</h2>
<h2 style="background-color:yellow">
Background-color set by using yellow
</h2>
<h2 style="background-color:blue;color:white">
Background-color set by using blue
</h2>
<h2 style="background-color:cyan">
Background-color set by using cyan
</h2>
</body>
</html>
Each parameter (red, green, and blue) defines the intensity of the color
between 0 and 255.
For example, rgb(255,0,0) is displayed as red, because red is set to its highest
value (255) and the others are set to 0.
To display the color black, all color parameters must be set to 0, like this:
rgb(0,0,0).
To display the color white, all color parameters must be set to 255, like this:
rgb(255,255,255).
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:rgb(255,0,0)">
Background-color set by using rgb(255,0,0)
</h2>
<h2 style="background-color:rgb(0,255,0)">
Background-color set by using rgb(0,255,0)
</h2>
<h2 style="background-color:rgb(0,0,255)">
Background-color set by using rgb(0,0,255)
</h2>
<h2 style="background-color:rgb(255,255,0)">
Background-color set by using rgb(255,255,0)
</h2>
<h2 style="background-color:rgb(255,0,255)">
Background-color set by using rgb(255,0,255)
</h2>
<h2 style="background-color:rgb(0,255,255)">
Background-color set by using rgb(0,255,255)
</h2>
</body>
</html>
Background-color set by using rgb(255,0,0)
Background-color set by using rgb(0,255,0)
Background-color set by using rgb(0,0,255)
Background-color set by using rgb(255,255,0)
Background-color set by using rgb(255,0,255)
Background-color set by using rgb(0,255,255)
Shades of gray are often defined using equal values for all the 3 light sources:
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:rgb(0,0,0);color:white">
Background-color set by using rgb(0,0,0)
</h2>
<h2 style="background-color:rgb(90,90,90);color:white">
Background-color set by using rgb(90,90,90)
</h2>
<h2 style="background-color:rgb(128,128,128);color:white">
Background-color set by using rgb(128,128,128)
</h2>
<h2 style="background-color:rgb(200,200,200);color:white">
Background-color set by using rgb(200,200,200)
</h2>
<h2 style="background-color:rgb(255,255,255);">
Background-color set by using rgb(255,255,255)
</h2>
</body>
</html>
For example, #FF0000 is displayed as red, because red is set to its highest
value (FF) and the others are set to the lowest value (00).
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:#FF0000">
Background-color set by using #FF0000
</h2>
<h2 style="background-color:#00FF00">
Background-color set by using #00FF00
</h2>
<h2 style="background-color:#0000FF">
Background-color set by using #0000FF
</h2>
<h2 style="background-color:#FFFF00">
Background-color set by using #FFFF00
</h2>
<h2 style="background-color:#FF00FF">
Background-color set by using #FF00FF
</h2>
<h2 style="background-color:#00FFFF">
Background-color set by using #00FFFF
</h2>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:#000000;color:white">
Background-color set by using #000000
</h2>
<h2 style="background-color:#808080;color:white">
Background-color set by using #808080
</h2>
<h2 style="background-color:#FFFFFF;">
Background-color set by using #FFFFFF
</h2>
</body>
</html>
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
This example sets the text color of the <h1> element to blue:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within a
<style> element:
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
External CSS
An external style sheet is used to define the style for many HTML pages.
With an external style sheet, you can change the look of an entire web
site, by changing one file!
To use an external style sheet, add a link to it in the <head> section of the
HTML page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
An external style sheet can be written in any text editor. The file must not
contain any HTML code, and must be saved with a .css extension.
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
CSS Fonts
The CSS color property defines the text color to be used.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
p {
color: red;
font-family: courier;
font-size: 160%;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
CSS Border
The CSS border property defines a border around an HTML element:
<!DOCTYPE html>
<html>
<head>
<style>
p{
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
CSS Padding
The CSS padding property defines a padding (space) between the text and the
border:
<!DOCTYPE html>
<html>
<head>
<style>
p{
padding: 30px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
CSS Margin
The CSS margin property defines a margin (space) outside the border:
<!DOCTYPE html>
<html>
<head>
<style>
p{
margin: 50px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
This is a paragraph.
This is a paragraph.
The id Attribute
To define a specific style for one special element, add an id attribute to the
element:
<!DOCTYPE html>
<html>
<head>
<style>
#p01 {
color: blue;
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This is a paragraph.
This is a paragraph.
I am different.
<!DOCTYPE html>
<html>
<head>
<style>
p.error {
color: red;
</style>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body>
</html>
This is a paragraph.
This is a paragraph.
I am different.
This is a paragraph.
I am different too.
External References
External style sheets can be referenced with a full URL or with a path relative to
the current web page.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="https://www.w3schools.com/html/styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
This example links to a style sheet located in the html folder on the
current web site:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/html/styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
This example links to a style sheet located in the same folder as the current
page:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
This is a heading
This is a paragraph.
HTML Links
When you move the mouse over a link, the mouse arrow will turn into a little
hand
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The link text is the visible part (Visit our HTML tutorial).
Clicking on the link text will send you to the specified address.
Local Links
The example above used an absolute URL (A full web address).
A local link (link to the same web site) is specified with a relative URL (without
http://www....).
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
a:link {
color: green;
background-color: transparent;
text-decoration: none;
a:visited {
color: pink;
background-color: transparent;
text-decoration: none;
a:hover {
color: red;
background-color: transparent;
text-decoration: underline;
a:active {
color: yellow;
background-color: transparent;
text-decoration: underline;
}
</style>
</head>
<body>
</body>
</html>
HTML Images
This example will open the linked document in a new browser window/tab:
<!DOCTYPE html>
<html>
<body>
<a href="https://www.w3schools.com/html/" target="_blank">Visit our HTML
tutorial!</a>
<p>If you set the target attribute to "_blank", the link will open in a new
browser window or tab.</p>
</body>
</html>
If you set the target attribute to "_blank", the link will open in a new browser window or tab.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<html>
<body>
<a href="default.asp">
</a>
</body>
</html>
We have added "border:0" to prevent IE9 (and earlier) from displaying a border around the
image.
When the link is clicked, the page will scroll to the location with the bookmark.
<!DOCTYPE html>
<html>
<body>
<h2>Chapter 1</h2>
<h2>Chapter 2</h2>
<h2>Chapter 3</h2>
<h2>Chapter 5</h2>
<h2>Chapter 7</h2>
<h2>Chapter 8</h2>
<h2>Chapter 9</h2>
<h2>Chapter 10</h2>
<h2>Chapter 11</h2>
<h2>Chapter 12</h2>
<h2>Chapter 13</h2>
<h2>Chapter 15</h2>
<h2>Chapter 16</h2>
<h2>Chapter 17</h2>
</body>
</html>
Jump to Chapter 4
Chapter 1
This chapter explains ba bla bla
Chapter 2
This chapter explains ba bla bla
Chapter 3
This chapter explains ba bla bla
Chapter 4
This chapter explains ba bla bla
Chapter 5
This chapter explains ba bla bla
Chapter 6
This chapter explains ba bla bla
Chapter 7
This chapter explains ba bla bla
Chapter 8
This chapter explains ba bla bla
Chapter 9
This chapter explains ba bla bla
Chapter 10
This chapter explains ba bla bla
Chapter 11
This chapter explains ba bla bla
Chapter 12
This chapter explains ba bla bla
Chapter 13
This chapter explains ba bla bla
Chapter 14
This chapter explains ba bla bla
Chapter 15
This chapter explains ba bla bla
Chapter 16
This chapter explains ba bla bla
Chapter 17
This chapter explains ba bla bla
External Paths
External pages can be referenced with a full URL or with a path relative to the
current web page.
<!DOCTYPE html>
<html>
<body>
<p><a href="https://www.w3schools.com/html/default.asp">HTML
tutorial</a></p>
</body>
</html>
HTML tutorial
This example links to a page located in the html folder on the current web site:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML tutorial
This example links to a page located in the same folder as the current page:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML tutorial
HTML Images
<!DOCTYPE html>
<html>
<body>
<h2>Spectacular Mountain</h2>
</body>
</html>
Spectacular Mountain
If a browser cannot find an image, it will display the value of the alt attribute:
<!DOCTYPE html>
<html>
<body>
<p>If a browser cannot find an image, it will display the alternate text:</p>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Alternatively, you can use the width and height attributes. Here, the values
are specified in pixels by default:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Width and Height, or Style?
Both the width, height, and style attributes are valid in HTML5.
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:100%;
}
</style>
</head>
<body>
<p>It is better to use the style attribute to set the width and height of an image
(instead of using the width and height attributes), because it prevents
internal or external styles sheets to change the original size of an image:</p>
</body>
</html>
It is better to use the style attribute to set the width and height of an image (instead of using the
width and height attributes), because it prevents internal or external styles sheets to change the
original size of an image:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Actually, you can access images from any web address in the world:
<!DOCTYPE html>
<html>
<body>
Animated Images
The tandard allows animated images:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">
</a>
<p>Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.</p>
</body>
</html>
Add "border:0;" to prevent IE9 (and earlier) from displaying a border around the image.
Image Floating
Use the CSS float property to let the image float to the right or to the left of a
text:
<!DOCTYPE html>
<html>
<body>
<p>Please use the CSS float property. The align attribute is deprecated in HTML 4, and not
supported in HTML5.</p>
</body>
</html>
A paragraph with a floating image. A paragraph with a floating image. A paragraph with a
floating image.
Please use the CSS float property. The align attribute is deprecated in HTML 4, and not
supported in HTML5.
Image Maps
Use the <map> tag to define an image-map. An image-map is an image with
clickable areas.
The name attribute of the <map> tag is associated with the <img>'s usemap
attribute and creates a relationship between the image and the map.
The <map> tag contains a number of <area> tags, that defines the clickable
areas in the image-map:
<!DOCTYPE html>
<html>
<body>
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
<area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
<area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>
</body>
</html>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
The list items will be marked with bullets (small black circles) by default:
<!DOCTYPE html>
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Value Description
<!DOCTYPE html>
<html>
<body>
<ul style="list-style-type:disc">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Example - Circle
<!DOCTYPE html>
<html>
<body>
<ul style="list-style-type:circle">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<ul style="list-style-type:square">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Example - None
<!DOCTYPE html>
<html>
<body>
<h2>Unordered List without Bullets</h2>
<ul style="list-style-type:none">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Tea
Milk
<!DOCTYPE html>
<html>
<body>
<h2>An ordered HTML list</h2>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Type Description
type="i" The list items will be numbered with lowercase roman numbers
<!DOCTYPE html>
<html>
<body>
<ol type="1">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Uppercase Letters:
<!DOCTYPE html>
<html>
<body>
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
Lowercase Letters:
<!DOCTYPE html>
<html>
<body>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<ol type="I">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<ol type="i">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
The <dl> tag defines the description list, the <dt> tag defines the term
(name), and the <dd> tag describes each term:
<!DOCTYPE html>
<html>
<body>
<dl>
<dt>Coffee</dt>
<dt>Milk</dt>
</dl>
</body>
</html>
A Description List
Coffee
Milk
<!DOCTYPE html>
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</body>
</html>
A Nested List
Coffee
Tea
o Black tea
o Green tea
Milk
Horizontal Lists
HTML lists can be styled in many different ways with CSS.
<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
li a:hover {
background-color: blue;
</style>
</head>
<body>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
</body>
</html>
HTML Tables
Each table row is defined with the <tr> tag. A table header is defined with the
<th> tag. By default, table headings are bold and centered. A table data/cell is
defined with the <td> tag.
Example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
<!DOCTYPE html>
<html>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Jill Smith 50
Eve Jackson 94
John Doe 80
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
To set the border spacing for a table, use the CSS border-spacing property
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
padding: 5px;
}
table {
border-spacing: 15px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border-collapse: collapse;
th, td {
padding: 5px;
text-align: left;
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
</body>
</html>
55577854
Telephone:
55577855
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:100%">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
Monthly savings
Month Savings
January $100
February $50
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
<br>
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
<br>
<table id="t01">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
HTML Forms
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit
If you click the "Submit" button, the form-data will be sent to a page called "/action_page.php".
Text Input
<!DOCTYPE html>
<html>
<body>
<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
<p>Also note that the default width of a text input field is 20 characters.</p>
</body>
</html>
First name:
Last name:
Also note that the default width of a text input field is 20 characters.
Radio Button Input
<!DOCTYPE html>
<html>
<body>
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
</body>
</html>
Male
Female
Other
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit
If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".
<form action="/action_page.php">
First name:<br>
<input type="text" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".</p>
<p>Notice that the value of the "First name" field will not be submitted, because the
input element does not have a name attribute.</p>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit
If you click the "Submit" button, the form-data will be sent to a page called
"/action_page.php".
Notice that the value of the "First name" field will not be submitted, because the input
element does not have a name attribute.
<form action="/action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
</body>
</html>
Personal information:
First name:
Mickey
Last name:
Mouse
Submit
HTML Form Elements
The <select> Element
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit">
</form>
</body>
</html>
Volvo
Submit
<form action="/action_page.php">
<textarea name="message" rows="10" cols="30">The cat was playing in the
garden.</textarea>
<br>
<input type="submit">
</form>
</body>
</html>
gjghjghjgj
gj
ghjghjghjghjghj
Submit
</body>
</html>
Click Me!
<form action="/action_page.php">
<input list="browsers" name="browser">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
<input type="submit">
</form>
<p><b>Note:</b> The datalist tag is not supported in Safari or IE9 (and earlier).</p>
</body>
</html>
Submit
When the form is submitted, two keys are generated, one private and one
public.
The private key is stored locally, and the public key is sent to the server.
The public key could be used to generate a client certificate to authenticate the
user in the future.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
Username: <input type="text" name="user">
<br><br>
Encryption: <keygen name="security">
<br><br>
<input type="submit">
</form>
</body>
</html>
Username:
Encryption:
Submit
HTML5 <output> Element
The <output> element represents the result of a calculation (like one performed
by a script).
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
</body>
</html>
0 100 + =
Submit
Note: The output element is not supported in Edge 12 or Internet Explorer and earlier
versions.
HTML Input Types
Input Type Text
<input type="text"> defines a one-line text input field:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
<br><br>
<input type="submit">
</form>
</body>
</html>
First name:
Last name:
Submit
<!DOCTYPE html>
<html>
<body>
<form action="">
User name:<br>
<input type="text" name="userid">
<br>
User password:<br>
<input type="password" name="psw">
</form>
</body>
</html>
User name:
User password:
The form-handler is typically a server page with a script for processing input
data.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click "Submit", the form-data will be sent to a page called "/action_page.php".</p>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit
If you click "Submit", the form-data will be sent to a page called "/action_page.php".
If you omit the submit button's value attribute, the button will get a default
text:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit">
</form>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
<p>If you change the input values and then click the "Reset" button, the form-data will be reset
to the default values.</p>
</body>
</html>
First name:
Mickey
Last name:
Mouse
Submit Reset
If you change the input values and then click the "Reset" button, the form-data will be
reset to the default values.
Radio buttons let a user select ONLY ONE of a limited number of choices:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other<br><br>
<input type="submit">
</form>
</body>
</html>
Male
Female
Other
Submit
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="checkbox" name="vehicle1" value="Bike">I have a bike
<br>
<input type="checkbox" name="vehicle2" value="Car">I have a car
<br><br>
<input type="submit">
</form>
</body>
</html>
I have a bike
I have a car
Submit
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Depending on browser support, a color picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>
Depending on browser support:<br>
A color picker can pop-up when you enter the input field.
</p>
<form action="/action_page.php">
Select your favorite color:
<input type="color" name="favcolor" value="#ff0000">
<input type="submit">
</form>
</body>
</html>
Submit
Select your favorite color:
Depending on browser support, a date picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>
Depending on browser support:<br>
A date picker can pop-up when you enter the input field.
</p>
<form action="/action_page.php">
Birthday:
<input type="date" name="bday">
<input type="submit">
</form>
</body>
</html>
Birthday:
Submit
Depending on browser support, a date picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>
Depending on browser support:<br>
A date picker can pop-up when you enter the input field.
</p>
<form action="/action_page.php">
Birthday (date and time):
<input type="datetime-local" name="bdaytime">
<input type="submit" value="Send">
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
E-mail:
<input type="email" name="email">
<input type="submit">
</form>
<p>
<b>Note:</b>type="email" is not supported in IE9 and earlier.</p>
</body>
</html>
E-mail:
Submit
Depending on browser support, a date picker can show up in the input field.
<!DOCTYPE html>
<html>
<body>
<p>
Depending on browser support:<br>
A date picker can pop-up when you enter the input field.
</p>
<form action="/action_page.php">
Birthday (month and year):
<input type="month" name="bdaymonth">
<input type="submit">
</form>
</body>
</html>
Submit
Birthday (month and year):
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
Quantity (between 1 and 5):
<input type="number" name="quantity" min="1" max="5">
<input type="submit">
</form>
</body>
</html>
Submit
Quantity (between 1 and 5):
<p>
Depending on browser support:<br>
The input type "range" can be displayed as a slider control.
</p>
<p>
<b>Note:</b>
type="range" is not supported in Internet Explorer 9 and earlier versions.
</p>
</body>
</html>
Submit
Points:
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
Search Google:
<input type="search" name="googlesearch">
<input type="submit">
</form>
</body>
</html>
Submit
Search Google:
The formtarget attribute overrides the target attribute of the <form> element.
The formtarget attribute can be used with type="submit" and type="image".
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="submit" value="Submit as normal">
<input type="submit" formtarget="_blank" value="Submit to a new window/tab">
</form>
</body>
</html>
First name:
Last name:
Submit as normal Submit to a new w indow /tab
Note: The formtarget attribute of the input tag is not supported in Internet Explorer 9
and earlier versions.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
<p><b>Note:</b> The input type="image" sends the X and Y coordinates of the click that
activated the image button.</p>
</body>
</html>
First name:
Last name:
Note: The input type="image" sends the X and Y coordinates of the click that
activated the image button.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" method="get">
</datalist>
<input type="submit">
</form>
<p><b>Note:</b> The datalist tag is not supported in Internet Explorer 9 and earlier versions,
or in Safari.</p>
</body>
</html>
Submit
Note: The datalist tag is not supported in Internet Explorer 9 and earlier versions, or
in Safari.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="submit">
</form>
<p><strong>Note:</strong> The max and min attributes of the input tag is not
supported in Internet Explorer 9 and earlier versions, or in Firefox.</p>
<p><strong>Note:</strong> The max and min attributes will not work for dates and
time in Internet Explorer 10, since IE 10 does not support these input types.</p>
</body>
</html>
Note: The max and min attributes of the input tag is not supported in Internet
Explorer 9 and earlier versions, or in Firefox.
Note: The max and min attributes will not work for dates and time in Internet
Explorer 10, since IE 10 does not support these input types.
The multiple attribute works with the following input types: email, and file.
<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php">
<input type="submit">
</form>
<p>Try selecting more than one file when browsing for files.</p>
</body>
</html>
Submit
Select images:
Try selecting more than one file when browsing for files.
Note: The multiple attribute of the input tag is not supported in Internet Explorer 9
and earlier versions.
HTML5 Introduction
What is New in HTML5?
The DOCTYPE declaration for HTML5 is very simple:
<meta charset="UTF-8">
HTML5 Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>
Content of the document......
</body>
</html>
Because of this, you can "teach" older browsers to handle "unknown" HTML
elements.
<!DOCTYPE html>
<html>
<head>
<script>document.createElement("myHero")</script>
<style>
myHero {
display: block;
background-color: #dddddd;
padding: 50px;
font-size: 30px;
}
</style>
</head>
<body>
<h1>A Heading</h1>
</body>
</html>
A Heading
My Hero Element
HTML5 Semantic Elements
A home page could normally be split into sections for introduction, content, and
contact information.
<!DOCTYPE html>
<html>
<body>
<section>
<h1>WWF</h1>
</section>
<section>
<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>
</body>
</html>
WWF
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.
An article should make sense on its own, and it should be possible to read it
independently from the rest of the web site.
Forum post
Blog post
Newspaper article
<!DOCTYPE html>
<html>
<body>
<article>
</article>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<article>
<header>
<p>WWF's mission:</p>
</header>
</body>
</html>
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.
<!DOCTYPE html>
<html>
<body>
<footer>
someone@example.com</a>.</p>
</footer>
</body>
</html>
Contact information: someone@example.com.
<!DOCTYPE html>
<html>
<body>
<nav>
<a href="/html/">HTML</a> |
<a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
</nav>
</body>
</html>
HTML | CSS | JavaScript | jQuery
HTML5 <aside> Element
The <aside> element defines some content aside from the content it is placed
in (like a sidebar).
<!DOCTYPE html>
<html>
<body>
<aside>
<h4>Epcot Center</h4>
</aside>
</body>
</html>
Epcot Center
<!DOCTYPE html>
<html>
<body>
<p>The Pulpit Rock is a massive cliff 604 metres (1982 feet) above Lysefjorden,
opposite the Kjerag plateau, in Forsand, Ryfylke, Norway. The top of the cliff is
approximately 25 by 25 metres (82 by 82 feet) square and almost flat, and is a famous
tourist attraction in Norway.</p>
<figure>
</figure>
</body>
</html>
The Pulpit Rock is a massive cliff 604 metres (1982 feet) above Lysefjorden, opposite
the Kjerag plateau, in Forsand, Ryfylke, Norway. The top of the cliff is approximately
25 by 25 metres (82 by 82 feet) square and almost flat, and is a famous tourist
attraction in Norway.
Fig.1 - The Pulpit Rock, Norway.
There are a few things you can do to affect the presentation of a frameset
beyond styling the documents themselves. The size of each frame can be
specified and locked. The margin between frames can be changed. The border
around frames can be formatted. These changes aren’t made with CSS. Instead,
they are made by adding attributes and values to the frame elements
Sizing Frames
If we click the link Load frame_2.html we see the navigation contents both in the left
sidebar and the middle column.
Create form in HTML
form {
/* Just to center the form on the page */
margin: 0 auto;
width: 400px;
/* To see the outline of the form */
padding: 1em;
border: 1px solid #CCC;
border-radius: 1em;
}
label {
/* To make sure that all labels have the same size and are properly aligned */
display: inline-block;
width: 90px;
text-align: right;
}
input, textarea {
/* To make sure that all text fields have the same font settings
By default, textareas have a monospace font */
font: 1em sans-serif;
input:focus, textarea:focus {
/* To give a little highlight on active elements */
border-color: #000;
}
textarea {
/* To properly align multiline text fields with their labels */
vertical-align: top;
.button {
/* To position the buttons to the same position of the text fields */
padding-left: 90px; /* same size as the label elements */
}
button {
/* This extra margin represent roughly the same space as the space
between the labels and their text fields */
margin-left: .5em;
}
Example of Forms
<form method="post" action="mailto:youremail@email.com">
<p>What type of shoes you wear ?</p>
Color:
Dark
Light
Size:
Small
Average
Big
Email Myself
Simple Black
Simple White
Shades of gray
Black and white
Email Myself
Musical preferences
Emo
Metal/Rock
Hip Hop
Ska
Email Yourself
Level of education?
Choose
Email Yourself
Layouts
<table cellspacing="1" cellpadding="0" border="0" bgcolor="black" id="shell"
height="250" width="400">
<tr height="50">
<td colspan="2" bgcolor="white">
</td>
</tr>
<tr height="200">
<td bgcolor="white">
</td>
<td bgcolor="white">
<table title="Content" id="content" border="0">
<tr>
<td>Continutul sitului va fi plasat aici</td>
</tr>
</table>
</td>
</tr>
</table>
Link-uri!
Link-uri! Continutul sitului va fi plasat aici
Link-uri!
<head>
</head>
<body>
cellspacing="2">
<tr>
<td colspan=2>
</td>
</tr>
<tr>
<td>Name</td>
</tr>
<tr>
<td>Father Name</td>
size="30"></td>
</tr>
<tr>
<td>Postal Address</td>
</tr>
<tr>
<td>Personal Address</td>
id="personaladdress" size="30"></td>
</tr>
<tr>
<td>Sex</td>
</tr>
<tr>
<td>City</td>
<td><select name="City">
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Patna">PATNA</option>
</select></td>
</tr>
<tr>
<td>Course</td>
<td><select name="Course">
<option value="B.Tech">B.TECH</option>
<option value="MCA">MCA</option>
<option value="MBA">MBA</option>
<option value="BCA">BCA</option>
</select></td>
</tr>
<tr>
<td>District</td>
<td><select name="District">
<option value="Nalanda">NALANDA</option>
<option value="UP">UP</option>
<option value="Goa">GOA</option>
<option value="Patna">PATNA</option>
</select></td>
</tr>
<tr>
<td>State</td>
<td><select Name="State">
<option value="Mumbai">MUMBAI</option>
<option value="Goa">GOA</option>
<option value="Bihar">BIHAR</option>
</select></td>
</tr>
<tr>
<td>PinCode</td>
</tr>
<tr>
<td>EmailId</td>
</tr>
<tr>
<td>DOB</td>
</tr>
<tr>
<td>MobileNo</td>
</tr>
<tr>
<td><input type="reset"></td>
</table>
</form>
</body>
</html>
PinCode
EmailId
DOB
MobileNo
Reset Submit
Marquee tag
I will show you in this article some ways you can animate text with the marquee tag. The marquee
tag is an HTML element that makes text to move from left to right and top to down.
Example:-
<html>
<marquee>TEXT</marquee><br><br><br>
<marquee direction="right">TEXT</marquee><br><br><br>
<marquee behavior="alternate">TEXT</marquee><br><br><br>
<marquee direction="up">TEXT</marquee><br><br><br><br>
<marquee direction="down">TEXT</marquee><br><br><br><br>
style="height:100px">TEXT</marquee><br><br><br><br>
direction="right">TEXT</marquee></marquee><br><br><br><br>
<marquee behavior="alternate" direction="up" width="80%">
</marquee><br><br><br><br><br><br><br><br><br>
style="background:RED">TEXT</marquee></font><br><br><br><br>
after.<br><br><br><br><br><br><br><br>
</html>
<html>
<head>
</head>
<body>
</marquee>
</body>
</html>
<head>
</head>
<body>
</marquee>
</body>
</html>
<head>
</head>
<body>
</marquee>
</body>
</html>
<head>
</head>
<body>
</marquee>
</body>
</html>
<head>
</head>
<body>
</marquee>
</marquee>
</body>
</html>
Slide-In Images
<html>
</marquee>
</html>