html5_note
html5_note
Semantic elements
The HTML5 specification includes a series of new semantic elements that are used
to give some meaning to the various sections or parts of a Web page, such as a
header, footer, navigation, and so on. In previous versions of HTML, you would
typically use <div> elements to create these parts, using ID or class attributes to
differentiate them from each other. The problem with this is that this has no semantic
meaning, as there are no strict rules defined that specify what class names or IDs
are to be used, making it extremely difficult for software to determine what the
particular area is doing. HTML5 should help alleviate these issues, making it easier
for Web browsers to parse the semantic structure of a document.
It is worth pointing out that continuing to use <div> elements in HTML5 is perfectly
valid, but in order to future-proof your work, it is recommended that you use semantic
elements where relevant. On the other side of the coin, it is also suggested that you
avoid using these new elements for purposes other than their intended. For example,
the <nav> element should not be used for just any group of links; it is intended to
surround the main navigation block on the page.
The sample Web site at the end of this tutorial includes several of these new
semantic elements, and I will explain their syntax and use in more detail at that point.
• You can publish documents online with text, images, lists, tables, etc.
• You can access web resources such as images, videos or other HTML
document via hyperlinks.
• You can create forms to collect user inputs like name, e-mail address,
comments, etc.
• You can include images, videos, sound clips, flash movies, applications and
other HTML documents directly inside an HTML document.
• You can create offline version of your website that work without internet.
• You can store data in the user's web browser and access later on.
• You can find the current location of your website's visitor.
In this section we're going to take a brief look at each of the following new
input types:
• color
• date
• datetime-local
• email
• month
• number
• range
• search
• tel
• time
• url
• week
There was also a datetime input type for entering a date and time, but it is now
obsolete.
Let's try out the following example to understand how it basically works:
Example
Try this code »
<form>
<label for="mycolor">Select Color:</label>
<input type="color" value="#00ff00" id="mycolor">
</form>
Note: The color input (i.e. type="color") is supported in all major modern web
browsers such as Firefox, Chrome, Opera, Safari (12.1+), Edge (14+). Not
supported by the Microsoft Internet Explorer and older version of Apple Safari
browsers.
The date value includes the year, month, and day, but not the time.
Example
Try this code »
<form>
<label for="mydate">Select Date:</label>
<input type="date" value="2019-04-15" id="mydate">
</form>
Note: The date input (i.e. type="date") is supported by the Chrome, Firefox,
Opera and Edge browsers. Not supported by the Internet Explorer and Safari
browsers.
Let's try out the following example to understand how it basically works:
Example
Try this code »
<form>
<label for="mydatetime">Choose Date and Time:</label>
<input type="datetime-local" id="mydatetime">
</form>
Warning: The input type="datetime-local" is not supported by Firefox, Safari,
and Internet Explorer browsers. Currently supported by Chrome, Edge, and
Opera browsers.
Let's try out this example by entering any e-mail address to see how it actually
works:
Example
Try this code »
<form>
<label for="myemail">Enter Email Address:</label>
<input type="email" id="myemail" required>
</form>
Tip: You can style the email input field for different validation states, when an
value is entered using the :valid, :invalid or :required pseudo-classes.
Note: The validation for the email input (i.e. type="email") is supported by all
major browsers like Firefox, Chrome, Safari, Opera, Internet Explorer 10 and
above.
The value is a string in the format "YYYY-MM", where YYYY is the four-digit
year and MM is the month number. Let's try out an example to see how this
basically works:
Example
Try this code »
<form>
<label for="mymonth">Select Month:</label>
<input type="month" id="mymonth">
</form>
Warning: The input type="month" is not supported by Firefox, Safari and
Internet Explorer browsers. Currently supported in Chrome, Edge, and Opera
browsers.
Input Type Number
The number input type can be used for entering a numerical value. You can also
restrict the user to enter only acceptable values using the additional
attributes min, max, and step.
The following example will allow you to enter a numeric value between 1 to
10.
Example
Try this code »
<form>
<label for="mynumber">Enter a Number:</label>
<input type="number" min="1" max="10" step="0.5"
id="mynumber">
</form>
Note: The number input (i.e. type="number") is supported by all major web
browsers such as Firefox, Chrome, Safari, Opera, Internet Explorer 10 and
above. Internet Explorer however recognized the number but do not provide
increment and decrement spin buttons.
Let's try out the following example to understand how it basically works:
Example
Try this code »
<form>
<label for="mynumber">Select a Number:</label>
<input type="range" min="1" max="10" step="0.5"
id="mynumber">
</form>
Note: The range input (i.e. type="range") is supported by all major web
browsers such as Firefox, Chrome, Safari, Opera, Internet Explorer 10 and
above.
A search field typically behaves like a regular text field, but in some browsers
like Chrome and Safari as soon as you start typing in the search box a small
cross appears on the right side of the field that lets you quickly clear the
search field. Let's try out an example to see how it works:
Example
Try this code »
<form>
<label for="mysearch">Search Website:</label>
<input type="search" id="mysearch">
</form>
Note: The search input (i.e. type="search") is supported by all major web
browsers such as Firefox, Chrome, Safari, Opera, Internet Explorer 10 and
above.
Browsers don't support tel input validation natively. However, you can use
the placeholder attribute to help users in entering the correct format for a
phone number, or specify a regular expression to validate the user input using
the pattern attribute. Let's check out an example:
Example
Try this code »
<form>
<label for="myphone">Telephone Number:</label>
<input type="tel" id="myphone" placeholder="xx-xxxx-xxxx"
required>
</form>
Note: The validation for tel input (i.e. type="tel") is currently not supported by
any browser because format for phone numbers vary so much across
countries, but it is still useful. Mobile browsers display a numeric keyboard for
tel input field for entering phone numbers.
Browser may use 12- or 24-hour format for inputting times, based on local
system's time setting.
Example
Try this code »
<form>
<label for="mytime">Select Time:</label>
<input type="time" id="mytime">
</form>
Warning: The input type="time" is not supported by Internet Explorer and
Safari browsers. Currently supported by Chrome, Firefox, Edge, and Opera
browsers.
You can use the multiple attribute to enter more than one URL. Also,
if required attribute is specified browser will automatically carry out validation
to ensure that only text that matches the standard format for URLs is entered
into the input box. Let's see how this works:
Example
Try this code »
<form>
<label for="myurl">Enter Website URL:</label>
<input type="url" id="myurl" required>
</form>
Note: The validation for the url input (i.e. type="url") is supported by all major
browsers like Firefox, Chrome, Safari, Opera, Internet Explorer 10 and above.
Let's try out the following example to understand how this works:
Example
Try this code »
<form>
<label for="myweek">Select Week:</label>
<input type="week" id="myweek">
</form>
Warning: The input type="week" is not supported by Firefox, Safari and Internet
Explorer browsers. Currently supported by Chrome, Edge, and Opera browsers.
Actually, there are many type of HTML e.g. HTML 4.01 Strict, HTML 4.01 Transitional,
HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset,
XHTML 1.1 etc.
The <!DOCTYPE> declaration refers Document Type Declaration (DTD) in HTML 4.01;
because HTML 4.01 was based on SGML. But HTML 5 is not SGML based language.
DTD defines the rules for the markup languages so that the browsers recognize the
content correctly.
The doctype declaration differs between HTML versions. The HTML 5 doctype declaration
is given below.
Syntax
<!DOCTYPE html>
Display None
Usage Structural
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>This is the title</title>
5. </head>
6. <body>
7. This is the content of the document.
8. </body>
9. </html>
Note: It is always a good practice to add a declaration to your HTML documents to
enable web browser to recognize that what type of document to expect.
o Tags: An HTML tag surrounds the content and apply meaning to it. It is
written between < and > brackets.
o Attribute: An attribute in HTML provides extra information about the element,
and it is applied within the start tag. An HTML attribute contains two fields:
name & value.
Syntax
1. <tag name attribute_name= " attr_value"> content </ tag name>
o Elements: An HTML element is an individual component of an HTML file. In an
HTML file, everything written within tags are termed as HTML elements.
o <!DOCTYPE html>
o <html>
o <head>
o <title>The basic building blocks of HTML</title>
o </head>
o <body>
o <h2>The building blocks</h2>
o <p>This is a paragraph tag</p>
o <p style="color: red">The style is attribute of paragraph tag</p>
o <span>The element contains tag, attribute and content</span>
o </body>
o </html>
HTML Tags
HTML tags are like keywords which defines that how web browser will format and display
the content. With the help of tags, a web browser can distinguish between an HTML
content and a simple content. 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.
An HTML file must have some essential tags so that web browser can differentiate
between a simple text and HTML text. You can use as many tags you want as per your
code requirement.
o All HTML tags must enclosed within < > these brackets.
o Every tag in HTML perform different tasks.
o If you have used an open tag <tag>, then you must use a close tag </tag>
(except some tags)
Syntax
<tag> content </tag>
<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.
Global Attributes
HTML global attributes are those attributes which are common for all HTML elements.
The global attributes are supported by both standard and non-standard element.
The global attributes can be used with all elements, although it may not have any effect
on some elements.
accesskey character It is used to generate keyboard shortcuts for the current element.
class classname It is used to provide the class name for the current element. It is
mainly used with the stylesheet.
contextmenu menu_id It defines the id for the <menu> element which is used as a
context menu (a menu appear on right click) for an element.
dir rtl It specifies the direction of the content inside the current element.
ltr
auto
dropzone copy It specifies the action is taken on the dragged element when it is
move dropped, ¬¬ such as whether it is copied, moved or linked.
link
lang language_c It specifies the primary language for the content of an element.
ode
spellcheck true It specifies whether the content should be checked for spelling
false errors or not.
title text It is used to provide the title, name, or some extra information
about the element.
In HTML5 there are lots of event attributes available which can be activated using a
programming language such as JavaScript.
Following is a table of event attributes, using these attributes you can perform several
events.
Attribute Description
onoffline Executed the script when the network connection is disconnected, and
browser started working offline.
ononline Executed the script when the browser started working online
onpagehide Executed the script when the current webpage is hidden such as if the user
has moved away from the current webpage.
onpopstate Executed the script when the window's active history is changed.
onunload Executed the script when the current webpage is unloaded, or window is
closed.
The form events can be used with any element, but these are mainly used with HTML
form elements.
Attribute Description
onblur Executed the script when form element loses the focus.
onchange Executed the script when the value of the element is changed.
oninput Executed the script when the user enters input to the element.
oninvalid Executed the script when the element does not satisfy its predefined constraints.
onreset Triggers the event when user reset the form element values.
onsearch Triggers the event when a search field receives some input.
onselect Triggers the event when the user has selected some text.
Attribute Description
onkeydown Triggers the event when the user presses down a key on the keyboard.
onkeypress Trigger the event when the user presses the key which displays some character.
onkeyup Trigger the event when the user releases the currently pressed key.
ondblclick Trigger the event when mouse double-click occurs on the element.
onmousedown Trigger the event when the mouse button is pressed on the element.
onmousemove Trigger the event when the mouse pointer moves over the element.
onmouseout Trigger the event when the mouse moves outside the element.
onmouseover Trigger the event when the mouse moves onto the element.
onwheel Trigger the event when the mouse wheel rolls up or down on the element
oncopy Trigger the event when the user copies the content to the system clipboard.
oncut Trigger the event when the content of an element is cut and copy to the clipboard.
onpaste Trigger the event when the user pastes some content in an element.
oncanplayth Executed the script when the media file is ready to play without buffering or stopping.
rough
ondurationc Executed the script when the media file duration is changed.
hange
onemptied Executed the script if media occurs some fatal error, and the file becomes unavailable.
onended Executed the script when the media file occurs its end point.
onerror Executed the script when some error occurred while fetching the media data.
onplay Executed the script when media file ready to play after being paused.
onprogress Executed the script when the browser is in the process of getting the media data.
onseeked Executed the script when seek operation is ended and seeking attribute is set to false.
onseeking Executed the script when seek operation is active and seeking attribute is set to true.
onstalled Executed the script when browser unexpectedly stopped fetching the data media.
ontimeupda Executed the script when playback position is changed, such as if a user fasts forward the tra
te
onvolumech Executed the script when media volume is changed (muted or unmuted).
ange
onwaiting Executed the script if playback pause to wait for loading more data.
HTML 5 Tags
There is a list of newly included tags in HTML 5. These HTML 5 tags (elements) provide a
better document structure. This list shows all HTML 5 tags in alphabetical order with
description.
<aside> It specifies that article is slightly related to the rest of the whole page.
<audio> It is used to play audio file in HTML.
<bdi> The bdi stands for bi-directional isolation. It isolates a part of text that is forma
from the outside text document.
<menuitem> It defines a command that the user can invoke from a popup menu.
<rp> It defines what to show in browser that don't support ruby annotation.
HTML Anchor
The HTML anchor tag defines a hyperlink that links one page to another page. It can
create hyperlink to other web page as well as files, location, or any URL. The "href"
attribute is the most important attribute of the HTML a tag. and which links to
destination page or URL.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title></title>
5. </head>
6. <body>
7. <p>Click on <a href="https://www.javatpoint.com/" target="_blank"> this-
link </a>to go on home page of JavaTpoint.</p>
8. </body>
9. </html>
Note:
o The target attribute can only use with href attribute in anchor tag.
o If we will not use target attribute then link will open in same page.
HTML Image
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.
1) src
It is a necessary attribute that describes the source or path of the image. It instructs the
browser where to look for the image on the server.
2) alt
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
It is an optional attribute which is used to specify the width to display the image. It is
not recommended now. You should apply CSS in place of width attribute.
4) height
It h3 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.
Example:
1. <img src="animal.jpg" height="180" width="300" alt="animal image">
We can use alt attribute with tag. It will display an alternative text in case if image
cannot be displayed on browser. Following is the example for alt attribute:
1. <img src="animal.png" height="180" width="300" alt="animal image">
Note: If src URL will be incorrect or misspell then it will not display your image on web
page, so try to put correct URL.
Example:
1. <a href="https://www.javatpoint.com/what-is-
robotics"><img src="robot.jpg" height="100" width="100"></a>
HTML Table
HTML table tag is used to display data in tabular form (row * column). There can be
many columns in a row.
We can create a table to display data in tabular form, using <table> element, with the
help of <tr> , <td>, and <th> elements.
In Each table, table row is defined by <tr> tag, table header is defined by <th>, and
table data is defined by <td> tags.
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 .
HTML Table Tags
Tag Description
<col> It is used with <colgroup> element to specify column properties for each
column.
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
HTML Table with Border
There are two ways to specify border for HTML tables.
1. <table border="1">
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. }
5. </style>
You can collapse all the borders in one border by border-collapse property. It will
collapse the border into one.
1. <style>
2. table, th, td {
3. border: 2px solid black;
4. border-collapse: collapse;
5. }
6. </style>
HTML Table with cell padding
You can specify padding for table header and table data by two ways:
The cellpadding attribute of HTML table tag is obselete now. It is recommended to use
CSS. So let's see the code of CSS.
1. <style>
2. table, th, td {
3. border: 1px solid pink;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
We can adjust our table width as per our requirement. Following is the example to
display table with width.
1. table{
2. width: 100%;
3. }
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>table</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. width: 100%;
9. }
10. th,td{
11. border: 2px solid green;
12. padding: 15px;
13. }
14.
15. </style>
16. </head>
17. <body>
18. <table>
19. <tr>
20. <th>1 header</th>
21. <th>1 header</th>
22. <th>1 header</th>
23. </tr>
24. <tr>
25. <td>1data</td>
26. <td>1data</td>
27. <td>1data</td>
28. </tr>
29. <tr>
30. <td>2 data</td>
31. <td>2 data</td>
32. <td>2 data</td>
33. </tr>
34. <tr>
35. <td>3 data</td>
36. <td>3 data</td>
37. <td>3 data</td>
38. </tr>
39. </table>
40. </body>
41. </html>
It will divide one cell/row into multiple columns, and the number of columns depend on
the value of colspan attribute.
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 5px;
8. }
9. </style>
HTML code:
1. <table style="width:100%">
2. <tr>
3. <th>Name</th>
4. <th colspan="2">Mobile No.</th>
5. </tr>
6. <tr>
7. <td>Ajeet Maurya</td>
8. <td>7503520801</td>
9. <td>9555879135</td>
10. </tr>
11. </table>
It will divide a cell into multiple rows. The number of divided rows will depend on
rowspan values.
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
HTML code:
1. <table>
2. <tr><th>Name</th><td>Ajeet Maurya</td></tr>
3. <tr><th rowspan="2">Mobile No.</th><td>7503520801</td></tr>
4. <tr><td>9555879135</td></tr>
5. </table>
1. <table>
2. <caption>Student Records</caption>
3. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
4. <tr><td>Vimal</td><td>Jaiswal</td><td>70</td></tr>
5. <tr><td>Mike</td><td>Warn</td><td>60</td></tr>
6. <tr><td>Shane</td><td>Warn</td><td>42</td></tr>
7. <tr><td>Jai</td><td>Malhotra</td><td>62</td></tr>
8. </table>
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. table#alter tr:nth-child(even) {
10. background-color: #eee;
11. }
12. table#alter tr:nth-child(odd) {
13. background-color: #fff;
14. }
15. table#alter th {
16. color: white;
17. background-color: gray;
18. }
19. </style>
The <tbody> is used along with <thead> and <tfoot> which shows the different part of
the table that are table head, table body, and table footer, however, it does not affect
the layout of the table.
These elements can be used for providing semantic information which can be helpful in
accessibility purpose, or rendering the header at top and footer at the bottom while
printing a large table.
Tips: The <tbody> tag must contain one or more <tr> elements.
Syntax
1. <tbody>............</tbody>
Display Inline
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML tbody tag</title>
5. <style>
6. body{
7. margin-left: 195px;"
8. }
9. </style>
10. </head>
11. <body>
12. <h2>Example of the tbody tag</h2>
13. <table border="1" bgcolor="#98f5ff">
14. <thead>
15. <tr>
16. <th>EmpId</th>
17. <th>Name</th>
18. <th>Email-Id</th>
19. </tr>
20. </thead>
21. <tbody>
22. <tr>
23. <td>121</td>
24. <td>John</td>
25. <td>[email protected]</td>
26. </tr>
27.
28. <tr>
29. <td>122</td>
30. <td>William </td>
31. <td>[email protected]</td>
32. </tr>
33.
34. <tr>
35. <td>123</td>
36. <td>Amit</td>
37. <td>[email protected]</td>
38. </tr>
39. </tbody>
40. </table>
41. </body>
42. </html>
Attribute:
Tag-specific attributes:
Attribute Value Description
align right It determines the alignment of the content inside the <tbody> element
left HTML5)
center
justify
char
char character It specifies the alignment of the <tbody> content to the character.
HTML5)
charoff Number It specifies the number of characters the content will be aligned from the
the char attribute. (Not Supported in HTML5)
valign top It determines the vertical alignment of the content inside the <t
middle Supported in HTML5)
bottom
baseline
Global attribute:
The <tbody> tag supports the Global attributes in HTML.
Event attribute:
The <tbody> tag supports the Event attributes in HTML.
The grouped <td> elements of a <tr> tag renders as a single row in the table. The
content of the <td> elements is regular and left-aligned in the table by default.
Syntax
1. <td>.......</td>
Display Inline
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML td tag</title>
5. <style>
6. th{
7. background-color: #6495ed;
8. }
9. th,td{
10. border: 1px solid black;
11. padding: 10px;
12. }
13. </style>
14. </head>
15. <body>
16. <h2>Example of td Tag</h2>
17. <table style=" border-collapse: collapse; background-color:#dcdcdc;">
18. <tr>
19. <th>Product</th>
20. <th>Quantity</th>
21. <th>Price</th>
22. </tr>
23.
24. <tr>
25. <td>Books</td>
26. <td>5</td>
27. <td>589</td>
28. </tr>
29.
30. <tr>
31. <td>T-shirt</td>
32. <td>5</td>
33. <td>3500</td>
34. </tr>
35.
36. <tr>
37. <td>Jeans</td>
38. <td>2</td>
39. <td>5000</td>
40. </tr>
41. </table>
42. </body>
43. </html>
Attribute:
Tag-specific attributes:
nowrap nowrap If it sets then content inside the cell should not
wrap. (Not Supported in HTML5)
scope col It specifies the cells that the header element relates
colgroup to. (Not Supported in HTML5)
row
rowgroup
Global attribute:
The <td> tag supports the Global attributes in HTML.
Event attribute:
The <td> tag supports the Event attributes in HTML.
The content of the template will not be displayed until it is not activated using
JavaScript. The browser processes the content of the <template> element while loading
the page to ensure that the content is valid, the contents are not rendered, however.
It can also be useful when you want to use same content multiple times in your HTML
document without any change.
The <template> tag can be placed anywhere inside of <head>, <body>, <frameset>,
or <table> elements.
Syntax
1. <template>.........</template>
Display None
Usage Formatting
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML Template tag</title>
5. <style>
6. body{
7. background-color: #e6e6fa;
8. }
9. </style>
10. </head>
11. <body>
12. <h2>Example of template tag</h2>
13. <button onclick="clickMe()">Click Me</button><br>
14.
15. <template id="mytemplate">
16. <img src="bird.jpg" alt="bird's image" height="100" width="100">
17. <script>
18. alert("Thank you for choosing template. Click OK for image.")
19. </script>
20. </template>
21.
22. <script>
23. function clickMe() {
24. var x= document.getElementsByTagName("template")[0];
25. var clon = x.content.cloneNode(true);
26. document.body.appendChild(clon);}
27. </script>
28. </body>
29. </html>
Attribute:
Tag-specific attributes:
The <template> tag does not contain any specific attribute.
Global attribute:
The <template> tag supports the Global attributes in HTML.
HTML Textarea
The HTML <textarea> tag is used to define a multi-line text input control.
It can hold unlimited number of characters and the texts are displayed in a fixed-width
font (usually courier).
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.
autofocus It specifies that a text area should be automatically get focused when
the page is loaded.
wrap It specifies that how the texts in the textarea are wrapped at the time
of the submission of the form.
HTML Textarea form attribute
The form attribute specifies one or more forms the text area belongs to.
The textarea element above is outside the form , but it is still the part of the form.
The <tfoot> tag is used as a child element of HTML table (<table>) along with <thead>
and <tbody> elements, where <thead> defines table header and <tbody> defines the
table body.
Tips: The <thead>, <tbody>, and <tfoot> elements do not affect the table layout, and if
you want to apply the change in table layout then use CSS properties.
Syntax
1. <tfoot>
2. <tr></tr>
3. <tr></tr>
4. lt;/tfoot>
Display None
Start tag/End tag Start and End tag
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML tfoot Tag</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. }
9. thead,tfoot{
10. background-color:#3f87a6;
11. }
12. tbody{
13. background-color:#97ffff;
14. }
15. </style>
16. </head>
17. <body>
18. <h1>Example of tfoot tag</h1>
19. <table border="1" >
20. <thead>
21. <tr>
22. <th>Items</th>
23. <th>Quantity</th>
24. <th>Expenditure</th>
25. </tr>
26. </thead>
27. <tfoot>
28. <tr>
29. <th>Total</th>
30. <th>90</th>
31. <th>4175</th>
32. </tr>
33. </tfoot>
34. <tbody>
35. <tr>
36. <td>Books</td>
37. <td>5</td>
38. <td>1500</td>
39. </tr>
40. <tr>
41. <td>Drawing-Paper</td>
42. <td>50</td>
43. <td>800</td>
44. </tr>
45. <tr>
46. <td>Marker</td>
47. <td>35</td>
48. <td>1875</td>
49. </tr>
50. </tbody>
51. </table>
52. </body>
53. </html>
Attribute:
Tag-specific attributes:
char Character It specifies the alignment of the content inside the <tfoot>
element to the character. (Not Supported in HTML5)
Global attribute:
The <tfoot> tag supports the Global attributes in HTML.
Event attribute:
The <tfoot> tag supports the Event attributes in HTML.
o Header cell - It contains the header information (created using <th> element)
o Data Cells - It contains the main data of the table (created using <td> element).
HTML <th> tag is used to define the header cells of an HTML table. The header cell
renders as bold and centered by default on the browser, but you can change its default
style using CSS properties.
The <th> tag must be used as a child element of the <tr> element within <table>
element. The size of the table is auto-adjustable as per the content size.
Syntax
1. <th>Content....... </th>
Display None
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML th Tag</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. width: 70%;}
9. th,td{
10. background-color: #528b8b;
11. padding: 10px;
12. }
13. </style>
14. </head>
15. <body>
16. <h2>Example of th tag</h2>
17. <table border="1">
18. <tr>
19. <th>Month</th>
20. <th>Date</th>
21. </tr>
22. <tr>
23. <td>January</td>
24. <td>20.01.2018</td>
25. </tr>
26. <tr>
27. <td>February</td>
28. <td>01.02.2018</td>
29. </tr>
30. <tr>
31. <td>March</td>
32. <td>15.03.2018</td>
33. </tr>
34. </table>
35. </body>
36. </html>
Attribute:
Tag-specific attributes:
bgcolor rgb(x,x,x) It sets the background color of the header cell. (Not
#xxxxxx Supported in HTML5)
Color_name
nowrap nowrap If it sets then content inside the header cell should
not wrap. (Not Supported in HTML5)
rowspan number It determines the number of rows a cell should span.
scope col It specifies the cells that the header element relates
colgroup to. (Not Supported in HTML5)
row
rowgroup
Global attribute:
The <th> tag supports the Global attributes in HTML.
Event attribute:
The <th> tag supports the Event attributes in HTML.
The <thead> tag must be child of <table> element, and it must be used before any
<tbody>, <tr>, or <tfoot> elements.
The <thead> tag should contain at least one row <tr> element inside it.
Syntax
1. <thead>
2. <tr>
3. </tr>
4. lt;/thead>
Display Inline
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML thead Tag</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. margin: 15px;}
9. thead{
10. background-color:#005cb9;}
11. tbody{
12. background-color: #d4caca;}
13. th,td{
14. padding: 12px;}
15. </style>
16. </head>
17. <body>
18. <h2>Example of thead tag</h2>
19. <table border="1">
20. <caption>Population of India</caption>
21. <thead>
22. <tr>
23. <th>Year</th>
24. <th>Population</th>
25. </tr>
26. </thead>
27. <tbody>
28. <tr>
29. <td>2015</td>
30. <td>1,309,053,980</td>
31. </tr>
32. <tr>
33. <td>2016</td>
34. <td>1,324,171,354</td>
35. </tr>
36. <tr>
37. <td>2017</td>
38. <td>1,339,180,127</td>
39. </tr>
40. <tr>
41. <td>2018</td>
42. <td>1,354,051,854</td>
43. </tr>
44. </tbody>
45. </table>
46. </body>
47. </html>
Attribute:
Tag-specific attributes:
align right It determines the alignment of the content inside the <thead> element
left HTML5)
center
justify
char
char Character It specifies the alignment of the content inside the <thead> element t
Supported in HTML5)
charoff Number It specifies the number of characters the content that will be aligne
specified by the char attribute. (Not Supported in HTML5)
valign top It determines the vertical alignment of the content inside the <t
middle Supported in HTML5)
bottom
baseline
Global attribute:
The <thead> tag supports the Global attributes in HTML.
Event attribute:
The <thead> tag supports the Event attributes in HTML.
It is used to encode dates and times in a machine-readable way to make easy to mark or
schedule your task.
Attribute
There is only one specific attribute of HTML5 time tag.
Attribute Description
Output:
In this example, First line in the body tag defines basic usage of time tag.
Second line shows how to use the datetime attribute to provide contents in a machine-
readable format.
Third line uses the datetime attribute to provide an even more specific date and time.
The <time> tag also supports global attributes and event attributes in HTML 5.
Example
1. <p>An <abbr title = "Hypertext Markup language">HTML </abbr>language is used t
o create web pages. </p>
2. Marked tag:
The content written between <mark> and </mark> tag will show as yellow mark on
browser. This tag is used to highlight a particular text.
Example
1. <p>This tag will <mark>highlight</mark> the text.</p>
3. Strong text:
This tag is used to display the important text of the content. The text written between
<strong> and </strong> will be displayed as important text.
Example
1. <p>In HTML it is recommended to use <strong>lower-
case</strong>, while writing a code. </p>
4. Emphasized text
This tag is used to emphasize the text, and displayed the text in italic form. The text
written between <em> and </em> tag will italicized the text.
Example
1. <p>HTML is an <em>easy </em>to learn language.</p>
5. Definition tag:
When you use the <dfn> and </dfn> tags, it allow to specify the keyword of the
content. Following is the example to show how to definition element.
Example
1. <p><dfn>HTML </dfn> is a markup language. </p>
6. Quoting text:
The HTML <blockquote> element shows that the enclosed content is quoted from
another source. The Source URL can be given using the cite attribute, and text
representation of source can display using <cite> ..... </cite>element.
Example
1. <blockquote cite="https://www.keepinspiring.me/famous-
quotes/"><p>?The first step toward success is taken when you refuse to be a captive of
the environment in which you first find yourself.?</p></blockquote>
2. <cite>-Mark Caine</cite>
7. Short Quotations:
An HTML <q> ....... </q> element defines a short quotation. If you will put any content
between <q> ....... </q>, then it will enclose the text in double quotes.
Example:
1. <p>Steve Jobs said: <q>If You Are Working On Something That You Really Care About,
You Don?t Have To Be Pushed. The Vision Pulls You.</q>?</p>
8. Code tags
The HTML <code> </code> element is used to display the part of computer code. It will
display the content in monospaced font.
9. Keyboard Tag
In HTML the keyboard tag, <kbd>, indicates that a section of content is a user input
from keyboard.
HTML Responsive
Responsive Web design
Responsive web design is used to make your web page look appropriate, good, and well
placedon all devices (desktop, tablet, smartphone etc.)
Responsive web design uses HTML and CSS to resize, hide, shrink, enlarge, or move the
content. It makes the content look good on any screen.
Responsive Images
Images which can be scaled nicely to fit any browser size are known as responsive
images.
Set the CSS width property to 100% to make the image responsive and scale up and
down.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Responsive Image</h2>
6. <p>When we set the CSS width property to 100%, it makes the image responsive.
7. Resize the browser window to see the effect.</p>
8. <img src="img_girl.jpg" style="width:100%;">( change image)
9. </body>
10. </html>
Note: A problem with the above method (width: 100%) is that the image can be scaled
up to be larger than its original size. So, it is better to use the max-width property
instead.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Responsive Image</h2>
6. <p>"max-
width:100%" makes the image responsive and also ensures that the image
7. doesn't get bigger than its original size.</p>
8. <p>Resize the browser window to see the effect.</p>
9. <img src="img_girl.jpg" style="max-
width:100%;height:auto;"> (Change the image)
10. </body>
11. </html>
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Change Images Depending on Browser Width</h2>
6. <p>Resize the browser width and the image will change at 600px and 1500px.</p>
7. <picture>
8. <source srcset="img_smallflower.jpg" media="(max-width: 600px)">(Change image)
9. <source srcset="img_flowers.jpg" media="(max-width: 1500px)">(Change image)
10. <source srcset="flowers.jpg">
11. <img src="img_flowers.jpg" alt="Flowers" style="width:auto;">
12. </picture>
13. </body>
14. </html>
Responsive Text-size
We can make the text size responsive by using the "uv" unit. It means viewport-width.
By using this, we can make the text size to follow the browser window screen.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h1 style="font-size:10vw;">Here size is 10vw.</h1>
6. <p style="font-size:6vw;">Here size is 6vw.</p>
7. <p style="font-size:4vw;">Here size is 4vw.</p>
8. <p>Resize the browser window to see how the text size changes.</p>
9. </body>
10. </html>
Note: viewport specifies the browser window size. 1vw = 1% of viewport width. Means, if
the viewport is 100cm wide, 1vw is 1.0cm.
Media Query
We can also use media query to make responsive websites.
HTML Classes
Class Attribute in HTML
The HTML class attribute is used to specify a single or multiple class names for an HTML
element. The class name can be used by CSS and JavaScript to do some tasks for HTML
elements. You can use this class in CSS with a specific class, write a period (.) character,
followed by the name of the class for selecting elements.
A class attribute can be defined within <style> tag or in separate file using the (.)
character.
In an HTML document, we can use the same class attribute name with different
elements.
Example:
1. <head>
2. <style>
3. .headings{
4. color: lightgreen;
5. font-family: cursive;
6. background-color: black; }
7. </style>
8. </head>
We have define style for a class name "headings", and we can use this class name with
any of HTML element in which we want to provide such styling. We just need to follow
the following syntax to use it.
Example 1:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. .headings{
6. color: lightgreen;
7. font-family: cursive;
8. background-color: black; }
9. </style>
10. </head>
11. <body>
12. <h1 class="headings">This is first heading</h1>
13. <h2 class="headings">This is Second heading</h2>
14. <h3 class="headings">This is third heading</h3>
15. <h4 class="headings">This is fourth heading</h4>
16. </body>
17. </html>
Actually, there are many type of HTML e.g. HTML 4.01 Strict, HTML 4.01 Transitional,
HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset,
XHTML 1.1 etc.
The <!DOCTYPE> declaration refers Document Type Declaration (DTD) in HTML 4.01;
because HTML 4.01 was based on SGML. But HTML 5 is not SGML based language.
DTD defines the rules for the markup languages so that the browsers recognize the
content correctly.
The doctype declaration differs between HTML versions. The HTML 5 doctype declaration
is given below.
Syntax
<!DOCTYPE html>
Following are some specifications about the HTML <!DOCTYPE>
Display None
Usage Structural
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>This is the title</title>
5. </head>
6. <body>
7. This is the content of the document.
8. </body>
9. </html>
The <track> tag is used to add subtitle, caption, or any other form of text which
displayed when a media file plays.
Syntax
1. <track src=" " kind=" " srclang=" " label=" ">
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML track Tag</title>
5. </head>
6. <body>
7. <h2>Example of track tag</h2>
8. <video controls="controls">
9. <source src="flower.mp4" type="video/mp4">
10. <track src="flower.vtt" kind="subtitles" srclang="en" label="English">
11. Sorry!Your browser does not support the track
12. </video>
13. </body>
14. </html>
kind captions It specifies that which type of text track you want to
chapters add.
descriptions
metadata
subtitles
Global attribute:
The <track> tag supports the Global attributes in HTML.
Event attribute:
The <track> tag supports the Event attributes in HTML.
Note: Do not use HTML <tt> tag, as it is not supported in HTML5, instead of you
can use following tags for better use:
o <code>: To represent the computer programming code
o <pre>: To preserve line break and indentation in plain text.
o <kbd>: To represent keyboard input.
o <var>: To represent variables in an equation
o <samp>: To represent the text as sample output.
Syntax
Following are some specifications about the HTML <tt> tag
Note: Do not use HTML <tt> tag, as it is not supported in HTML5, instead of you can use
use:
Syntax
Display Inline
Usage Formatting
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML tt tag</title>
5. </head>
6. <body>
7. <h2>Example of tt tag</h2>
8. <p>This is paragraph with default font</p>
9. <p><tt>This is teletype paragraph</tt></p>
10. </body>
11. </html>
In HTML5, <u> tag is used to represent the text that is stylistically different with normal
text.
Tips: The use of <u> tag should be ignored as it may generate confusion for a
hyperlinked text.
Syntax
Following are some specifications about the HTML <u> tag
Display Inline
Usage Formatting
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML u tag</title>
5. <style>
6. u{
7. text-decoration: red wavy underline;}
8. </style>
9. </head>
10. <body>
11. <h2>Example of u tag</h2>
12. <p>This tag can be useful to identifying <u>spelling mistakes </u>in an document.</
p>
13. </body>
14. </html>
Attribute:
Tag-specific attributes:
The <u> tag does not contain any specific attribute.
Global attribute:
The <u> tag supports the Global attributes in HTML.
Event attribute:
The <u> tag supports the Event attributes in HTML.
The content within <var> tag renders in italic font in most of the browsers, but it can be
overridden using appropriate CSS.
Following are some related elements of <var> tag, which can also be used for the same
context:
Syntax
1. <var>........</var>
Following are some specifications about the HTML <var> tag
Display Inline
Usage Formatting
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML var tag</title>
5. </head>
6. <body>
7. <h2>Example of var tag</h2>
8. <p>Following is equation for distributive law</p>
9. <p><var>a</var>(<var>b</var>+<var>c</var>)=<var>ab</var>+<var>ac
</var></p>
10. </body>
11. </html>
Attribute:
Tag-specific attributes:
The <var> tag does not contain any specific attribute in HTML.
Global attribute:
The <var> tag supports the Global attributes in HTML.
Event attribute:
The <var> tag supports the Event attributes in HTML.
The contact information written between <address> tags mostly renders in the italic
form on the browser.
Note: To represent a random address use <p> tag instead of <address> tag, as it should
contain the main contact information.
Syntax
1. <address>Contact Author at:<br>
2. <a href="mailto:[email protected]">[email protected]</a></address>
If you want to specify the information of the author for an article, you must place the
<address> tag inside the <article> element.
Display Block
Usage Semantic
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Address Tag</title>
5. </head>
6. <body>
7. <h2>Example of Address tag</h2>
8. <address>The article is written by:<b>Harshita</b> <br>Contact Author at:
Global Attribute:
The <address> tag supports the global attributes.
Event attribute:
The <address> tag supports all Events attributes.
The use of Java applet is also deprecated, and most browsers do not support the use of
plugins.
Note: The <applet> tag is deprecated in HTML4.0 and not supported in HTML5. So you
can use <object> tag or <embed> tag instead of <applet>.
Syntax
1. <applet code="URL" height="200" width="100">.............</applet>
Display Block
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Applet Tag</title>
5. </head>
6. <body>
7. <p>Example of Applet Tag</p>
8. <applet code="Shapes.class" align="right" height="200" width="300">
9. <b>Sorry! you need Java to see this</b>
10. </applet>
11. </body>
12. </html>
Attributes
Specific Attributes
o top
o middle
o bottom
Global Attributes
The <applet> tag supports all Global Attributes in HTML
Event Attributes
The <applet> tag supports all Event Attributes in HTML
Inside an image map different areas can be hyperlinked to various locations using
multiple <area> elements in a single <map> element.
The <area> element is defined with (required) attributes shape and coords. The shape
attribute specifies the shape of the area such as rectangle, circle, square,
and polygon. The coords attribute defines the coordinates of areas inside the image.
What is Image-map
An image-map is defined as a graphical image with active areas so that when user click
on those area, it can link to different destinations. To define an image-map, we
require the following things:
o An HTML <img> element with usemap attribute which defines a valid map name.
o HTML <map> element with name attribute whose value must be same
as usemap
o One or more <area> elements inside a <map> element which create clickable
areas in an image-map.
Syntax
1. <area shape="" coords="" href="">
Display Block
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML Area tag</title>
5. <style>
6. body{
7. margin-left: 250px;}
8. </style>
9. </head>
10. <body>
11. <h2>Example of HTML Area tag</h2>
12. <img src="image1.png" usemap="#web">
13. <map name="web">
14. <area shape="rect" coords="66,117,131,168" href="https://www.google.com">
15. <area shape="rect" coords="199,36,277,85" href="https://www. google.com ">
16. <area shape="rect" coords="330,107,406,159" href="https://www.
google.com">
17. <area shape="rect" coords="199,185,267,236" href="https://www.
google.com">
18. </map>
19. </body>
20. </html>
Attribute:
Tag-specific attributes:
Global attribute:
The <area> tag supports the global attributes in HTML
Event attribute:
The <area> tag supports the event attributes in HTML.
HTML Article Tag
The HTML <article> tag defines an independent self-contained content in a document,
page, application or a site.
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.
Narendra Modi
(Naam to suna hi hoga)
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.
next →← prev
Output:
I don't want to live in Ghaziabad, I wish; I could buy a flat in New Delhi.
New Delhi
HTML aside tag also supports global and event attributes in HTML.
HTML Audio Tag
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.
1. <audio controls>
2. <source src="koyal.mp3" type="audio/mpeg">
3. Your browser does not support the html audio tag.
4. </audio>
Let's see the example to play ogg file using HTML audio tag.
1. <audio controls>
2. <source src="koyal.ogg" type="audio/ogg">
3. Your browser does not support the html audio tag.
4. </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.
ogg audio/ogg
wav audio/wav
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.
Opera no yes
1. <video controls>
2. <source src="movie.mp4" type="video/mp4">
3. Your browser does not support the html video tag.
4. </video>
Let's see the example to play ogg file using HTML video tag.
1. <video controls>
2. <source src="movie.ogg" type="video/ogg">
3. Your browser does not support the html video tag.
4. </video>
Attribute Description
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.
muted It is used to mute the video output.
preload It specifies the author view to upload video file when the page loads.
mp4 video/mp4
ogg video/ogg
webM video/webM
A <menu> element can contain one or more <li> or <menuitem> elements within it.
Note: The <menu> tag was deprecated in HTML 4.01 and again included in HTML 5.1
specification. But it will better to ignore it as it is experimental and not supported by
many browsers.
Syntax
1. <menu>........<menu>
Display Inline
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Menu Tag</title>
5. </head>
6. <body>
7. <h2>Example of Menu Tag</h2>
8. <menu>
9. <li>Home</li>
10. <li>Registration</li>
11. <li>Contact-us</li>
12. <li>About-us</li>
13. </menu>
14. </body>
15. </html>
Attribute:
Tag-specific attributes:
o popup
o toolbar
o context
Attribute Value Description
Global attribute:
The <menu> tag supports the global attributes in HTML
Event attribute:
The <menu> tag supports the event attributes in HTML.
The <picture> tag contains one or more <source> elements and one <img> elements.
According to the viewport, the matching image will be loaded from different <source>
tag, and if no source contains the matching image, then the default image present in
<img> tag will be displayed on the browser.
Syntax
1. <picture>
2. <source srcset="" media="">
3. <img src="">
4. </picture>
Usage Image
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Picture Tag</title>
5. <style>
6. body{
7. text-align: center;
8. }
9. p{
10. font-size: bold;
11. font-size: 20px;
12. color: green;
13. }
14. </style>
15. </head>
16. <body>
17. <h2>Example of picture tag</h2>
18. <p>Resize the page to see the different versions of the images at different viewports, a
nd as per viewport image will be automatically changed.</p>
19. <picture>
20. <source srcset="download1.jpg" media="(min-width: 750px)">
21. <source srcset="pic2.jpg" media="(min-width: 450px)">
22. <img srcset="rose.jpg" alt="default image" style="width: auto;">
23. </picture>
24. </body>
25. </html>
Attribute:
Tag-specific attributes:
Attribute Value Description
media media_query It defines and accept any media query which can be
defined in CSS.
srcset URL It defines the URL of the image which can be used for
different situations. (Required)
Global attribute:
HTML <picture> tag supports the global attributes in HTML.
The HTML progress tag is new in HTML5 so you must use new browsers.
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.
1. <progress></progress>
Let's see the progress example with value and max attributes.
1. Downloading progress:
2. <progress value="43" max="100"></progress>
1. progress{
2. width: 300px;
3. height: 30px;
4. }
1. <script>
2. var gvalue=1;
3. function abc(){
4. var progressExample = document.getElementById ('progress-javascript-example');
5. setInterval (function ()
6. {
7. if(gvalue<100){
8. gvalue++;
9. progressExample.value =gvalue;
10. }
11. abc();
12. }, 1000);
13. }
14. </script>
15. <progress id="progress-javascript-example" min="1" max="100"></progress>
16. <br/><br/>
17. <button onclick="abc()">click me</button>
HTML Form
An HTML form is a section of a document which contains controls such as text fields,
password fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for
processing such as name, email address, password, phone number, etc. .
For example: If a user want to purchase some items on internet, he/she must fill the
form such as shipping address and credit/debit card details so that item can be sent to
the given address.
Tag Description
Tag Description
Note: The <form> element does not itself create a form but it is container to contain all
required form elements, such as <input>, <label>, etc.
Syntax:
1. <form>
2. //Form elements
3. </form>
Example:
1. <body>
2. <form>
3. Enter your name <br>
4. <input type="text" name="username">
5. </form>
6. </body>
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
Note: If you will omit 'name' attribute then the text filed input will not be submitted to
server.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
6. <body>
7. <form>
8. Enter your address:<br>
9. <textarea rows="2" cols="20"></textarea>
10. </form>
11. </body>
12. </html>
If you click on the label tag, it will focus on the text control. To do so, you need to have
for attribute in label tag that must be same as id attribute of input tag.
NOTE: It is good to use <label> tag with form, although it is optional but if you will use it,
then it will provide a focus when you tap or click on label tag. It is more worthy with
touchscreens.
1. <form>
2. <label for="firstname">First Name: </label> <br/>
3. <input type="text" id="firstname" name="firstname"/> <br/>
4. <label for="lastname">Last Name: </label>
5. <input type="text" id="lastname" name="lastname"/> <br/>
6. </form>
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password"/> <br/>
4. </form>
HTML 5 Email Field Control
The email field in new in HTML 5. It validates the text for correct email address. You
must use @ and . in this field.
1. <form>
2. <label for="email">Email: </label>
3. <input type="email" id="email" name="email"/> <br/>
4. </form>
Note: If we will not enter the correct email, it will display error like:
If you use one name for all the radio buttons, only one radio button can be selected at a
time.
Using radio buttons for multiple options, you can only choose a single option at a time.
1. <form>
2. <label for="gender">Gender: </label>
3. <input type="radio" id="gender" name="gender" value="male"/>Male
4. <input type="radio" id="gender" name="gender" value="female"/>Female
<br/>
5. </form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
1. <form>
2. Hobby:<br>
3. <input type="checkbox" id="cricket" name="cricket" value="cricket"/>
4. <label for="cricket">Cricket</label> <br>
5. <input type="checkbox" id="football" name="football" value="football"/>
6. <label for="football">Football</label> <br>
7. <input type="checkbox" id="hockey" name="hockey" value="hockey"/>
8. <label for="hockey">Hockey</label>
9. </form>
Note: These are similar to radio button except it can choose multiple options at a time
and radio button can select one button at a time, and its display.
Syntax:
The value attribute can be anything which we write on button on web page.
Example:
1. <form>
2. <label for="name">Enter name</label><br>
3. <input type="text" id="name" name="name"><br>
4. <label for="pass">Enter Password</label><br>
5. <input type="Password" id="pass" name="pass"><br>
6. <input type="submit" value="submit">
7. </form>
Example:
1. <form>
2. <fieldset>
3. <legend>User Information:</legend>
4. <label for="name">Enter name</label><br>
5. <input type="text" id="name" name="name"><br>
6. <label for="pass">Enter Password</label><br>
7. <input type="Password" id="pass" name="pass"><br>
8. <input type="submit" value="submit">
9. </fieldset>
10. lt;/form>
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Form in HTML</title>
5. </head>
6. <body>
7. <h2>Registration form</h2>
8. <form>
9. <fieldset>
10. <legend>User personal information</legend>
11. <label>Enter your full name</label><br>
12. <input type="text" name="name"><br>
13. <label>Enter your email</label><br>
14. <input type="email" name="email"><br>
15. <label>Enter your password</label><br>
16. <input type="password" name="pass"><br>
17. <label>confirm your password</label><br>
18. <input type="password" name="pass"><br>
19. <br><label>Enter your gender</label><br>
20. <input type="radio" id="gender" name="gender" value="male"/>Male <br>
21. <input type="radio" id="gender" name="gender" value="female"/>Female <b
r/>
22. <input type="radio" id="gender" name="gender" value="others"/>others <br
/>
23. <br>Enter your Address:<br>
24. <textarea></textarea><br>
25. <input type="submit" value="sign-up">
26. </fieldset>
27. </form>
28. </body>
29. </html>
HTML Form Example
Let's see a simple example of creating HTML form.
1. <form action="#">
2. <table>
3. <tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter name:</lab
el></td>
5. <td><input type="text" name="name" value="" id="register_name" style="width
:160px"/></td>
6. </tr>
7. <tr>
8. <td class="tdLabel"><label for="register_password" class="label">Enter password
:</label></td>
9. <td><input type="password" name="password" id="register_password" style="wi
dth:160px"/></td>
10. </tr>
11. <tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter Email:</lab
el></td>
13. <td
14. ><input type="email" name="email" value="" id="register_email" style="width:160p
x"/></td>
15. </tr>
16. <tr>
17. <td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</l
abel></td>
18. <td>
19. <input type="radio" name="gender" id="register_gendermale" value="male"/>
20. <label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfemale" value="female"/>
22. <label for="register_genderfemale">female</label>
23. </td>
24. </tr>
25. <tr>
26. <td class="tdLabel"><label for="register_country" class="label">Select Country:<
/label></td>
27. <td><select name="country" id="register_country" style="width:160px">
28. <option value="india">india</option>
29. <option value="pakistan">pakistan</option>
30. <option value="africa">africa</option>
31. <option value="china">china</option>
32. <option value="other">other</option>
33. </select>
34. </td>
35. </tr>
36. <tr>
37. <td colspan="2"><div align="right"><input type="submit" id="register_0" value
="register"/>
38. </div></td>
39. </tr>
40. </table>
41. </form>
HTML5 Semantics
In any language, it is essential to understand the meaning of words during
communication. And if this is a computer communication then it becomes more critical.
So HTML5 provides more semantic elements which make easy understanding of the
code.
Semantic elements= elements with a meaning. Semantic elements have a simple and
clear meaning for both, the browser and the developer.
For example:
In HTML4 we have seen <div>, <span> etc. are which are non-semantic elements. They
don't tell anything about its content.
On the other hand, <form>, <table>, and <article> etc. are semantic elements because
they clearly define their content.
This is so difficult for search engines to identify the correct web page content. Now in
HTML5 elements (<header> <footer> <nav> <section> <article>), this will become
easier. It now allows data to be shared and reused across applications, enterprises, and
communities."
Semantic elements can increase the accessibility of your website, and also helps to
create a better website structure.
3. <details> Defines additional details that the user can view or hide
Example:
1. <article>
2. <h2>Today's highlights</h2>
3. <p>First story</p>
4. <p>Second story</p>
5. <p>Third story</p>
6. </article>
Example:
1. <body>
2. <h2>My last year memories</h2>
3. <p>I have visited Paris with my friends last month. This was the memorable journey an
d i wish to go there again.</p>
4. <aside>
5. <h4>Paris</h4>
6. <p>Paris, France's capital, is a major European city and a global center for art, fashio
n, gastronomy and culture</p>
7. </aside>
8. </body>
Example:
In HTML, we can use <section> elements within <article> elements, and <article>
elements within <section> elements.
We can also use <section> elements within <section> elements, and <article> elements
within <article> elements.
For example:
In a newspaper, the sport <article> in the sport section, may have a technical section in
each <article>.
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <nav>
5. <a href="https://www.javatpoint.com/html-tutorial">HTML</a> |
6. <a href="https://www.javatpoint.com/java-tutorial">Java</a> |
7. <a href="https://www.javatpoint.com/php-tutorial">PHP</a> |
8. <a href="https://www.javatpoint.com/css-tutorial">CSS</a>
9. </nav>
10. </body>
11. </html>
Nesting <article> tag in <section> tag or Vice Versa?
We know that the<article> element specifies independent, self-contained content and
the <section> element defines section in a document.
In HTML, we can use <section> elements within <article> elements, and <article>
elements within <section> elements.
We can also use <section> elements within <section> elements, and <article> elements
within <article> elements.
For example:
In a newspaper, the sport <article> in the sport section, may have a technical section in
each <article>.
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <nav>
5. <a href="https://www.javatpoint.com/html-tutorial">HTML</a> |
6. <a href="https://www.javatpoint.com/java-tutorial">Java</a> |
7. <a href="https://www.javatpoint.com/php-tutorial">PHP</a> |
8. <a href="https://www.javatpoint.com/css-tutorial">CSS</a>
9. </nav>
10. </body>
11. </html>
Example:
1. <header>
2. <h1>Welcome to Web123.com</h1>
3. <nav>
4. <ul>
5. <li>Home |</li>
6. <li>About us |</li>
7. <li>Contact us</li>
8. </ul>
9. </nav>
10. </header>
Example:
1. <footer>
2. <p>© Copyright 2019. All rights reserved. </p>
3. </footer>
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.
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 draw a line which starting point is (0,0) and the end point is (200,100), use the
stroke method to draw the line.
To sketch circle on HTML canvas, use one of the ink() methods, like stroke() or fill().
font property: It is used to define the font property for the text.
fillText(text,x,y) method: It is used to draw filled text on the canvas. It looks like bold
font.
strokeText(text,x,y) method: It is also used to draw text on the canvas, but the text
is unfilled.
HTML5 Migration
HTML5 migration specifies that how to migrate from HTML4 to HTML5. Let?s see how to
convert HTML4 page into HTML5 page without any problem in content or structure.
Table:
In HTML4 In HTML5
1. <!DOCTYPE html>
Example:
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5. <title>HTML5</title>
6. <style>
7. body {
8. font-family: Verdana,sans-serif;
9. font-size: 0.9em;
10. }
11. div#header, div#footer {
12. padding: 10px;
13. color: white;
14. background-color: black;
15. }
16.
17. div#content {
18. margin: 5px;
19. padding: 10px;
20. background-color: lightgrey;
21. }
22. div.article {
23. margin: 5px;
24. padding: 10px;
25. background-color: white;
26. }
27. div#menu ul {
28. padding: 0;
29. }
30. div#menu ul li {
31. display: inline;
32. margin: 5px;
33. }
34. </style>
35. </head>
36. <body>
37. <div id="header">
38. <h1>JavaTpoint Times</h1>
39. </div>
40.
41. <div id="menu">
42. <ul>
43. <li>Tutorials</li>
44. <li>Technology</li>
45. <li>Blog</li>
46. </ul>
47. </div>
48. <div id="content">
49. <h2>Tutorials Section</h2>
50. <div class="article">
51. <h2>Tutorial1</h2>
52. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.