HTML&HTML 5
HTML&HTML 5
<!DOCTYPE>
<html>
<body>
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph.</p>
</body>
</html>
What is HTML
Hyper Text: Hyper Text simply means "Text within Text". A text has a link
within it, is a hypertext. Every time when you click on a word which brings
you to a new webpage, you have clicked on a hypertext.
An HTML document is made of many HTML tags and each HTML tag contains
different content.
<html>
<head>
<title>Page title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html>
<!doctype HTML>
The <!DOCTYPE> Declaration represents the document type, and helps the
browser to display a web page correctly.
It must only appear once, at the top of the page (before any HTML tags).
There are different document types. To display a web page correctly, the
browser must know both type and version.
The doctype declaration is not case sensitive. All cases are acceptable.
HTML Title
HTML title tag is used to provide a title name for your webpage.
The HTML title tag must be used inside the <head> tag.
The title of the page is displayed on the title bar of the browser.
Here you see that we are using two elements, the head tag and the title tag.
The whole title element is within the head tag.
The head element which appears before body element just contains the
information about the page but it doesn't display on the browser window.
So, to display a title name on the web page, title element is used.
If you look at the above example, you will see that "First web page" will be
displayed on the tab/ title bar of the browser. Content(text) between
<title>.............</title> is shown on the title bar.
Test it Now
Description of HTML example
Features of HTML
4) It facilitates programmers to add link on the web pages (by html anchor
tag) , so it enhances the interest of browsing of the user.
HTML tags contain three main parts: opening tag, content and closing tag.
But some HTML tags are unclosed tags.
When a web browser reads an HTML document, browser reads it from top to
bottom and left to right. HTML tags are used to create HTML documents and
render their properties. Each HTML tags have different properties.
Syntax
Examples
Note: HTML Tags are always written in lowercase letters. The basic HTML
tags are given below:
Some HTML tags are not closed, for example br and hr.
<br> Tag: br stands for break line, it breaks the line of the code.
<hr> Tag: hr stands for Horizontal Rule. This tag is used to put a line
across the webpage.
HTML Text Tags
<p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <strong>, <em>, <abbr>,
<acronym>, <address>, <bdo>, <blockquote>, <cite>, <q>, <code>,
<ins>, <del>, <dfn>, <kbd>, <pre>, <samp>, <var> and <br>
<a>
table, tr, td, th, tbody, thead, tfoot, col, colgroup and caption
form, input, textarea, select, option, optgroup, button, label, fieldset and
legend
HTML Formatting
HTML Formatting is a process of formatting text for better look and feel.
There are many formatting tags in HTML. These tags are used to make
text bold, italicized, or underlined. There are almost 12 options available
that how text appears in HTML and XHTML.
1) Bold Text
2) Italic Text
If you want to mark or highlight a text, you should write the content
within <mark>.........</mark>.
5) Strike Text
Output:
6) Monospaced Font
If you want that each letter has the same width then you should write the
content within <tt>.............</tt> element.
Note: We know that most of the fonts are known as variable-width fonts
because different letters have different width. (for example: 'w' is wider
than 'i'). Monospaced Font provides similar space among every letter.
7) Superscript Text
8) Subscript Text
Output:
9) Deleted Text
Output:
If you want to put your font size larger than the rest of the text then put
the content within <big>.........</big>. It increase one font size larger
than the previous one.
Output:
If you want to put your font size smaller than the rest of the text then put
the content within <small>.........</small>tag. It reduces one font size
than the previous one.
See this example:
HTML Heading
There are six different HTML headings which are defined with the <h1> to
<h6> tags.
h1 is the largest heading tag and h6 is the smallest one. So h1 is used for
most important heading and h6 is used for least important.
Attribute:- only one attribute use with this tag is align, whose values are
left, center, right and justify.
Heading no. 1
Heading no. 2
Heading no. 3
Heading no. 4
Heading no. 5
Heading no. 6
HTML Paragraph
Output:
If you put a lot of spaces inside the HTML p tag, browser removes extra
spaces and extra line while displaying the page. The browser counts number
of spaces and lines as a single one.
<p>
I am
going to provide
you a tutorial on HTML
and hope that it will
be very beneficial for you.
</p>
<p>
Look, I put here a lot
of spaces but I know, Browser will ignore it.
</p>
<p>
You cannot determine the display of HTML</p>
<p>because resized windows may create different result.
</p>
Output:
I am going to provide you a tutorial on HTML and hope that it will be very
beneficial for you.
Look, I put here a lot of spaces but I know, Browser will ignore it.
Attribute:- only one attribute use with this tag is align, whose values are
left, center, right and justify.
HTML Anchor
The HTML anchor tag defines a hyperlink that links one page to another
page. The "href" attribute is the most important attribute of the HTML a tag.
The href attribute is used to define the address of the file to be linked. In
other words, it points out the destination page.
Option Description
Example
Following example makes use of <base> tag to *specify base URL and later
we can use relative path to all the links instead of giving complete URL for
every link.t/
<!DOCTYPE html>
<html>
<head>
<title>Hyperlink Example</title>
<base href="http://www.learnerspoint.com/">
</head>
<body>
<p>Click following link</p>
<a href="/html/index.htm" target="_blank">HTML Tutorial</a>
</body>
</html>
First create a link to the place where you want to reach with-in a webpage
and name it using <a...> tag as follows:
Second step is to create a hyperlink to link the document and place where
you want to reach:
This will produce following link, where you can click on the link
generated Go to the Top to reach to the top of the HTML Text Link s.
Go to the Top
mailto link
Mailto link is a type of HTML link that activates the default mail client on the
computer for sending an e-mail.
The web browser requires a default e-mail client software installed on his computer
in order to activate the e-mail client.
If you have Microsoft Outlook, for example as your default mail client, pressing a
mailto link will open a new mail window.
The mailto link is written like regular link with extra parameters inside the href
attribute:
<a href="mailto:[email protected]">Link text</a>
Parameter Description
HTML img tag is used to display image on the web page. HTML img tag is
an empty tag that contains attributes only, closing tags are not used in
HTML image element.
Output:
The src and alt are important attributes of HTML img tag. All attributes of
HTML image tag are given below.
1) src
The alt attribute defines an alternate text for the image, if it can't be
displayed. The value of the alt attribute describe the image in words. The alt
attribute is considered good for SEO prospective.
3) width
4) height
It specifies the height of the image. The HTML height attribute also supports
iframe, image and object elements. It is not recommended now. You should
apply CSS in place of height attribute.
HTML Table
HTML table tag is used to display data in tabular form (row * column).
There can be many columns in a row.
HTML tables are used to manage the layout of the page e.g. header section,
navigation bar, body content, footer section etc. But it is recommended to
use div tag over table to manage the layout of the page .
Tag Description
formatting.
<table>
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></t
r>
<tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
<tr><td>James</td><td>William</td><td>80</td></tr>
<tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
<tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
</table>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
You can use border attribute of table tag in HTML to specify border. But it is
not recommended now.
<table border="1">
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></t
r>
<tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
<tr><td>James</td><td>William</td><td>80</td></tr>
<tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
<tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
</table>
Output:
James William 80
Swati Sironi 82
Chetna Singh 72
<style>
table, th, td {
border: 1px solid black;
}
</style>
You can collapse all the borders in one border by border-collapse property.
<style>
table, th, td {
border: 2px solid black;
border-collapse: collapse;
}
</style>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
You can specify padding for table header and table data by two ways:
<style>
table, th, td {
border: 1px solid pink;
border-collapse: collapse;
}
th, td {
padding: 10px;
}
</style>
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
HTML Table with colspan
If you want to make a cell span more than one column, you can use the
colspan attribute.
CSS code:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
HTML code:
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Mobile No.</th>
</tr>
<tr>
<td>Ajeet Maurya</td>
<td>7503520801</td>
<td>9555879135</td>
</tr>
</table>
Output:
Name Mobile No.
If you want to make a cell span more than one row, you can use the
rowspan attribute.
CSS code:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 10px;
}
1. </style>
HTML code:
<table>
<tr><th>Name</th><td>Ajeet Maurya</td></tr>
<tr><th rowspan="2">Mobile No.</th><td>7503520801</td></tr>
<tr><td>9555879135</td></tr>
</table>
Output:
HTML caption is diplayed above the table. It must be used after table tag
only.
<table>
<caption>Student Records</caption>
<tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></t
r>
<tr><td>Vimal</td><td>Jaiswal</td><td>70</td></tr>
<tr><td>Mike</td><td>Warn</td><td>60</td></tr>
<tr><td>Shane</td><td>Warn</td><td>42</td></tr>
<tr><td>Jai</td><td>Malhotra</td><td>62</td></tr>
</table>
CSS code:
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 10px;
}
table#alter tr:nth-child(even) {
background-color: #eee;
}
table#alter tr:nth-child(odd) {
background-color: #fff;
}
table#alter th {
color: white;
background-color: gray;
}
</style>
Output:
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain one
or more list elements. There are three different types of HTML lists:
In the ordered HTML lists, all the list items are marked with numbers. It is
known as numbered list also. The ordered list starts with <ol> tag and the
list items start with <li> tag.
<ol>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ol>
Output:
1. Aries
2. Bingo
3. Leo
4. Oracle
Attributes
1) The type attribute for <ol> tag to specify the type of numbering you like. By
default it is a number.
2) The start attribute for <ol> tag to specify the starting point of numbering
you need.
In HTML Unordered list, all the list items are marked with bullets. It is also
known as bulleted list also. The Unordered list starts with <ul> tag and list
items start with the <li> tag.
<ul>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ul>
Output:
o Aries
o Bingo
o Leo
o Oracle
You can use type attribute for <ul> tag to specify the type of bullet you
like. By default it is a disc. Following are the possible options:
<ul type="square">
<ul type="disc">
<ul type="circle">
HTML Description list is also a list style which is supported by HTML and
XHTML. It is also known as definition list where entries are listed like a
dictionary or encyclopedia.
The definition list is very appropriate when you want to present glossary, list
of terms or other name-value list.
<dl>
<dt>Aries</dt>
<dd>-One of the 12 horoscope sign.</dd>
<dt>Bingo</dt>
<dd>-One of my evening snacks</dd>
<dt>Leo</dt>
<dd>-It is also an one of the 12 horoscope sign.</dd>
<dt>Oracle</dt>
<dd>-It is a multinational technology corporation.</dd>
</dl>
Output:
Aries
Bingo
Leo
Oracle
Marquee HTML
In simple words, you can say that it scrolls the image or text up, down, left
or right automatically.
Attribute Description
Width This specifies the width of the marquee. This can be a value like 10
or 20% etc.
height This specifies the height of the marquee. This can be a value like
10 or 20% etc.
direction This specifies the direction in which marquee should scroll. This can
be a value like up, down, left or right.
behavior This specifies the type of scrolling of the marquee. This can have a
value like scroll, slide and alternate.
scrolldelay This specifies how long to delay between each jump. This will have
a value like 10 etc.
scrollamount This specifies the speed of marquee text. This can have a value like
10 etc.
Loop This specifies how many times to loop. The default value is
INFINITE, which means that the marquee loops endlessly.
bgcolor This specifies background color in terms of color name or color hex
value.
hspace This specifies horizontal space around the marquee. This can be a
value like 10 or 20% etc.
vspace This specifies vertical space around the marquee. This can be a
value like 10 or 20% etc.
HTML Textarea
The size of the HTML textarea is defined by <cols> and <rows> attribute, or
it can also be defined through CSS height and width properties.
HTML Quotes
HTML quotes are used to put a short quotation on your website. To do so,
you need to use HTML q tag and HTML blockquote tag.
HTML q tag
HTML q tag is used to put small quotation. To do so, write your text within
<q>.............</q> tag.
Output:
Dr. Seuss once said : Reality is finally better than your dreams.
Output:
According to scientists, the bumblebee's body is too heavy and its wing span
too small. Aerodynamically, the bumblebee cannot fly. But the bumblebee
doesn't know that and it keeps flying. When you don't know your limitations,
you go out and surprise yourself. In hindsight, you wonder if you had any
limitations. The only limitations a person has are those that are self-
imposed. Don't let education put limitations on you.
Tag Description
<address> It is used to define the contact information of the document writer. The
<address> element is usually displayed in italic
<address>
Visit us at:<br/>
Example.com<br/>
html
</address>
<cite> It defines the title of source from where quotation or work is taken in
italic.
HTML Style
HTML Style is used to change or add the style on existing HTML elements.
There is a default style for every HTML element e.g. background color is
white, text color is black etc.
The style attribute can by used with any HTML tag. To apply style on HTML
tag, you should have the basic knowledge of css properties e.g. color,
background-color, text-align, font-family, font-size etc.
style= "property:value"
HTML Style color
Output:
Output:
The font-family property specifies the font family of the HTML tag.
<h3 style="font-
family:times new roman">This is times new roman font family</h3>
<p style="font-family:arial">This is arial font family</p>
Output:
The font-size property is used to define the text size of the HTML tag.
Output:
The text-align property is used to define the horizontal text alignment for
the HTML element.
<h3 style="text-align:right;background-
color:pink;">This text is located at right side</h3>
<p style="text-align:center;background-
color:pink;">This text is located at center side</p>
Output:
HTML <b> tag is used to display the written text in bold format. It is
strictly a presentational element. If you want to show your text in bold
letters and not have real semantic meaning, then put it within
<b>.......</b> tag.
The b tag is explicit whereas strong tag is semantic.The <strong> tag adds
extra semantic meaning to the HTML document.
HTML hr tag
HTML br tag
You can use HTML br tag two ways: <br> or <br/>. It is recommended to
use closed br tag <br/> because it is supported in HTML and XHTML both.
In HTML br tag need not to be closed e.g. <br> whereas br tag must be
properly closed in XHTML e.g. <br/>.
HTML Div Tag
The HTML <div> tag is used to group the large section of HTML elements
together.
We know that every tag has a specific purpose e.g. p tag is used to specify
paragraph, <h1> to <h6> tag are used to specify headings but the <div>
tag is just like a container unit which is used to encapsulate other page
elements and divides the HTML documents into sections.
The div tag is generally used by web developers to group HTML elements
together and apply CSS styles to many elements at once. For example: If
you wrap a set of paragraph elements into a div element so you can take the
advantage of CSS styles and apply font style to all paragraphs at once
instead of coding the same style for each paragraph element.
Output:
HTML div element is used to wrap HTML span element is used to wrap small
large sections of elements. portion of texts, image etc.
HTML pre tag
The HTML <pre> tag is used to specify pre formatted texts. Texts within
<pre>.......</pre> tag is displayed in a fixed-width font. Usually it is
displayed in Courier font. It maintains both space and line break.
<pre>
Text in a pre element
is displayed in a fixed-width
font, and it preserves
both spaces and
line breaks
</pre>
The <label> tag is used to specify a label for an <input> element. It adds a
label to a form control such as text, email, password, textarea etc.
<label for="email">EMAIL-
ID:<br /> <input type="text" name="emailid" size="30"><br /><br />
<label for="phone">PHONE NO:<br /> <input type="text" name="phno"
size="30"
maxlength="10" pattern="[0-9]{10}"><br /><br />
The HTML <input> tag is used to represent a form input control in HTML
document. This form input control facilitate user to input data and
communicate with a website or application. Let's take an example of an
HTML form with three input fields, two text fields and one button for
submission.
<form action="#">
First name: <input type="text" name="FirstName" ><br>
Last name: <input type="text" name="LastName" ><br>
<input type="submit" value="Submit">
</form>
Output:
First name:
Last name:
Submit
Click the "Submit" button for sending the form-data to a page on the server.
Points to remember
1) Use the input element within the form element to declare input control
that allow user to enter data.
3) If you want to define labels for input element, use the label element with
each input tag.
HTML5
HTML5 is a next version of HTML. Here, you will get some brand new features which
will make HTML much easier. These new introducing features make your website
layout clearer to both website designers and users.
• It is enriched with advance features which makes it easy and interactive for
designer/developer and users.
• It allows you to play a video and audio file.
• It allows you to draw on a canvas.
• It facilitate you to design better forms and build web applications that work
offline.
• It provides you advance features for that you would normally have to write
JavaScript to do.
The most important reason to use HTML 5 is, we believe it is not going anywhere. It
will be here to serve for a long time according to W3C recommendation.
<!DOCTYPE>
<html>
<body>
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph.</p>
</body>
</html>
Supporting Browsers
HTML audio tag is used to define sounds such as music and other audio clips.
Currently there are three supported file format for HTML 5 audio tag.
1. mp3
2. wav
3. ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar
technologies are used to play the multimedia items.
This table defines that which web browser supports which audio file format.
Let's see the code to play mp3 file using HTML audio tag.
<audio controls>
<source src="koyal.mp3" type="audio/mpeg">
Your browser does not support the html audio tag.
</audio>
Output:
Let's see the example to play ogg file using HTML audio tag.
<audio controls>
<source src="koyal.ogg" type="audio/ogg">
Your browser does not support the html audio tag.
</audio>
Attribute Description
controls It defines the audio controls which is displayed with play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, every time when it is
completed.
preload It specifies the author view to upload audio file when the page loads.
Here we are going to use controls, autoplay, loop and src attributes of HTML audio
tag.
<audio controls autoplay loop>
<source src="koyal.mp3" type="audio/mpeg"></audio>
mp3 audio/mpeg
ogg audio/ogg
wav audio/wav
HTML 5 supports <video> tag also. The HTML video tag is used for streaming video
files such as a movie clip, song clip on the web page.
Currently, there are three video formats supported for HTML video tag:
1. mp4
2. webM
3. ogg
Let's see the table that defines which web browser supports video file format.
Let's see the code to play mp4 file using HTML video tag.
<video controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the html video tag.
</video>
Let's see the example to play ogg file using HTML video tag.
<video controls>
<source src="movie.ogg" type="video/ogg">
Your browser does not support the html video tag.
</video>
controls It defines the video controls which is displayed with play/pause buttons.
poster It specifies the image which is displayed on the screen when the video is not
played.
autoplay It specifies that the video will start playing as soon as it is ready.
loop It specifies that the video file will start over again, every time when it is
completed.
preload It specifies the author view to upload video file when the page loads.
Let's see the example of video tag in HTML where are using height, width, autoplay,
controls and loop attributes.
mp4 video/mp4
ogg video/ogg
webM video/webM
HTML Graphics
HTML Canvas Tag
The HTML canvas element provides HTML a bitmapped surface to work with. It is
used to draw graphics on the web page.
The HTML 5 <canvas> tag is used to draw graphics using scripting language like
JavaScript.
The <canvas> element is only a container for graphics, you must need a scripting
language to draw the graphics. The <canvas> element allows for dynamic and
scriptable rendering of 2D shapes and bitmap images.
It is a low level, procedural model that updates a bitmap and does not have a built-
in scene. There are several methods in canvas to draw paths, boxes, circles, text
and add images.
Example
Note: It is always necessary to specify the id attribute and the height &
width attribute to define the size of the canvas. You can have multiple
canvas elements on one HTML page.
The canvas element has a DOM method called getContext, used to obtain
the rendering context and its drawing functions. This function takes one
parameter, the type of context 2d.
Coordinates (0,0) defines the upper left corner of the canvas. The parameters
(0,0,200,100) is used for fillRect() method. This parameter will fill the rectangle
start with the upper-left corner (0,0) and draw a 200 * 100 rectangle.
If you want to draw a straight line on the canvas, you can use the following two
methods.
If you draw a line which starting point is (0,0) and the end point is (200,100), use
the stroke method to draw the line.
4 fill() - This method fills the subpaths with the current fill style.
5 stroke() - This method strokes the subpaths with the current stroke
style.
If you want to draw a circle on the canvas, you can use the arc() method:
To sketch circle on HTML canvas, use one of the ink() methods, like stroke() or
fill().
<script type="text/javascript">
function drawShape(){
// get the canvas element using the DOM
var canvas = document.getElementById('mycanvas');
// Make sure we don't execute when canvas isn't supported
if (canvas.getContext){
// use getContext to use the canvas for drawing
var ctx = canvas.getContext('2d');
// Draw shapes
ctx.beginPath();
ctx.arc(75,75,50,0,Math.PI*2,true); // Outer circle
ctx.moveTo(110,75);
ctx.arc(75,75,35,0,Math.PI,false); // Mouth
ctx.moveTo(65,65);
ctx.arc(60,65,5,0,Math.PI*2,true); // Left eye
ctx.moveTo(95,65);
ctx.arc(90,65,5,0,Math.PI*2,true); // Right eye
ctx.stroke();
}
else {
alert('You need Safari or Firefox 1.5+ to see this demo.');
}
}
</script>
</head>
There are property and methods used for drawing text on the canvas.
font property: It is used to define the font property for the text.
strokeText(text,x,y) method: It is also used to draw text on the canvas, but the
text is unfilled.
HTML SVG
The HTML SVG is an acronym which stands for Scalable Vector Graphics.
SVG is mostly used for vector type diagrams like pie charts, 2-Dimensional
graphs in an X,Y coordinate system etc.
The <svg> element specifies the root of a SVG fragment. You can animate every
element and every attribute in SVG files.
1) Draw a circle
Here, we are using cx, cy and r attributes of circle tag. These attributes can't be
used with svg rect tag.
2) Draw Rectangle
SVG images can be saved as the smallest size possible. Unlike bitmap image
formats like JPG or PNG, it does not contain a fixed set of dots. So it is also easy
to print with high quality at any resolution.
SVG images can be zoomed to a certain level without degradation of the picture
quality.
SVG images and their behaviors are defined in XML text files, so they can be
created and edited with any text editor.
HTML Drag and Drop(NTD)
HTML Drag and Drop (DnD) is a feature of HTML5. It is a powerful user interface
concept which is used to copy, reorder and delete items with the help of mouse.
You can hold the mouse button down over an element and drag it to another
location. If you want to drop the element there, just release the mouse button.
If you want to achieve the Drag and Drop functionality in traditional HTML4, you
must either have to use complex JavaScript programming or other JavaScript
frameworks like jQuery etc.
Event Description
Drag It fires every time when the mouse is moved while the object is being dragged.
Dragstart It is a very initial stage. It fires when the user starts dragging object.
Dragenter It fires when the user moves his/her mouse cursur over the target element.
Dragover This event is fired when the mouse moves over an element.
Dragend It fires when user releases the mouse button to complete the drag operation.
<script>
function allowDrop(ev) {ev.preventDefault();}
function drag(ev) {ev.dataTransfer.setData("text/html", ev.target.id);}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text/html");
ev.target.appendChild(document.getElementById(data));
}
</script>
<p>Drag the learners image into the rectangle:</p>
<div id="div1" style="width:350px;height:100px;padding:10px;border:1px solid #
aaaaaa;"
ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<br>
<img id="drag1" src="/htmlpages/images/learners.png" alt="learners image"
draggable="true" ondragstart="drag(event)"/>
If you want to make an element draggable, set the draggable attribute to "true" on
the element. For example:
2) What to drag:
3) Where to Drop:
The HTML progress tag is new in HTML5 so you must use new browsers.
HTML <progress> tag supports the global and event attributes as well as 2 specific
attributes.
Tag Description
value It defines that how much work the task has been completed.
max It defines that how much work the task requires in total.
The progress tag should be used to represent progress of a task only, not
for just a gauge (disk pace usage). For such purpose, <meter> element is
used.
Let's see the progress example with value and max attributes.
Downloading progress:
<progress value="43" max="100"></progress>
The <progress> tag should be used in conjunction with JavaScript to display the
progress of a task.
<script>
var gvalue=1;
function abc(){
var progressExample = document.getElementById ('progress-javascript-
example');
setInterval (function ()
{
if(gvalue<100){
gvalue++;
progressExample.value =gvalue;
}
abc();
}, 1000);
}
</script>
<progress id="progress-javascript-
example" min="1" max="100"></progress>
<br/><br/>
<button onclick="abc()">click me</button>
The HTML <data> tag is used to provide a machine readable version of its own
contents. It displays the data in a special format. It is useful in the case where your
data needs to be in a certain format because it may be processed by a script, but
this might not be the format that you'd like your users to see.
There is only one required attribute. The data tag supports global and event
attributes also.
Attribute Description
<ul>
<li><data value="101">Java Tutorial</data></li>
<li><data value="111">SQL tutorial</data></li>
<li><data value="121">HTML tutorial</data></li>
</ul>
Output:
o Java Tutorial
o SQL tutorial
o HTML tutorial
HTML Datalist Tag
The HTML <datalist> tag is used to provide an auto complete feature on form
element. It provides a list of predefined options to the users to select data.
The <datalist> tag should be used with an <input< element that contains a "list"
attribute. The value of "list" attribute is linked with the datalist id.
The HTML datalist tag supports global and event attributes also.
Let's see the simple example of HTML5 datalist tag. If you press A, it will show a list
of cricketers starting with A letter.
<label>
Enter your favorite cricket player: Press any character<br />
<input type="text" id="favCktPlayer" list="CktPlayers">
<datalist id="CktPlayers">
<option value="Sachin Tendulkar">
<option value="Brian Lara">
<option value="Jacques Kallis">
<option value="Ricky Ponting">
<option value="Rahul Dravid">
<option value="Shane Warne">
<option value="Rohit Sharma">
<option value="Donald Bradman">
<option value="Saurav Ganguly ">
<option value="AB diVilliers">
<option value="Mahendra Singh Dhoni">
<option value="Adam Gilchrist">
</datalist>
</label>
HTML5 - Geolocation
HTML5 Geolocation API lets you share your location with your favorite web
sites. A Javascript can capture your latitude and longitude and can be sent
to backend web server and do fancy location-aware things like finding local
businesses or showing your location on a map.
Today most of the browsers and mobile devices support Geolocation API.
The geolocation APIs work with a new property of the global navigator
object ie. Geolocation object which can be created as follows:
Geolocation Methods
The geolocation object provides the following methods −
Method Description
function getLocation() {
var geolocation = navigator.geolocation;
geolocation.getCurrentPosition(showLocation, errorHandler);
}
A semantic element clearly describes its meaning to both the browser and
the developer.
HTML5 offers new semantic elements to define different parts of a web page:
• <article>
• <aside>
• <details>
• <figcaption>
• <figure>
• <footer>
• <header>
• <main>
• <mark>
• <nav>
• <section>
• <summary>
• <time>
HTML Header Tag
You can use several <header> elements in one document, but a <header> element
cannot be placed within a <footer>, <address> or another <header> element.
<header>
<h2>ABCOnline.com</h2>
<p> World's no.1 shopping website</p>
</header>
CSS Code:
header{
border: 1px solid pink;
background-color:pink;
padding:10px;
border-radius:5px;
}
HTML Code:
<header>
<h2>ABCOnline</h2>
<p> World's no.1 shopping website</p>
</header>
HTML <footer> tag contains information about its containing elements for example:
o author information
o contact information
o copyright information
o sitemap
o back to top links
o related documents etc.
Note: You can have one or many footer elements in one document.
If you want to put information like address, e-mail etc. about the author on your
web page, all the relevant elements should be included into the footer element.
<footer>
<p>Posted by: Abc hybd</p>
<p>
<address> Learners, plot no. 6, near MX Mall,Nehru Nagar, Pune
</address>
</p>
<p>Contact information:
<a href="mailto:[email protected]">Email Me</a>.
</p>
</footer>
HTML figure tag
HTML <figure> tag is used to mark up a photo in the document on a web page.
As we know image tag is already available in HTML to display the pictures on web
pages. But HTML 5 <figure> tag is used to handle the group of diagrams, photos,
code listing etc. with some embedded content. You can also add a caption for the
photo with the help of <figcaption> tag.
<p>The Taj Mahal is widely recognized as "the jewel of Muslim art in India and
one of the universally admired masterpieces of the world's heritage". It is regarded
by many as the finest example of Mughal architecture, a style that combines eleme
nts from Islamic, Persian, Ottoman, Turkish and Indian architectural styles.</p>
<figure>
<img src="htmlpages/images/tajmahal.jpg" alt="Taj Mahal"/>
</figure>
Output:
The Taj Mahal is widely recognized as "the jewel of Muslim art in India and one of
the universally admired masterpieces of the world's heritage". It is regarded by
many as the finest example of Mughal architecture, a style that combines elements
from Islamic, Persian, Ottoman, Turkish and Indian architectural styles.
Note: The content you put within <figure>.......</figure> tag is related to
the main flow, but its position is independent of the main flow and does
not affect the flow the document when removed.
Note: HTML figure tag also supports the global and event attribute in
HTML.
It is an optional tag and can appear before or after the content within the <figure>
tag.
Only one <figcaption> element can be nested within a <figure> tag although the
<figure> element itself may contain multiple other elements like <img> or
<code>.
The <figcaption> element is used with <figure> element and it can be placed as
the first or last child of the <figure> element.
<figure>
<img src="htmlpages/images/tajmahal.jpg" alt="Taj Mahal"/>
<figcaption>Fig.1.1 -
A front view of the great Taj Mahal in Agra.</figcaption>
</figure>
Output:
The article tag content makes sense on its own. It is independent and complete
from other content shown on the page. This tag is generally used on Forum post,
Blog post, News story, comment etc.
<article>
<h2>Narendra Modi</h2>
<i>Prime Minister Of India </i>
<p>Narendra DamodarDas Modi is the 15th and current Prime Minister of India,
Modi, a leader of the Bharatiya Janata Party (BJP), previously served as the Chief
Minister of Gujarat state from 2001 to 2014. He is currently the Member of Parliam
ent (MP) from Varanasi. </p>
</article>
Output:
Narendra Modi
Narendra DamodarDas Modi is the 15th and current Prime Minister of India, Modi, a
leader of the Bharatiya Janata Party (BJP), previously served as the Chief Minister
of Gujarat state from 2001 to 2014. He is currently the Member of Parliament (MP)
from Varanasi.
HTML article tag also supports global and event attributes in HTML.
HTML Dialog Tag
HTML <dialog> tag to create a new popup dialog on a web page. This tag
represents a dialog box or other interactive component like window.
The <dialog> element uses a boolean attribute called open that activate element
and facilitate user to interact with it.
<div>
<dialog id="myFirstDialog" style="width:50%;background-
color:#F4FFEF;border:1px dotted black;">
<p><q>I am so clever that sometimes I don't understand a single word of
what I am saying.
</q> - <cite>Oscar Wilde</cite></p>
<button id="hide" onclick="hided()">Close</button>
</dialog>
<button id="show" onclick="showd()">Show Dialog</button>
</div>
<!-- JavaScript to provide the "Show/Close" functionality -->
<script type="text/JavaScript">
var dialog=document.getElementById("myFirstDialog");
function showd() {
dialog.show();
}
function hided(){
dialog.close();
}
</script>
HTML Details Tag
HTML <details> tag is used to specify the additional details on the web page that
the user can view or hide on demand.
According to W3C HTML specification, it is used as a disclosure widget from which
user can retrieve additional information or control.
The <details> tag wraps all the content which you want to show or hide and the
<summary> tag contains the summary and the title of the section.
HTML details tag also supports global and event attributes in HTML.
Attribute Description
open It specifies that the details will be displayed (open) to the user.
<details>
<summary>Copyright 2011-2014.</summary>
<p> - by Learners. All Rights Reserved.</p>
<p>All content and graphics on this web site are the property of the learners</p>
</details>
<p><b>Note:</b> The details tag is currently only supported in Opera, Chrome,
and in Safari 6.</p>
Output:
Copyright 2011-2014.
Note: The details tag is currently only supported in Opera, Chrome, and in Safari 6.
HTML Summary Tag
The HTML <summary> tag is used with <details> tag. It is used as a summary,
caption or legend for the content of a <details> element.
<details>
<summary>Learner Summary</summary>
<p> Learning is a quite good habit.</p>
<p>You can learn various technologies such as HTML, CSS, JavaScript, Java, Andr
oid.</p>
</details>
<details>
<summary>MacBook Pro Specification</summary>
<ul>
<li><strong>13.3-inch LED-
backlit glossy widescreen display</strong> with edge-to-
edge, uninterrupted glass (1280 x 800-pixel resolution).</li>
<li><strong>2.4 GHz Intel Core i5 dual-
core processor</strong> with 3 MB shared L3 cache for excellent multitasking.</
li>
<li><strong>Intel HD Graphics 3000</strong> with 384 MB of DDR3 SDRA
M shared with main memory.</li>
<li><strong>500 GB Serial ATA hard drive</strong> (5400 RPM)</li>
<li><strong>4 GB installed RAM</strong> (1333 MHz DDR3; supports up t
o 8 GB)</li>
</ul>
</details>
HTML Section Tag
The HTML <section> tag is used to define sections in a document. When you put
your content on a web page, it may contains many chapters, headers, footers, or
other sections on a web page that is why HTML <section> tag is used.
CSS code:
section{
border:1px solid pink;
padding:15px;
margin:10px;
}
HTML code:
Output:
Indian Leader
Jawaharlal Nehru
Jawaharlal Nehru was the first Prime Minister of India and a central figure in Indian
politics for much of the 20th century. He emerged as the paramount leader of the
Indian independence movement under the tutelage of Mahatma Gandhi. -Source
Wikipedia
Subhas Chandra Bose was an Indian nationalist whose attempt during World War II
to rid India of British rule with the help of Nazi Germany and Japan left a troubled
legacy. The honorific Netaji (Hindustani language: "Respected Leader"), first
applied to Bose in Germany, by the Indian soldiers of the Indische Legion and by
the German and Indian officials in the Special Bureau for India in Berlin, in early
1942, is now used widely throughout India. -source Wikipedia
an image map is one image with multiple "clickable" areas. i.e., An Image maps allow
you to make certain areas of an image into links. There are two types of image maps;
server side and client side.
For a server side image map, put an image inside a link, and set the ISMAP attribute on
the IMG (just the name, it does not need a value). When the link is clicked, the browser
will request the given link, and add ?x,y on the end of it. If the user is not using a mouse
(or equivalent), then the coordinates will be 0,0.
With a client side image map, you can specify a list of areas that will be used as the
links. This gives the user the chance to see immediately if where they are about to click
is somewhere useful, as opposed to the server-side image map where they must wait
for the reply from the server to tell them.
The basic idea behind an image map is that you combine two different components:
There are four types of linked areas on Map; rectangles, circles, polygons and default.
Image
First of all, you need a suitable graphic. You need to be a bit careful when choosing the
right image. An image that cannot be divided in different sections is not your best
choice, but an image that has clear cut-offs or lines would be better. Of course, this
down not apply to navigational menus or similar, just to everyday pictures like animals,
objects or people.
-Co-ordinates
When you've chosen or created your desired image, you then insert it into an image
editor (i.e Ms Paint) so that you can find its co-ordinates. Try to either write down
different co-ordinates of take them one by one and then insert them into your document.
You'll need different co-ordinates depending on what sort of “area” or "hot spot" you'd
like to use.
Hot Spot
Now that you've got your image and co-ordinates, HTML comes to finalise your job.
There are three different shapes (commonly termed "hot spots" or “areas”) that can be
used in image maps. They are as follows:
-RECT
-CIRCLE
-POLYGON
-Rect
Rect is obviously short for rectangle. For this one, you'll need two different co-ordinates.
Top right and bottom left.
shape="rect" coords="10,20,75,40"
-Circle
This expects three coordinates. The horizontal position of the centre, the vertical
position of the centre and the radius of the circle.
shape="circle" coords="50,80,20"
-Polygon
This expects as many pairs of coordinates as you need to make your polygon.
These can make any polygon shapes you need, and can have sloping lines. All
coordinates are specified as horizontal position then vertical position, with all of
them in a long comma separated list. The last pair of coordinates can optionally
match the first.
shape="poly"
coords="217,305,218,306,218,306,228,316,243,316,243,325,229,325,229,322,217,310
"
<!DOCTYPE html>
<html>
<body>
<p>Click on the sun or on one of the planets to watch it closer:</p>
<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>