HTML Tutorial
HTML Tutorial
HTML Tutorial
HTML Tutorial
Tutorial for Beginners and Web Developers
This HTML Tutorial documentation was prepared to support beginners. We
tried our best to make the content so simple for understanding. Feel free to
mail us for suggestions. Visit: http://iotearth.in for more.
http://iotearth.in
Technology for You
2/11/2016
HTML Introduction
What is HTML?
HTML stands for hypertext markup language used to describe the structure of web pages
using markup. HTML is a scripting language used to develop static web pages. HTML code
is edited in any editors including note pad and even in IDEs. The edited code is executed in
any browser. Browsers eliminate the tags used and just present the content we intended to
without or with applied formatting. HTML elements are represented as tags which is a single
or a group of characters enclosed within angular brackets (<a> or <html>). All HTML tags
are predefined and do not support user-defined tags.
Example Explained
The <!DOCTYPE html> defines as HTML document
The <html> tag is the root element for an HTML page
The <head> tag contains meta information of the document
The <title> tag is used to specify a title to a document
The <body> tag contains the content to display on web page
The <h1> tag defines a maximum heading size
The <p> tag defines content as paragraph
HTML Tags
HTML tags are element names are enclosed by using angle brackets:
Web Browsers
All web browsers HTML documents to dispaly their content in them. The browsers that
supports HTML are Netscape Navigator, Microsoft Internet Explorer, Google Chrome,
Mozilla Firefox etc..
<body>
<!-- web page content here -->
</body>
</html>
HTML Versions
Version
Year
HTML
1991
HTML 2.0
1995
HTML 3.2
1997
HTML 4.01
1999
XHTML
2000
HTML5
2014
HTML Head
The HTML <head> Element
The <head> element is a container for metadata and is placed between the <html> tag and
the <body> tag. Metadata describes the data about the HTML document. Metadata is used to
internal purpose and not displayed. Metadata defines the document title <title>, character set
<meta>, styles <style>, links <link>, scripts <script>, and other meta information.
Example
<!DOCTYPE html>
<html>
<head>
<title>Webpage Title</title>
</head>
<body>
The content of the document......
</body>
</html>
Example
<style>
body {background-color: red;}
h1 {color: green;}
p {color: blue;}
</style>
Example
<link rel="stylesheet" href="mystyle.css">
Example
<meta charset="UTF-8">
<meta name="description" content="Free HTML tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="W3C Schools">
Example
<script>
function myFunction {
document.getElementById("demo").innerHTML = "Hello HTML and JavaScript!";
}
</script>
Example
<!DOCTYPE html>
<title>Page Title</title><h1>This is an important heading</h1>
<p>This is a paragraph ceontent.</p>
Note:
We strongly recomment to use the <html> and <body> tags in order to avoid crashing of
DOM or XML software and produce errors in older browsers like IE9.
Description
<base> Defines a default address or a default target for all links on a page
<link>
Example
<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>
Note: By default all browsers automatically add some white space before and after a heading.
Example
<p>Sample text</p>
<hr>
<p>Sample text</p>
<hr>
Example
<!DOCTYPE html>
<html>
<head>
<title>Welcome to HTML</title>
<meta charset="UTF-8">
</head>
<body>
.
.
.
</body>
</html>
HTML Paragraphs
The HTML <p> element is used to define a paragraph:
Example
<p>This is a paragraph</p>
<p>This is another paragraph</p>
<p>This is yet another paragraph</p>
Note: By default all browsers automatically add some white space before and after a
paragraph.
Example
<p>This is<br>a paragraph<br>with two line breaks.</p>
The <br> tag is an unpaired empty tag, which never has an end tag.
Example
<pre>
This text line 1 is preformatted.
This text line 2 is preformatted.
This text line 3 is preformatted.
</pre>
HTML Styles
This text is in red color
This text is in blue color
Example
<body style="background-color:blue;">
<h1>This is an important heading</h1>
<p>This is a paragraph content.</p>
</body>
Example
<h1 style="color:red;">This is an important heading</h1>
<p style="color:green;">This is a paragraph content.</p>
HTML Fonts
The font-family property is used to define an HTML elements font to be displayed:
Example
<h1 style="font-family:arial;">This is a important heading</h1>
<p style="font-family:courier;">This is a paragraph content.</p>
Example
<h1 style="font-size:100%;">This is an important heading</h1>
<p style="font-size:60%;">This is a paragraph content.</p>
The text-align property is used to define the horizontal text alignment of an HTML element.
By default all the HTML document content is aligned left.
Example
<h1 style="text-align:center;">Centered Important Heading</h1>
<p style="text-align:right;">Paragraph aligned right.</p>
- Bold text
- Important text
- Italic text
- Emphasized text
- Marked text
- Small text
- Deleted text
- Inserted text
- Subscript text
- Superscript text
Description
<abbr>
<address>
<bdo>
<q>
Description
Defines a variable
<pre>
HTML Comments
Comment tags are used to insert comments in the HTML program code.
Conditional Comments
We can also specify conditional based comments in HTML:
<!--[if IE 9]>
.... some HTML here ....
<![endif]-->
This code comments defines some HTML tags to be executed in Internet Explorer only.
HTML Colors
In HTML, a color value can be specified by using a color name with its RGB value, or a
HEX value notation.
Color Names
In HTML, a color can be specified by using a color name:
Example
Color Name
Red
Orange
Yellow
Cyan
Blue
Example
Color
RGB
rgb(255,0,0)
rgb(255,255,0)
rgb(0,255,0)
rgb(0,255,255)
rgb(0,0,255)
HEX Value
HEX values are base 16 numbers. In HTML, a color can also be specified using a
hexadecimal notation value as: #RRGGBB, where RR is for red, GG is for green and BB is
for blue and their hexadecimal values will be in between 00 and FF..
Example
Color
HEX
#FF0000
#FFFF00
#00FF00
#00FFFF
#0000FF
Inline CSS
An inline CSS defines a unique style to a specific HTML element. An inline CSS defines the
style attribute of an HTML element.
Example
<h1 style="color:red;">This is a Red Important Heading</h1>
Internal CSS
An internal CSS defines a style for a single HTML page.
Example
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: red;}
h1 {color: green;}
p {color: blue;}
</style>
</head>
<body>
<h1>This is an important heading</h1>
<p>This is a paragraph content.</p>
</body>
</html>
External CSS
An external style sheet defines the styles which can be applied to an entire website at a time
by choosing one file. <link> element is used in the <head> section of the HTML page to link
the content and their styles:
Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" type=text/css media=screen>
</head>
<body>
<h1>This is an important heading</h1>
<p>This is a paragraph ceontent.</p>
</body>
</html>
An external style sheet can be defined in a separate file and saved with a .css extension.
Here is how the "styles.css" looks:
body {
background-color: red;
}
h1 {
color: green;
}
p{
color: blue;
}
CSS Fonts
The CSS color property defines the text color, font-family property defines the font, fontsize property defines the size of the text.
Example
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
font-family: arial;
font-size: 100%;
}
p {
color: blue;
font-family: verdana;
font-size: 60%;
}
</style>
</head>
<body>
<h1>This is an important heading</h1>
<p>This is a paragraph content.</p>
</body>
</html>
CSS Border
This border property is used to define HTML elements border around it:
Example
p{
border: 1px solid red;
}
CSS Padding
The CSS padding property is used to define a padding or space between the text to the
border:
Example
p{
border: 1px solid red;
padding: 20px;
}
CSS Margin
The CSS margin property is used to define a margin or space outside the border of HTML
element:
Example
p{
border: 1px solid red;
margin: 30px;
}
The id Attribute
This attribute is to define a specific style for a specific element:
<p id="pid1">I am too specific</p>
defines a style for the element with the specific id and is to be unique within a page:
Example
#pid1 {
color: red;
}
then define a style for the elements with the specific class:
Example
p.pclass {
color: red;
}
HTML Links
Links are used to navigate from one page to another page or from one portion of a page to
another portion of the same page.
Example
<a href="http://iotearth.in/html tutorial part-5/">Visit our HTML tutorial</a>
Here href attribute specifies the destination address of the link. The address links can be
specified as either absolute (if source and destination are in different folders) or relative (if
source and destination are within the same folder).
Example
<a href="html_images.bmp">HTML Images</a>
Example
<style>
a:link {color:red; background-color:transparent; text-decoration:underline}
a:visited {color:green; background-color:transparent; text-decoration:underline}
a:hover {color:yellow; background-color:transparent; text-decoration:none}
a:active {color:blue; background-color:transparent; text-decoration:none}
</style>
This example will open the linked document in a new browser window/tab:
Example
<a href="http://iotearth.in/" target="_blank">Visit HTML Tutorial Series!</a>
Example
<a href="http://iotearth.in/html/" target="_top">HTML5 tutorial!</a>
Example
<a href="default.jsp">
<img src="building.jpg" alt="HTML tutorial" style="width:40px;height:40px;border:1;">
</a>
Example
First, create a bookmark with the id attribute:
<h1 id="top"> Top Section</h2>
Example
<a href="html_basics.html#top">Visit the Top Section</a>
HTML Images
Example
<!DOCTYPE html>
<html>
<body>
<h2>Beautiful Scene</h2>
<img src="pic_scene.jpg" alt="Nature View" style="width:200px;height:160px;">
</body>
</html>
Example
<img src="incorrectname.jpg" alt="HTML Icon" style="width:150px;height:150px;">
Example
<img src="html.jpg" alt="HTML Icon" style="width:150px;height:150px;">
Another option is to use the width and height attributes by specifying values in pixels.
Example
<img src="html.jpg" alt="HTML Icon" width="150" height="150">
Note: Always specify the width and height of an image for better visibility.
Example
<!DOCTYPE html>
<html>
<head>
<style>
img {
width:80%;
}
</style>
</head>
<body>
<img src="htmllogo.jpg" alt="HTML Icon" style="width:150px;height:150px;">
<img src="htmllogo.jpg" alt="HTML Icon" width="150" height="150">
</body>
</html>
Example
<img src="/images/htmllogo.jpg" alt="HTML Icon" style="width:150px;height:150px;">
Example
<img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com">
Animated Images
HTML also allows animated images with the GIF standard:
Example
<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px;">
Example
<a href="home.php">
<img src="HTMLlogo.gif" alt="HTML tutorial" style="width:40px;height:40px;border:1;">
</a>
Image Floating
With the use of the CSS float property, we can let the images to float either from right to left
or from left to right:
Example
<p><img src="HTMLlogo.gif" alt="HTML Logo" style="float:right;width:40px;height:40px;">
The image will float to the right of the text.</p>
<p><img src="HTMLlogo.gif" alt="HTML Logo" style="float:left;width:40px;height:40px;">
and creates an association between the image and the map. The <map> tag is specified with a
number of <area> tags, which defines the clickable areas in the image-map:
Example
<img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px;">
<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>
HTML Tables
Defining an HTML Table
To display the table of content on a webpage, HTML defined a tag <table> where the
content can be represented in rows and columns. The <table> tag is considered as a parent tag
(container tag) with <tr> and <td> tags. <tr> tag is used to define the rows and <td> tag
define the content (text, image, list, table.) of an individual cell. Number of <tr> tags used
reflects the number of table rows and number of <td> tags used reflects the number of cells in
each row. A table header is defined with the <th> tag. By default, table headings are bold and
centered.
Example
<table style="width:100%">
<tr>
<th> Firstname</th>
<th> Middlename</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Ronald</td>
<td>Stephen</td>
<td>Rose</td>
<td>25</td>
</tr>
<tr>
<td>St</td>
<td>Anthony</td>
<td>Jain</td>
<td> 30</td>
</tr>
</table>
Example
table, th, td {
border: 2px solid black;
}
We can also define borders for both the table and the table cells.
Example
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
Example
th, td {
padding: 10px;
}
Example
table {
border-spacing: 5px;
}
Note: Border spacing has no effect is identified if the table has collapsed borders.
Example
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Profile</th>
</tr>
<tr>
<td>Nagaraju</td>
<td>9441168122</td>
<td>+91-9441168122</td>
</tr>
</table>
Example
<table style="width:100%">
<tr>
<th>Name:</th>
<td>Nagaraju</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>9441168122</td>
</tr>
<tr>
<td>+91-9441168122</td>
</tr>
</table>
Example
<table style="width:100%">
<caption>Go Green</caption>
<tr>
<th>Go</th>
<th>Green</th>
</tr>
<tr>
<td>Save</td>
<td>Tress</td>
</tr>
<tr>
<td>Save</td>
<td>Power consumption</td>
</tr>
</table>
HTML Lists
HTML defines a provision to represent the content as a sequence of items called list. HTML
allows defining list in 3 ways as Ordered List (arrangement of list items in a proper order)
and Unordered List (arrangement of list items without a order), Description List (to describe
each term in the list).
An Ordered List:
1.
2.
3.
4.
Item1
Item2
Item3
Item4
Example
<ul>
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
Value
disc
Description
Sets the list item with a bullet (default)
Example - Disc
<ul style="list-style-type:disc">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
Example - Circle
<ul style="list-style-type:circle">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
Example - Square
<ul style="list-style-type:square">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
Example - None
<ul style="list-style-type:none">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ul>
Example
<ol>
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ol>
Description
Numbers:
<ol type="1">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ol>
Uppercase Letters:
<ol type="A">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ol>
Lowercase Letters:
<ol type="a">
<li>Pen</li>
<li>Pencil</li>
<li>Eraser</li>
</ol>
Example
<dl>
<dt>Pen</dt>
<dd>- used to write on a paper</dd>
<dt>Eraser</dt>
<dd>- used to erase the written text </dd>
</dl>
Example
<ul>
<li>Pen</li>
<li>Pencil</li>
<ul>
<li>Reynolds Pen</li>
<li>HB Pencil</li>
</ul>
</li>
<li>Eraser</li>
</ul>
Note: List items can contain other HTML elements, like lists, images and links, etc.
Example
<!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: #111111;
}
</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>
Block-level Elements
A block-level element starts in a new line and displays with full available width.
Examples of block-level elements are:
<div>
<h1> - <h6>
<p>
<form>
Inline Elements
An inline element does not start in a new line and displays with necessary width only.
This is an inside inline <span> element a paragraph.
Examples of inline elements are:
<span>
<a>
<img>
Example
<div style="background-color:black;color:white;padding:20px;">
<h2>India</h2>
<p>India is the most beautiful country with rich traditions and human values</p>
</div>
Example
<h1>Most<span style="color:red">Important</span> Heading</h1>
Description
Defines a section in a document (block-level)
Example
<!DOCTYPE html>
<html>
<head>
<style>
div.places {
background-color: black;
color: white;
margin: 20px 0 20px 0;
padding: 20px;
}
</style>
</head>
<body>
<div class="places">
<h2>India</h2>
<p>India is the most ancient country with history of mankind, democracy and human traditions.
Festivals in India bring all religious people together. </p>
</div>
<div class="vehicle">
<h2>Benz</h2>
<p>Benz is a four wheeler car with a great horse power engine best suited to drive on highways and
interior wide roads.</p>
</div>
</body>
</html>
The HTML class attribute can also be used for inline elements:
Example
<!DOCTYPE html>
<html>
<head>
<style>
span.alert {
font-size: 120%;
color: red;
}
</style>
</head>
<body>
<h1>Most <span class="alert">Important</span> Heading</h1>
<p>This is some most <span class="alert">important</span> text.</p>
</body>
</html>
HTML Forms
HTML Form Example
First name:
Nagaraju
Last name:
Mamillapally
An HTML form contains of several form elements used to accept different types of input
elements like text fields, password fields checkboxes, radio buttons, submit button, reset
button and more.
Description
<input type="text">
<input type="radio">
Defines a radio button used for selection one among the choices
Text Input
<input type="text"> defines a one-line input field for text input with a default width of 20
visible characters:
Example
<form>
First name:<br>
<input type="text" name="firstname"><br>
Middle name:<br>
<input type="text" name="middlename">
Last name:<br>
<input type="text" name="lastname">
</form>
Middle name:
Last name:
Example
<form>
<input type="radio" name="gender" value="female" checked>Female<br>
<input type="radio" name="gender" value="male"> Male<br>
<input type="radio" name="gender" value="other"> Other
</form>
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mamillapally"><br>
Last name:<br>
<input type="text" name="lastname" value="Nagaraju"><br><br>
<input type="submit" value="Submit">
</form>
First name:
Mamillapally
Last name:
Nagaraju
If the action attribute is not specified, the action is set to the current page.
or:
<form action="action_page.php" method="post">
Note: GET method is not suitable when sending the sensitive information.
Its better to use POST method always. This method does not display the submitted form data
in the page address field. POST is best suited to send large amount of data.
Example
<form action="action_page.php">
First name:<br>
<input type="text" value="Mamillapally"><br>
Last name:<br>
<input type="text" name="lastname" value="Nagaraju"><br><br>
<input type="submit" value="Submit">
</form>
Example
<form action="action_page.php">
<fieldset>
<legend>Personal information:</legend>
First name:<br>
<input type="text" name="firstname" value="Mamillapally"><br>
Last name:<br>
<input type="text" name="lastname" value="Nagaraju"><br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
Last name:
Nagaraju
Example
<select name="cars">
<option value="vista">Vista</option>
<option value="indica">Indica</option>
<option value="shift">Shift</option>
<option value="dezire">Dezire</option>
</select>
The <option> elements define options to select. By default, the first item in the drop-down
list is selected. To redefine it, add the selected attribute to the option:
Example
<option value="vista" selected>Vista</option>
Example
The rows attribute specifies the number of visible lines in a text area and the cols attribute
specifies the visible width of a text area.
http://iotearth.in is here to provid
Example
<button type="button" onclick="alert('Welcome to HTML')">Click Here!</button>
Example
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
Example
<form>
User name:<br>
<input type="text" name="username"><br>
User password:<br>
<input type="password" name="pwd">
</form>
The characters in a password field are displayed as asterisks or circles for security.
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mamillapally"><br>
Last name:<br>
Last name:
Nagaraju
If you omit the submit button's value attribute, the button will get a default text:
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mamillapally"><br>
Last name:<br>
<input type="text" name="lastname" value="Nagaraju"><br><br>
<input type="submit">
</form>
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mamillapally"><br>
Last name:<br>
<input type="text" name="lastname" value="Nagaraju"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
<input type="radio"> is used to define a radio button. This allows to select only one
option form a limited number of choices.
Example
<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>
Example
<form>
<input type="checkbox" name="vehicle1" value="Car"> I own a car <br>
<input type="checkbox" name="vehicle2" value="Bike"> I have a bike
</form>
Example
HTML Iframes
An iframe is HTML element used to display a web page within a web page.
Iframe Syntax
An HTML iframe is defined with the tag <iframe>:
<iframe src="URL"></iframe>
The src attribute specifies the URL of the inline frame page.
Example
<iframe src="demo_iframe.htm" height="200" width="300"></iframe>
Example
<iframe src="demo_iframe.htm" style="border:none;"></iframe>
HTML defines the change of size, color and style of the iframe's border using CSS.
Example
<iframe src="demo_iframe.htm" style="border:2px solid grey;"></iframe>
Example
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="http://iotearth.in" target="iframe_a">IoTandEarth</a></p>
Description
Note: Our authors followed the standards recommendations by W3C Schools to make the
documentation simple to learn. This document is prepared to support students, instructors
who are interested in web development and is not meant for
commercial purpose.