Académique Documents
Professionnel Documents
Culture Documents
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.
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
1
<fieldset> It groups the related element in a form.
Tag Description
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
2
Label Tag in Form
It is considered better to have label in form. As it makes the code parser/browser/user
friendly.
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.
1. <form>
2. <label for="firstname">First Name: </label>
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>
1. <form>
2. <label for="email">Email: </label>
3. <input type="email" id="email" name="email"/> <br/>
4. </form>
3
Radio Button Control
The radio button is used to select one from multiple options. It is used in gender, quiz
questions etc.
If you use one name for all the radio buttons, only one radio button can be selected 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.
<form>
Hobby:<br>
<input type="checkbox" id="cricket" name="cricket" value="cricket"/>
<label for="cricket">Cricket</label>
<input type="checkbox" id="football" name="football" value="football"/>
<label for="football">Football</label>
<input type="checkbox" id="hockey" name="hockey" value="hockey"/>
<label for="hockey">Hockey</label>
</form>
<form action="#">
<table>
<tr>
4
<td class="tdLabel"><label for="register_name" class="label">Enter name:</label></t
d>
<td><input type="text" name="name" value="" id="register_name" style="width:160px"/
></td>
</tr>
<tr>
<td class="tdLabel"><label for="register_password" class="label">Enter password:</lab
el></td>
<td><input type="password" name="password" id="register_password" style="width:160
px"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="register_email" class="label">Enter Email:</label></t
d>
<td
><input type="email" name="email" value="" id="register_email" style="width:160px"/></
td>
</tr>
<tr>
<td class="tdLabel"><label for="register_gender" class="label">Enter Gender:</label><
/td>
<td>
<input type="radio" name="gender" id="register_gendermale" value="male"/>
<label for="register_gendermale">male</label>
<input type="radio" name="gender" id="register_genderfemale" value="female"/>
<label for="register_genderfemale">female</label>
</td>
</tr>
<tr>
<td class="tdLabel"><label for="register_country" class="label">Select Country:</label>
</td>
<td><select name="country" id="register_country" style="width:160px">
<option value="india">india</option>
<option value="pakistan">pakistan</option>
<option value="africa">africa</option>
<option value="china">china</option>
<option value="other">other</option>
5
</select>
</td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" id="register_0" value="registe
r"/>
</div></td>
</tr>
</table>
</form>
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.
Example:
Let's use a class name "Fruit" with CSS to style all elements.
<style>
.fruit {
background-color: orange;
color: white;
padding: 10px;
}
</style>
<h2 class="fruit">Mango</h2>
<p>Mango is king of all fruits.</p>
<h2 class="fruit">Orange</h2>
<p>Oranges are full of Vitamin C.</p>
<h2 class="fruit">Apple</h2>
6
<p>An apple a day, keeps the Doctor away.</p>
Test it Now
Here you can see that we have used the class name "fruit" with (.) to use all its elements.
Note: You can use class attribute on any HTML element. The class name is case-sensitive.
Example:
Let's hide all the elements with class name "fruit" when the use click on the button.
<!DOCTYPE html>
<html>
<body>
<h2 class="fruit">Mango</h2>
<p>Mango is king of all fruits.</p>
<h2 class="fruit">Orange</h2>
<p>Oranges are full of Vitamin C.</p>
<h2 class="fruit">Apple</h2>
<p>An apple a day, keeps the Doctor away.</p>
<script>
function myFunction() {
var x = document.getElementsByClassName("fruit");
7
for (var i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
}
</script>
</body>
</html>
Multiple Classes
You can use multiple class names (more than one) with HTML elements. These class names
must be separated by a space.
Example:
Let's style elements with class name "fruit" and also with a class name "center".
<!DOCTYPE html>
<html>
<style>
.fruit {
background-color: orange;
color: white;
padding: 10px;
}
.center {
text-align: center;
}
</style>
<body>
<h2>Multiple Classes</h2>
<p>All three elements have the class name "fruit". In addition, Mango also have the class na
me "center", which center-aligns the text.</p>
8
<h2 class="fruit">Apple</h2>
</body>
</html>
You can see that the first element <h2> belongs to both the "fruit" class and the "center"
class.
Example:
<!DOCTYPE html>
<html>
<style>
.fruit {
background-color: orange;
color: white;
padding: 10px;
}
</style>
<body>
<h2>Same Class with Different Tag</h2>
<h2 class="fruit">Mango</h2>
<p class="fruit">Mango is the king of all fruits.</p>
</body>
</html>
HTML Id Attribute
The id attribute refers to a unique value for an HTML element. This HTML id value can be
used with CSS and JavaScript to perform certain task.
9
Example:
Use the HTML id "myid" with CSS:
<style>
#myid {
background-color: lightpink;
color: black;
padding: 40px;
text-align: center;
}
</style>
<h1 id="myid">Example of HTML id</h1>
Note: Here the id attribute is "myid" which can be used on any HTML element. The HTML id
value is case-sensitive and it must contain at least one character, and must not contain
whitespace (spaces, tabs, etc.).
Example:
<!DOCTYPE html>
<html>
<head>
<style>
/* Style the element with the id "myid" */
#myid {
background-color: pink;
color: black;
padding: 40px;
text-align: center;
}
10
background-color: orange;
color: white;
padding: 10px;
}
</style>
</head>
<body>
<h2 class="fruit">Mango</h2>
<p>The Kinkg of all fruits.</p>
<h2 class="fruit">Orange</h2>
<p>Full of Vitamin C</p>
<h2 class="fruit">Apple</h2>
<p>An apple a day, keeps the doctor away.</p>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML id with JavaScript</h2>
<h1 id="myid">Hello JavaTpoint!</h1>
<button onclick="displayResult()">Change text</button>
<script>
11
function displayResult() {
document.getElementById("myid").innerHTML = "All the best for future!";
}
</script>
</body>
</html>
HTML iframes
HTML Iframe is used to display a nested webpage (a webpage within a webpage). The HTML
<iframe> tag defines an inline frame.
Iframe Syntax
1. <iframe src="URL"></iframe>
Here, "src" attribute specifies the web address (URL) of the inline frame page.
Example: (Pixels)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes example</h2>
<p>Use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="300" width="400"></iframe>
</body>
</html>
Example: (Percentage)
<!DOCTYPE html>
<html>
<body>
12
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="50%" width="70%"></iframe>
</body>
</html>
You can also use CSS to set the height and width of the iframe.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>Use the CSS height and width properties to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" style="height:300px;width:400px"></iframe>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Remove the Iframe Border</h2>
<p>This iframe example doesn't have any border</p>
<iframe src="https://www.javatpoint.com/" style="border:none;"></iframe>
</body>
</html>
Test it Now
You can also change the size, color, style of the iframe's border.
13
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Custom Iframe Border</h2>
<iframe src="https://www.javatpoint.com/" style="border:2px solid tomato;"></iframe>
</body>
</html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Iframe - Target for a Link</h2>
5. <iframe height="300px" width="100%" src="https://www.javatpoint.com/" name="iframe_
a"></iframe>
6. <p><a href="https://www.hindi100.com" target="iframe_a">Hindi100.com</a></p>
7. </body>
8. </html>
HTML JavaScript
JavaScript is used with HTML to make web pages more attractive, dynamic and interactive.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Date and Time example</h1>
<button type="button"
14
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
Test it Now
It is mainly used to manipulate images, form validation and change content dynamically.
JavaScript uses document.getElementById() method to select an HTML element.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Use JavaScript to Change Text</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaTpoint";
</script>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<p>JavaScript can change the content of an HTML element:</p>
<button type="button" onclick="myFunction()">Click Me!</button>
15
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaTpoint!";
}
</script>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo">JavaScript can change the style of an HTML element.</p>
<script>
function myFunction() {
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "brown";
document.getElementById("demo").style.backgroundColor = "lightgreen";
}
</script>
<button type="button" onclick="myFunction()">Click Me!</button>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<script>
function light(sw) {
16
var pic;
if (sw == 0) {
pic = "pic_lightoff.png"
} else {
pic = "pic_lighton.png"
}
document.getElementById('myImage').src = pic;
}
</script>
<img id="myImage" src="pic_lightoff.png" width="100" height="180">
<p>
<button type="button" onclick="light(1)">Light On</button>
<button type="button" onclick="light(0)">Light Off</button>
</p>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
<noscript>This text is not visible in the browser.</noscript>
</body>
</html>
1. Web pages
2. Images
3. Style sheets
4. JavaScript
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Full URL File Path</h2>
5. <img src="https://www.javatpoint.com/images/nature-
1.jpg" alt="image" style="width:300px">
6. </body>
7. </html>
Test it Now
18
Relative File Paths
The relative file path specifies to a file which is related to the current page.
Example:
Let's take an example to see how the file path points to a file in the images folder located at
the root of the current web.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="/images/nature-2.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
Test it Now
Example:
This is how a file path points to a file in the images folder located in the current folder.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="images/nature-3.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
Test it Now
Example:
When the images folder located in the folder one level above the current folder.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="../images/nature4.jpg" alt="Mountain" style="width:300px">
19
6. </body>
7. </html>
HTML Head
The HTML <head> element is used as a container for metadata (data about data). It is used
between <html> tag and <body> tag.
HTML metadata is not displayed. It only specifies data about the HTML document.
Metadata defines the document title, character set, styles, links, scripts, and other meta
information.
Example:
<!DOCTYPE html>
<html>
<head>
<title>This Page Title</title>
</head>
<body>
<p>The body's content is displayed in the browser window.</p>
<p>The content of the title element is displayed in the browser tab, in favorites and in search e
ngine results.</p>
</body>
</html>
Test it Now
20
HTML <style> Element
The HTML <style> element is used to style the HTML page.
Example:
<!DOCTYPE html>
<html>
<head>
<title>This is Page Title</title>
<style>
body {background-color: pink;}
h1 {color: red;}
p {color: blue;}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<head>
<title>This is a Page Title</title>
<link rel="stylesheet" href="external.css">
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
21
</html>
Test it Now
external.css
<style>
body {
background-color: lightblue;
}
</style>
Metadata is mainly used by browsers, search engines, and other web services to rank your
webpage better.
1. <meta charset="UTF-8">
Example:
<!DOCTYPE html>
22
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML,CSS,XML,JavaScript">
<meta name="author" content="Akon">
</head>
<body>
<p>All the meta information are set.</p>
</body>
</html>
Test it Now
Viewport is the user's visible area of a webpage. It changes from device to device and
appears smaller on mobile phones than computer screens.
Here, the <meta> viewport element specifies how to control the page's dimensions and
scaling.
The width=device-width is used to set the width of the page to follow the screen-width of
the device (which will vary depending on the device).
The initial-scale=1.0 is used to set the initial zoom level when the page is first loaded by
the browser.
<!DOCTYPE html>
<html>
<body>
<p><b>To understand this example, you should open this page on a phone or a tablet.</b><
/p>
23
<img src="image.jpg" alt="image" width="460" height="345">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tinci
dunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel
eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu
feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent lupta
tum
zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazi
m placerat
facer possim assum.
</p>
</body>
</html>
Test it Now
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
img {
max-width: 100%;
height: auto;
}
</style>
</head>
<body>
<p><b>To understand this example, you should open this page on a phone or a tablet.</b><
/p>
24
<img src="image.jpg" alt="image" width="460" height="345">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tinci
dunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci
tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel
eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu
feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent lupta
tum
zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazi
m placerat
facer possim assum.
</p>
</body>
</html>
Test it Now
Note: To see the difference clearly, open this page on smartphone or tablet.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<base href="https://www.javatpoint.com/image/" target="_blank">
</head>
25
<body>
<img src="html5.gif">
<p>We have specified a base URL, the browser will look for the image "html5.gif"
at "https://www.w3schools.com/images/html5.gif"</p>
<p><a href=" https://www.javatpoint.com">W3Schools</a></p>
<p>The link above will open in a new window becausebase target is set to "_blank".</p>
</body>
</html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <title>Page Title</title>
3. <h1>This is a heading</h1>
4. <p>This is a paragraph.</p>
Test it Now
Note: It is not recommended to omit the <html> and <body> tags. Omitting these tags can
crash DOM or XML software and produce errors in older browsers (IE9).
HTML Layouts
HTML layout specifies a way in which the webpageis arranged.
Following are different HTML5 elements which are used to define the different parts of a
webpage.
26
o <nav>: It is used to define a container for navigation links
o <aside>: It is used to define content aside from the content (like a sidebar)
o HTML tables
o CSS framework
o CSS flexbox
HTML Tables
HTML tables are not recommended for your page layout. The <table> element is
designed to display tabular data. It is not good for a layout. It will complicate your code
and make it very difficult to redesign your website after sometimes.
CSS Frameworks
CSS provides many frameworks like W3.CSS, Bootstrap etc. to create your layout fast.
CSS Float
You can create an entire web layout using CSS float property.
Advantage: It is very easy to learn and use. You just learn how the float and clear
properties work.
Disadvantage: Floating elements are tied to the document flow, which may harm the
flexibility.
27
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div.container {
6. width: 100%;
7. border: 1px solid gray;
8. }
9.
10. header, footer {
11. padding: 1em;
12. color: white;
13. background-color: #000080;
14. clear: left;
15. text-align: center;
16. }
17.
18. nav {
19. float: left;
20. max-width: 160px;
21. margin: 0;
22. padding: 1em;
23. }
24.
25. nav ul {
26. list-style-type: none;
27. padding: 0;
28. }
29.
30. nav ul a {
31. text-decoration: none;
32. }
33.
34. article {
35. margin-left: 170px;
28
36. border-left: 1px solid gray;
37. padding: 1em;
38. overflow: hidden;
39. }
40. </style>
41. </head>
42. <body>
43.
44. <div class="container">
45.
46. <header>
47. <h1>Tutorials Gallery</h1>
48. </header>
49.
50. <nav>
51. <ul>
52. <li><a href="#">HTML</a></li>
53. <li><a href="#">CSS</a></li>
54. <li><a href="#">JavaScript</a></li>
55. </ul>
56. </nav>
57. <article>
58. <h1>HTML</h1>
59. <p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html. Our
HTML tutorial is
60. developed for beginners and professionals.</p>
61. <p>TML is an acronym which stands for Hyper Text Markup Language. Let's see what is
Hyper Text and what is Markup Language?</p>
62. </article>
63. <footer>Copyright © javatpoint.com</footer>
64. </div>
65. </body>
66. </html>
Test it Now
CSS Flexbox
29
Flexbox is a new layout mode in CSS3.
Advantage: It ensures that the page layout must accommodate different screen sizes
and different display devices.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
text-align: center;
}
.flex-container > * {
padding: 15px;
-webkit-flex: 1 100%;
flex: 1 100%;
}
.article {
text-align: left;
}
.nav ul {
list-style-type: none;
30
padding: 0;
}
.nav ul a {
text-decoration: none;
}
<div class="flex-container">
<header>
<h1>City Gallery</h1>
</header>
<nav class="nav">
<ul>
<li><a href="#">HTML</a></li>
<li><a href="#">CSS</a></li>
<li><a href="#">JavaScript</a></li>
</ul>
</nav>
<article class="article">
<h1>HTML</h1>
<p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html. Our HT
ML tutorial is
developed for beginners and professionals.</p>
<p>TML is an acronym which stands for Hyper Text Markup Language. Let's see what is Hyp
er Text and what is Markup Language?</p>
<p><strong>Resize this page to see what happens!</strong></p>
</article>
31
<footer>Copyright © javatpoint.com</footer>
</div>
</body>
</html>
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
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<h2>Responsive Image</h2>
<p>When we set the CSS width property to 100%, it makes the image responsive.
32
Resize the browser window to see the effect.</p>
<img src="img_girl.jpg" style="width:100%;">( change image)
</body>
</html>
Test it Now
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
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<h2>Responsive Image</h2>
<p>"max-width:100%" makes the image responsive and also ensures that the image
doesn't get bigger than its original size.</p>
<p>Resize the browser window to see the effect.</p>
<img src="img_girl.jpg" style="max-width:100%;height:auto;"> (Change the image)
</body>
</html>
Test it Now
Example
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
33
<body>
<h2>Change Images Depending on Browser Width</h2>
<p>Resize the browser width and the image will change at 600px and 1500px.</p>
<picture>
<source srcset="img_smallflower.jpg" media="(max-width: 600px)">(Change image)
<source srcset="img_flowers.jpg" media="(max-width: 1500px)">(Change image)
<source srcset="flowers.jpg">
<img src="img_flowers.jpg" alt="Flowers" style="width:auto;">
</picture>
</body>
</html>
Test it Now
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 browserwindow screen.
Example
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>
<h1 style="font-size:10vw;">Here size is 10vw.</h1>
<p style="font-size:6vw;">Here size is 6vw.</p>
<p style="font-size:4vw;">Here size is 4vw.</p>
<p>Resize the browser window to see how the text size changes.</p>
</body>
</html>
Test it Now
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. Read the details of media query
from here: Media Query
34
CSS Media Queries
o It uses the @media rule to include a block of CSS properties only if a certain
condition is true.
35
grid integer no It is true for a grid-based device.
Tablet: 768px
Netbook: 1024px
Desktop: 1600px
This example specifies that if you resize your window less than 500px, the background color
will be changed.
36
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
background-color:yellow;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
37
<style>
*{
box-sizing: border-box;
}
.row:after {
content: "";
clear: both;
display: block;
}
[class*="col-"] {
float: left;
padding: 15px;
}
html {
font-family: "Lucida Sans", sans-serif;
}
.header {
background-color: purple;
color: pink;
padding: 15px;
}
.menu ul {
list-style-type: none;
margin: 0;
padding: 0;
}
.menu li {
padding: 8px;
margin-bottom: 7px;
background-color :green;
color: #ffffff;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.menu li:hover {
background-color: #0099cc;
}
.aside {
38
background-color: green;
padding: 15px;
color: #ffffff;
text-align: center;
font-size: 14px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}
.footer {
background-color: #0099cc;
color: #ffffff;
text-align: center;
font-size: 12px;
padding: 15px;
}
/* For mobile phones: */
[class*="col-"] {
width: 100%;
}
@media only screen and (min-width: 600px) {
/* For tablets: */
.col-m-1 {width: 8.33%;}
.col-m-2 {width: 16.66%;}
.col-m-3 {width: 25%;}
.col-m-4 {width: 33.33%;}
.col-m-5 {width: 41.66%;}
.col-m-6 {width: 50%;}
.col-m-7 {width: 58.33%;}
.col-m-8 {width: 66.66%;}
.col-m-9 {width: 75%;}
.col-m-10 {width: 83.33%;}
.col-m-11 {width: 91.66%;}
.col-m-12 {width: 100%;}
}
@media only screen and (min-width: 768px) {
/* For desktop: */
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
39
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
}
</style>
</head>
<body>
<div class="header">
<h1>JavaTpoint</h1>
</div>
<div class="row">
<div class="col-3 col-m-3 menu">
<ul>
<li>C/C++</li>
<li>Java</li>
<li>SQL</li>
<li>Android</li>
<li>HTML</li>
<li>CSS</li>
<li>Cloud Computing</li>
<li>PHP</li>
<li>JSON</li>
<li>JQuery</li>
<li>MongoDB</li>
<li>Oracle</li>
</ul>
</div>
40
<div class="col-6 col-m-9">
<h1>About JavaTpoint</h1>
<p>JavaTpoint is written and developed that students may learn computer science related tech
nologies easily.</p>
</div>
</div>
<div class="footer">
<p>Resize the browser window to see how the content respond to the resizing.</p>
</div>
</body>
</html>
HTML Computercode
41
HTML uses different tags for user inputs, codes, programs etc. Following is a list of some
tags which are used in HTML for this task.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Computer Code</h2>
<p>This is a programming code:</p>
<code>
x = 5;<br>
y = 6;<br>
z = x + y;
</code>
</body>
</html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The kbd Element</h2>
5. <kbd>This is how content written within kbd element looks like.</kbd></p>
6. </body>
7. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The samp Element</h2>
5. <samp>This is how the content within samp element looks like. </samp>
6. </body>
7. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The var Element</h2>
5. <p>This is a famous formula: <var>E</var> = <var>mc</var><sup>2</sup>.</p>
6. </body>
7. </html>
HTML Entities
HTML character entities are used as a replacement of reserved characters in HTML. You can
also replace characters that are not present on your keyboard by entities.
These characters are replaced because some characters are reserved in HTML.
For example: if you use less than (<) or greater than (>) symbols in your text, the
browser can mix them with tags that's why character entities are used in HTML to display
reserved characters.
Syntax:
1. &entity_name;
43
2. OR
3. &#entity_number;
44
Note:Entity names are case sensitive.
Disadvantage of entity name: Browsers may not support all entity names, but the
support for numbers is good.
Some diacritical marks, like grave ( )̀ and acute ( )́ are called accents.Diacritical marks
can be used both above and below a letter, inside a letter, and between two letters.
̀ a à à
́ a á á
̂ a â â
̃ a ã ã
̀ O Ò Ò
́ O Ó Ó
̂ O Ô Ô
̃ O Õ Õ
45
HTML Symbols
There are many mathematical, technical and currency symbols which are not present on a
normal keyboard. We have to use HTML entity names to add such symbols to an HTML
page.
If there no entity name exists, you can use an entity number, a decimal, or hexadecimal
reference.
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <p>This is Euro €</p>
5. <p>This is also Euro €</p>
6. <p> This is also Euro €</p>
7. </body>
8. </html>
Test it Now
46
∏ ∏ ∏ N-ARY PRODUCT
47
↓ ↓ ↓ DOWNWARDS ARROW
next →← prev
HTML Charset
HTML Charset is also called HTML Character Sets or HTML Encoding. It is used to display
an HTML page properly and correctly because for displaying anything correctly, a web
browser must know which character set (character encoding) to use.
UTF-8
UTF-8 is a variable width character encoding which covers almost all of the characters
and symbols in the world. ANSI (Windows-1252) was the original Windows character set,
which supported 256 different character codes.
ISO-8859-1 was the default character set for HTML 4. This character set also supported
256 different character codes.
Because ANSI and ISO-8859-1 were so limited, HTML 4 also supported UTF-8.The default
character encoding for HTML5 is UTF-8.
48
1. <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
1. <meta charset="UTF-8">
Syntax of a URL:
scheme://prefix.domain:port/path/filename
Here,
scheme is used to define the type of Internet service (most common is http or https).
dort is used to define the port number at the host (default for http is 80).
path is used to define a path at the server (If omitted: the root directory of the site).
URL Encoding
URL encoding is used to convert non-ASCII characters into a format that can be used over
the Internet because a URL is sent over the Internet by using the ASCII character-set only.
If a URL contains characters outside the ASCII set, the URL has to be converted.
49
In URL encoding, the non-ASCII characters are replaced with a "%" followed by
hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign,
or %20.
Following is a list of some character sets which are encoded by browser after
submitting the text.
next →← prev
Marquee HTML
The Marquee HTML tag is a non-standard HTML element which is used to scroll a image
or text horizontally or vertically.
In simple words, you can say that it scrolls the image or text up, down, left or right
automatically.
Marquee tag was first introduced in early versions of Microsoft's Internet Explorer. It is
compared with Netscape's blink element.
Test it Now
Attribute Description
behavior It facilitates user to set the behavior of the marquee to one of the three different types
50
alternate.
direction defines direction for scrolling content. It may be left, right, up and down.
Output:
51
<marquee width="100%" behavior="slide" bgcolor="pink">
This is an example of a slide marquee...
</marquee>
Test it Now
Output:
Output:
Output:
52
<marquee width="400px" height="100px" behavior="alternate" style="border:2px solid red"
>
<marquee behavior="alternate">
Nested marquee...
</marquee>
</marquee>
Test it Now
2) Since Marquee text moves, so it is more difficult to click static text, depending on the
scrolling speed.
4) It draws user's attention needlessly and makes the text harder to read
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.
Output:
53
New HTML 5 Textarea Attributes
Attribute Description
autofocus It specifies that a text area should be automatically get focused when the page is loade
maxlength It specifies the maximum number of characters allowed in the text area.
placeholder It specifies a short hint that describes the expected value of a textarea.
wrap It specifies that how the texts in the textarea are wrapped at the time of the submissio
54
Test it Now
Output:
Submit
Name:
The textarea element above is outside the form , but it is still the part of the form.
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.”
55
HTML blockquote tag is used to define a large quoted section. If you have a large quotation
then put the entire text within <blockquote>.............</blockquote> tag.
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
56
<q> It is used to put the small quotations.
<cite> It defines the title of source from where quotation or work is taken.
next →← prev
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.
1. style= "property:value"
Let's see a simple example of styling html tags by color property of css.
Output:
57
HTML Style background-color
The background-color property is used to define background color for the HTML tag.
Output:
Output:
58
Output:
1. <h3 style="text-align:right;background-
color:pink;">This text is located at right side</h3>
2. <p style="text-align:center;background-
color:pink;">This text is located at center side</p>
Test it Now
Output:
HTML Title
HTML title tag is used to provide a title name for your webpage. It is necessary for Search
Engine Optimization (SEO).
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.
1. <!DOCTYPE html>
2. <html>
59
3. <head>
4. <title>First web page.</title>
5. </head>
6. <body>
7. <p>Welcome to my first web page.</p>
8. </body>
9. </html>
n
Here you see that we are using two elements, the head tag and the title tag. The
whole
e title element is within the head tag.
x
The head element which appears before body element just contains the information about
t
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.
p
Doctype
r HTML
e
On the HTML document you have often seen that there is a <!DOCTYPE html> declaration
v
before the <html> tag. This <!DOCTYPE html> declaration is not an HTML tag. It is used to
instruct the web browser about the HTML page.
H
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.T
M
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.
L
DTD defines the rules for the markup languages so that the browsers recognize the content
Q
correctly.
e
Let's see an example of HTML document with doctype declaration.
1. s html>
<!DOCTYPE
60
H
T
M
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>
Test it Now
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.
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 large sections of HTML span element is used to wrap small
elements. image etc.
CSS Code:
.loginform{
padding:10px;
border:1px solid pink;
border-radius:10px;
float:right;
margin-top:10px;
}
.formheading{
background-color:red;
color:white;
padding:4px;
text-align:center;
}
.sub{
background-color:blue;
padding: 7px 40px 7px 40px;
color:white;
font-weight:bold;
margin-left:70px;
border-radius:5px;
}
62
HTML Code:
<div class="loginform">
<h3 class="formheading">Please Login</h3>
<form action="LoginServlet" method="post">
<table>
<tr><td>Email:</td><td><input type="email" name="email"/></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"/></td></tr>
Output:
Please Login
Email:
Password:
login
It is widely used to display language examples e.g. Java, C#, C, C++ etc because it displays
the code as it is typed.
63
5. </pre>
Test it Now
Output:
It is widely used to display language examples e.g. Java, C#, C, C++ etc because it displays
the code as it is typed.
Output:
64
Test it Now
Output:
package com.javatpoint;
public class FirstJava{
public static void main(String args[]){
System.out.println("hello java");
}
}
If you remove pre tagove pre tag from the above example, all the text will be displayed in a
single line.
package com.javatpoint; public class FirstJava{ public static void main(String args[]){
System.out.println("hello java"); } }
width attribute
The HTML <pre> tag also supports the width attribute. The width attribute specifies the
desired width of the pre-formatted text. But, it is not supported in HTML 5.
Tag Description
65
<code> defines a piece of computer code
Output:
It is inside em tag.
It is inside strong tag.
It is inside dfn tag.
It is inside code tag.
It is inside samp tag.
It is inside kbd tag.
It is inside var tag.
66
1. <label for="email">EMAIL-
ID:<br /> <input type="email" value="" name="emailid" size="30"
2. placeholder="Enter a valid email address"><br /><br />
3. <label for="phone">PHONE NO:<br /> <input type="text" value="" name="phno" size=
"30"
4. maxlength="10" placeholder="Enter a valid phone number" pattern="[0-
9]{10}"><br /><br />
Test it Now
Output:
EMAIL-ID:
PHONE NO:
1. <form action="#">
2. First name: <input type="text" name="FirstName" placeholder="enter firstname..."><br
>
3. Last name: <input type="text" name="LastName" placeholder="enter lastname..."><br>
Output:
67
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.
2) The input element is empty. It contains attributes only. There is no need of an end tag in
HTML.
3) If you want to define labels for input element, use the label element with each input tag.
You should always specify the type attribute for a <button> tag. Different browsers use
different default type for the button element.
HTML Button tag can be used inside and outside the form.
If you use it inside the form, it works as the submit button. You can also use it as reset
button.
If you use it outside the form, you can call JavaScript function on it.
68
HTML Button Tag Example
Let's see the code to display the button.
Output:
Click Here
Output:
Click Here
1. <form>
2. Enter Name:<input type="text" name="name"/><br/>
3. <button>Submit</button>
4. </form>
Test it Now
Output:
69
Enter Name:
Submit
<form>
Enter Name:<input type="text" name="name"/><br/>
<button type="reset">reset</button>
</form>
Test it Now
Output:
Enter Name:
Reset
Attribute Description
autofocus It specifies that a button should automatically get focus while the loading of the pa
form It specifies one or more forms that the button belongs to.
formaction It is used for submit type. It specifies where to send the form data when form is su
formnovalidate It specifies that the form data should not be validated on submission.
70
formtarget It specifies that where to display the response after submitting the form.
HTML hr tag
HTML <hr> tag is used to specify a paragraph-level thematic break in HTML document. It is
used when you abruptly change your topic in your HTML document. It draw a horizontal line
between them. It is also called a Horizontal Rule in HTML.
HTML hr tag
1. <h2>HTML</h2>
2. <p>HTML is a language for describing web pages.</p>
3. <hr/>
4. <h2>HR Tag </h2>
5. <p> HR tag is used to draw a horizontal line within the texts to sepate content.<p>
Test it Now
Output:
HTML
HTML is a language for describing web pages.
HR Tag
HR tag is used to draw a horizontal line within the texts to separate content.
71
HR tag in HTML and XHTML
In HTML <hr> tag need not to be closed whereas <hr> tag must be properly closed in
XHTML.
HTML br tag
HTML <br> tag or element is used to break line in a paragraph.
Don't use br tag for margin between two paragraphs, use CSS margin property instead.
Output:
72
HTML Script Tag
HTML script tag is used to specify client-side script such as JavaScript. It facilitate you to
place a script within your HTML document.
JavaScript is used for image manipulation, form validation, and dynamic content.
1. <script>
2. //code to be executed
3. </script>
src It specifies the URL of an external script file. HTML 4.01, HTML5
73
The script tag can be used within <body> or <head> tag to embed the scripting code. Let's
see the example to have script tag within HTML body.
1. <script type="text/javascript">
2. document.write("JavaScript is a simple language for javatpoint learners")
3. </script>
Test it Now
Output:
Let's see the example to have script tag within HTML head tag.
1. <script type="text/javascript">
2. function msg(){
3. alert("Hello Javatpoint");
4. }
5. </script>
Test it Now
The <noscript> element can be used within <head> and <body> tags.
While using noscript tag inside <head> element, <noscript> must contain <link>, <style>,
and <meta> tags.
74
The text inside the <noscript> element will be displayed if the user's browser is not script
supporting.
1. <script>
2. document.write("Welcome to JavaTpoint")
3. </script>
4. <noscript>Sorry! Your browser does not support JavaScript.!</noscript>
Test it Now
Output:
Welcome to JavaTpoint
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.
75
HTML bold tag example
1. <p> Hello guys, <b>this is the method to write bold text.</b></p>
Test it Now
Output:
Note: According to HTML5 specification, b tag should be used only if no other tag is
appropriate. For example: If you want to write a heading, you must use the header tag <h1> to
<h6>. Important statement should be denoted within <strong>.....</strong> tag, and the text
you want to mark or highlight, must be put within <mark>...</mark> tag.
76
HTML5 Tutorial
HTML5 tutorial provides details of all 40+ HTML tags including audio, video, header,
footer, data, datalist, article etc. This HTML tutorial is designed for beginners and
professionals.
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. There are some elements like <header>, <footer>,
<nav> and <article> that define the layout of a website.
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.
HTML 5 Example
Let's see a simple example of HTML5.
1. <!DOCTYPE>
2. <html>
3. <body>
4. <h1>Write Your First Heading</h1>
5. <p>Write Your First Paragraph.</p>
6. </body>
7. </html>
77
Test it Now
For example:
1. <!DOCTYPE html>
You can also use <!DOCTYPE html> to maintain your lower case practice.
o Mixing lower case and upper case letters in elements is not a good idea.
Example:
Bad practice:
1. <SECTION>
2. <p>This is javatpoint.com</p>
3. </SECTION>
78
Note: This example will run but it is not a good practice to write elements in uppercase
letters.
1. <Section>
2. <p>This is a javatpoint.com</p>
3. </SECTION>
Good practice:
1. <section>
2. <p>This is javatpoint.com.</p>
3. </section>
Bad practice:
1. <section>
2. <p>This is javatpoint.com
3. </section>
Good practice:
1. <section>
2. <p>This is javatpoint.com</p>
3. </section>
Good practice:
1. <meta charset="utf-8">
79
Don't Omit <html> and <body>
HTML5 facilitates you to omit and tag. You can exclude both tags and the program will work
well enough.
Example:
1. <!DOCTYPE html>
2. <head>
3. <title>Page Title</title>
4. </head>
5. <h1>This is javatpoint.com</h1>
6. <p>Welcome to javatpoint.com</p>
Test it Now
We recommend you to not to omit and tag because is a root element and specifies the page
language.
Syntax:
1. <!DOCTYPE html>
2. <html lang="en-US">
Example:
1. <!DOCTYPE html>
2. <html lang="en-US">
3. <head>
4. <title>Page Title</title>
5. </head>
6. <body>
7. <h1>This is a heading</h1>
8. <p>This is a paragraph.</p>
9. </body>
10. </html>
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.
80
List of HTML 5 Tags
Tag Description
<article> This element is used to define an independent piece of content in a document, that ma
magazine or a newspaper article.
<aside> It specifies that article is slightly related to the rest of the whole page.
<bdi> The bdi stands for bi-directional isolation. It isolates a part of text that is formatted in
from the outside text document.
81
<main> It defines the main content of a 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.
82
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>
Test it Now
Output:
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.
83
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.
mp3 audio/mpeg
ogg audio/ogg
wav audio/wav
Currently, there are three video formats supported for HTML video tag:
1. mp4
2. webM
84
3. ogg
Let's see the table that defines which web browser supports video file format.
yes no
Internet Explorer
yes yes
Google Chrome
yes yes
Mozilla Firefox
no yes
Opera
yes no
Apple Safari
1. <video controls>
2. <source src="movie.mp4" type="video/mp4">
3. Your browser does not support the html video tag.
4. </video>
Test it Now
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.
85
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.
preload It specifies the author view to upload video file when the page loads.
86
MIME Types for HTML Video format
The available MIME type HTML video tag is given below.
mp4 video/mp4
ogg video/ogg
webM video/webM
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.
87
HTML Progress Tag Example
Let's see HTML progress example without attribute.
1. <progress></progress>
Test it Now
Output:
Let's see the progress example with value and max attributes.
1. Downloading progress:
2. <progress value="43" max="100"></progress>
Test it Now
Output:
Downloading progress:
1. progress{
2. width: 300px;
3. height: 30px;
4. }
Test it Now
Output:
1. <script>
88
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>
Test it Now
Output:
click me
The HTML meter tag is new in HTML5 so you must use new browsers.
89
Attributes Description
value It is a mandatory attribute which is used to specify a value in numbers. The number may
floating point number.
form It specifies one or more forms to which meter element belongs to.
optimum It specifies the optimum value for the gauge.It is an optional attribute.
1. <p>Display a gauge:</p>
2. <meter value="30" min="1" max="100">30 out of 100</meter><br>
3. <meter value="0.8">80%</meter>
Test it Now
Output:
Display a gauge:
Styling Meter
You can apply CSS code on meter tag.
1. meter{
2. width: 300px;
90
3. height: 30px;
4. }
Test it Now
Output:
Suppose you have to represent some numbers to your users with letter (i.e. one, two, three
and so on) but you have script that sorts the numbers in ascending or descending orders.
So your script needs numbers in a format like 1, 2, 3... etc.
Attribute Description
value It is required attribute. It is used to provide the machine-readable version of tag's conten
91
4. <li><data value="121">HTML tutorial</data></li>
5. </ul>
Test it Now
Output:
o Java Tutorial
o SQL tutorial
o HTML tutorial
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.
1. <label>
2. Enter your favorite cricket player: Press any character<br />
3. <input type="text" id="favCktPlayer" list="CktPlayers">
4. <datalist id="CktPlayers">
5. <option value="Sachin Tendulkar">
6. <option value="Brian Lara">
7. <option value="Jacques Kallis">
8. <option value="Ricky Ponting">
9. <option value="Rahul Dravid">
10. <option value="Shane Warne">
11. <option value="Rohit Sharma">
92
12. <option value="Donald Bradman">
13. <option value="Saurav Ganguly ">
14. <option value="AB diVilliers">
15. <option value="Mahendra Singh Dhoni">
16. <option value="Adam Gilchrist">
17. </datalist>
18. </label>
Test it Now
Output:
You can use several <header> elements in one document, but a <header> element cannot
be placed within a <footer>, <address> or another <header> element.
Output:
ABCOnline.com
World's no.1 shopping website
93
CSS Code:
1. header{
2. border: 1px solid pink;
3. background-color:pink;
4. padding:10px;
5. border-radius:5px;
6. }
HTML Code:
1. <header>
2. <h2>ABCOnline.com</h2>
3. <p> World's no.1 shopping website</p>
4. </header>
Test it Now
Output:
ABCOnline.com
World's no.1 shopping website
HTML <footer> tag contains information about its containing elements for example:
o author information
o contact information
o copyright information
o sitemap
94
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.
5. </address>
6. </p>
7. <p>Contact information:
8. <a href="mailto:sonoojaiswal1987@gmail.com">sonoojaiswal1987@gmail.com</a>.
9. </p>
10. </footer>
Test it Now
Output:
JavaTpoint, plot no. 6, near MMX Mall,Mohan Nagar, Ghaziabad Pin no. 201007
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.
95
HTML figure tag example
1. <p>The Taj Mahal is widely recognized as "the jewel of Muslim art in India and
2. one of the universally admired masterpieces of the world's heritage". It is regarded
3. by many as the finest example of Mughal architecture, a style that combines elements
4. from Islamic, Persian, Ottoman, Turkish and Indian architectural styles.</p>
5. <figure>
6. <img src="htmlpages/images/tajmahal.jpg" alt="Taj Mahal"/>
7. </figure>
Test it Now
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.
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.
96
HTML figure tag example
1. <figure>
2. <img src="htmlpages/images/tajmahal.jpg" alt="Taj Mahal"/>
3. <figcaption>Fig.1.1 - A front view of the great Taj Mahal in Agra.</figcaption>
4. </figure>
Test it Now
Output:
Supporting Browsers
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.
6. of Gujarat state from 2001 to 2014. He is currently the Member of Parliament (MP) from V
aranasi. </p>
7. </article>
Test it Now
Output:
97
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.
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.
98
HTML Dialog Tag
HTML <dialog> tagto 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.
Output:
99
Show Dialog
HTML dialog tag also supports global and event attributes in HTML.
According to W3C HTML specification, it is used as a disclosure widget from which user can
retrieve additional information or control.
It is used together with a relevant tag known as <summary>. Technically, there is no need
of summary tag, but if you ignore this then the browser will use some default text.
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.
Attribute Description
open It specifies that the details will be displayed (open) to the user.
100
6. <p><b>Note:</b> The details tag is currently only supported in Opera, Chrome, and in S
afari 6.</p>
Test it Now
Output:
Copyright 2011-2014.
Note: The details tag is currently only supported in Opera, Chrome, and in Safari 6.
Output:
JavaTpoint Summary
1. <details>
2. <summary>MacBook Pro Specification</summary>
3. <ul>
101
4. <li><strong>13.3-inch LED-backlit glossy widescreen display</strong> with edge-
to-edge, uninterrupted glass (1280 x 800-pixel resolution).</li>
5. <li><strong>2.4 GHz Intel Core i5 dual-
core processor</strong> with 3 MB shared L3 cache for excellent multitasking.</li>
6. <li><strong>Intel HD Graphics 3000</strong> with 384 MB of DDR3 SDRAM shared
with main memory.</li>
7. <li><strong>500 GB Serial ATA hard drive</strong> (5400 RPM)</li>
8. <li><strong>4 GB installed RAM</strong> (1333 MHz DDR3; supports up to 8 GB)
</li>
9. </ul>
10. </details>
Test it Now
Output:
The <summary> tag supports only Global attributes in HTML 5. There are no other specific
attributes used with <summary> tag.
1. section{
2. border:1px solid pink;
3. padding:15px;
4. margin:10px;
5. }
102
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
103
The <section> tag supports global and event attributes in HTML 5.
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:
104
The business meeting is scheduled on next wednesday.
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.
The <main> tag is written within <body> tag. It is used to accurately describe the primary
content of a page.
The content of the main tag is directly related to the central topic of the document.
Points to remember:
Author should not include more than one <main> tag within a document.
The <main> element should not used as a child of an <article>, <aside>, <header>,
<footer>, or <nav> element.
HTML main tag and its sub elements can be easily styled by CSS.
105
3. <p>The apple is a red color pomaceous fruit of the apple tree. It is a very famous saying a
bout apple.
4. </br> "An apple in a day, keeps the Doctor away".</p>
5. <article>
6. <h3>Red Delicious</h3>
7. <p>These bright red apples are the most common found in many supermarkets.</p>
8. </article>
9. <article>
10. <h3>Granny Smith</h3>
11. <p>These juicy, green apples make a great filling for apple pies.</p>
12. </article>
13. </main>
Test it Now
Output:
Apples
The apple is a red color pomaceous fruit of the apple tree. It is a very famous saying about
apple.
"An apple in a day, keeps the Doctor away".
Red Delicious
These bright red apples are the most common found in many supermarkets.
Granny Smith
These juicy, green apples make a great filling for apple pies.
The <main> tag also supports global attributes and event attributes in HTML 5.
Without wbr tag, it is very difficult to read a long single word or a sentence. Without wbr
tag, single long word can wrap or not wrap at all, it creates problem for the layout of the
page.
Without <wbr> tag, users will have to scroll right to read a long complete word or sentence.
106
The <wbr> tag is new and introduced in HTML 5.
Test it Now
Output:
This is a world record for the largest word, a 45-letter word appears in a major
dictionarypneumonoultramicroscopicsilicovolcanoconiosis
107
pneumonoultramicroscopicsilicovolcaniosis
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.
Output:
108
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.
Output:
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.
Output:
109
Drawing Circle on Canvas
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().
Output:
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.
110
4. var c = document.getElementById("myCanvasText1");
5. var cctx = c.getContext("2d");
6. ctx.font = "30px Arial";
7. ctx.fillText("Hello JavaTpoint",10,50);
8. </script>
Output:
Output:
HTML SVG
The HTML SVG is an acronym which stands for Scalable Vector Graphics.
HTML SVG is a modularized language which is used to describe graphics in XML. It describe
two-dimensional vector and mixed vector/raster graphics in XML. It is a W3C
recommendation. SVG images and their behaviors are defined in XML text files. So as XML
files, you can create and edit an SVG image with text editor, but generally drawing
programs like inkspace are preferred to create it.
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.
111
1. <svg width="100" height="100">
2. <circle cx="50" cy="50" r="40" stroke="yellow" stroke-width="4" fill="red" />
3. </svg>
Here, we are using cx, cy and r attributes of circle tag. These attributes can't be used with
svg rect tag.
Test it Now
Output:
Test it Now
Output:
Test it Now
Output:
112
Why SVG is preferred over other image formats?
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.
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.
113
Drop Drop It fires at the end of the drag operation.
Dragend It fires when user releases the mouse button to complete the drag operation.
1. <script>
2. function allowDrop(ev) {ev.preventDefault();}
3. function drag(ev) {ev.dataTransfer.setData("text/html", ev.target.id);}
4. function drop(ev) {
5. ev.preventDefault();
6. var data = ev.dataTransfer.getData("text/html");
7. ev.target.appendChild(document.getElementById(data));
8. }
9. </script>
10. <p>Drag the javatpoint image into the rectangle:</p>
11. <div id="div1" style="width:350px;height:100px;padding:10px;border:1px solid #aaaaaa;
"
12. ondrop="drop(event)" ondragover="allowDrop(event)"></div>
13. <br>
14. <img id="drag1" src="/htmlpages/images/javatpoint.png" alt="javatpoint image"
15. draggable="true" ondragstart="drag(event)"/>
In the above example, we have used ondrop and ondragover events on div element,
and ondragstart event on img tag.
Test it Now
Output:
114
Note: MouseEvent is not fired during drag operation.
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:
4) Do the Drop:
Syntax:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>First Google Map Example</h1>
5. <div id="map">My map will go here...</div>
6. </body>
7. </html>
115
Set the Map Size
You can set the map size by using the following syntax:
You can set the map properties by creating a function. Here, the function is myMap(). This
example shows the Google map centered in London, England.
We have to use the functionalities of Google Maps API provided by a JavaScript library
located at Google. Use the following script to refer to the Google Maps API with a callback to
the myMap function.
1. <script src="https://maps.googleapis.com/maps/api/js?callback=myMap"></script>
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h1>My First Google Map</h1>
5. <div id="map" style="width:400px;height:400px;background:grey"></div>
6. <script>
7. function myMap() {
8. var mapOptions = {
9. center: new google.maps.LatLng(51.5, -0.12),
10. zoom: 10,
11. mapTypeId: google.maps.MapTypeId.HYBRID
12. }
13. var map = new google.maps.Map(document.getElementById("map"), mapOptions);
14. }
15. </script>
16. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-
916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
17. </body>
18. </html>
Test it Now
Example Explanation
116
mapOptions: It is a variable which defines the properties for the map.
center: It specifies where to center the map (using latitude and longitude coordinates).
zoom: It specifies the zoom level for the map (try to experiment with the zoom level).
mapTypeId: It specifies the map type to display. The following map types are supported:
ROADMAP, SATELLITE, HYBRID, and TERRAIN.
element with id="map", using the parameters that are passed (mapOptions).
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <div id="googleMap1" style="width:400px;height:300px;"></div>
5. <br>
6. <div id="googleMap2" style="width:400px;height:300px;"></div>
7. <br>
8. <div id="googleMap3" style="width:400px;height:300px;"></div>
9. <br>
10. <div id="googleMap4" style="width:400px;height:300px;"></div>
11. <script>
12. function myMap() {
13. var mapOptions1 = {
14. center: new google.maps.LatLng(51.508742,-0.120850),
15. zoom:9,
16. mapTypeId: google.maps.MapTypeId.ROADMAP
17. };
18. var mapOptions2 = {
19. center: new google.maps.LatLng(51.508742,-0.120850),
20. zoom:9,
21. mapTypeId: google.maps.MapTypeId.SATELLITE
22. };
117
23. var mapOptions3 = {
24. center: new google.maps.LatLng(51.508742,-0.120850),
25. zoom:9,
26. mapTypeId: google.maps.MapTypeId.HYBRID
27. };
28. var mapOptions4 = {
29. center: new google.maps.LatLng(51.508742,-0.120850),
30. zoom:9,
31. mapTypeId: google.maps.MapTypeId.TERRAIN
32. };
33. var map1 = new google.maps.Map(document.getElementById("googleMap1"),mapOptions
1);
34. var map2 = new google.maps.Map(document.getElementById("googleMap2"),mapOptions
2);
35. var map3 = new google.maps.Map(document.getElementById("googleMap3"),mapOptions
3);
36. var map4 = new google.maps.Map(document.getElementById("googleMap4"),mapOptions
4);
37. }
38. </script>
39. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu-
916DdpKAjTmJNIgngS6HL_kDIKU0aU&callback=myMap"></script>
40. </body>
41. </html>
Test it Now
HTML5 Semantics
In any language, semantics is used to study the meaning of words and phrases. i.e.
semantic elements= elements with a meaning.
Semantic elements have a simple and clear meaning for both, the browser and the
developer.
For example:
<div>, <span> etc. 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.
118
HTML5 semantic elements are supported by all major browsers.
Semantic elements are used in HTML5 because in HTML4, developers have to use their own
id/class names to style elements: header, top, bottom, footer, menu, navigation, main,
container, content, article, sidebar, topnav, etc.
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."
3. <details> Defines additional details that the user can view or hide
119
10. <nav> Defines navigation links
https://www.javatpoint.com/html-article-tag
https://www.javatpoint.com/html-section-tag
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>.
120
HTML5 <nav> Element
The HTML <nav> element is used to define a set of navigation links.
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>
Test it Now
HTML5<figure> Element
https://www.javatpoint.com/html-figure-tag
https://www.javatpoint.com/html-figcaption-tag
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:
121
In HTML4 In HTML5
Example:
1. <!DOCTYPE HTML PUBLIC "-
//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2. <html lang="en">
3. <head>
4. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
5. <title>HTML4</title>
6. <style>
7. body {
8. font-family: Verdana,sans-serif;
9. font-size: 0.9em;
10. }
11.
12. div#header, div#footer {
13. padding: 10px;
14. color: white;
15. background-color: black;
16. }
17.
18. div#content {
122
19. margin: 5px;
20. padding: 10px;
21. background-color: lightgrey;
22. }
23.
24. div.article {
25. margin: 5px;
26. padding: 10px;
27. background-color: white;
28. }
29.
30. div#menu ul {
31. padding: 0;
32. }
33.
34. div#menu ul li {
35. display: inline;
36. margin: 5px;
37. }
38. </style>
39. </head>
40. <body>
41.
42. <div id="header">
43. <h1>JavaTpoint Times</h1>
44. </div>
45.
46. <div id="menu">
47. <ul>
48. <li>Tutorials</li>
49. <li>Technology</li>
50. <li>Blog</li>
51. </ul>
52. </div>
53.
54. <div id="content">
55. <h2>Tutorials Section</h2>
123
56. <div class="article">
57. <h2>Tutorial1</h2>
58. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
59. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
60. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
61. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
62. </div>
63. <div class="article">
64. <h2>Tutorial2</h2>
65. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
66. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
67. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
68. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
69. </div>
70. </div>
71.
72. <div id="footer">
73. <p>© 2018 JavaTpoint Times. All rights reserved.</p>
74. </div>
75.
76. </body>
77. </html>
Test it Now
1. <!DOCTYPE html>
Example:
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
124
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.
125
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.
53. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
54. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
55. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
56. </div>
57. <div class="article">
58. <h2>Tutorial2</h2>
59. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
60. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
61. <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque in porta lorem.
62. Morbi condimentum est nibh, et consectetur tortor feugiat at.</p>
63. </div>
64. </div>
65. <div id="footer">
66. <p>© 2018 JavaTpoint Times. All rights reserved.</p>
67. </div>
68.
69. </body>
70. </html>
It is recommended to use hex values than html color names because it occupies less space.
Whenever you minify your css file, it uses hex color value replacing html color names.
126
Let's see the list of 500+ html color names.
ABCDFGHIKLMNOPRSTVWY
A color names
There is given a list of 13 color names that starts with A letter.
AliceBlue #f0f8
AntiqueWhite #fae
AntiqueWhite1 #ffef
AntiqueWhite2 #eed
AntiqueWhite3 #cdc
AntiqueWhite4 #8b8
aquamarine1 #7fff
aquamarine2 #76e
aquamarine4 #458
azure1 #f0ff
127
azure2 #e0e
azure3 #c1c
azure4 #838
B color names
There is given a list of 21 color names that starts with B letter.
beige #f5
bisque1 #ffe
bisque2 #ee
bisque3 #cd
bisque4 #8b
black #00
BlanchedAlmond #ffe
blue1 #00
blue2 #00
blue4 #00
128
BlueViolet #8a
brown #a5
brown1 #ff4
brown2 #ee
brown3 #cd
brown4 #8b
burlywood #de
burlywood1 #ffd
burlywood2 #ee
burlywood3 #cd
burlywood4 #8b
C color names
There is given a list of 27 color names that starts with C letter.
CadetBlue #5f9
CadetBlue1 #98f
129
CadetBlue2 #8ee
CadetBlue3 #7ac
CadetBlue4 #538
chartreuse1 #7ff
chartreuse2 #76e
chartreuse3 #66c
chartreuse4 #458
chocolate #d26
chocolate1 #ff7
chocolate2 #ee7
chocolate3 #cd6
coral #ff7
coral1 #ff7
coral2 #ee6
coral3 #cd5
coral4 #8b3
130
CornflowerBlue #649
cornsilk1 #fff8
cornsilk2 #eee
cornsilk3 #cdc
cornsilk4 #8b8
cyan1 #00f
cyan2 #00e
cyan3 #00c
cyan4 #008
D color names
There is given a list of 49 color names that starts with D letter.
DarkGoldenrod #b
DarkGoldenrod1 #ff
DarkGoldenrod2 #e
DarkGoldenrod3 #cd
131
DarkGoldenrod4 #8
DarkGreen #0
DarkKhaki #b
DarkOliveGreen #5
DarkOliveGreen1 #ca
DarkOliveGreen2 #b
DarkOliveGreen3 #a
DarkOliveGreen4 #6
DarkOrange #ff
DarkOrange1 #ff
DarkOrange2 #e
DarkOrange3 #cd
DarkOrange4 #8
DarkOrchid #9
DarkOrchid1 #b
DarkOrchid2 #b
132
DarkOrchid3 #9
DarkOrchid4 #6
DarkSalmon #e
DarkSeaGreen #8
DarkSeaGreen1 #c1
DarkSeaGreen2 #b
DarkSeaGreen3 #9
DarkSeaGreen4 #6
DarkSlateBlue #4
DarkSlateGray #2
DarkSlateGray1 #9
DarkSlateGray2 #8
DarkSlateGray3 #7
DarkSlateGray4 #5
DarkTurquoise #0
DarkViolet #9
133
DeepPink1 #ff
DeepPink2 #e
DeepPink3 #cd
DeepPink4 #8
DeepSkyBlue1 #0
DeepSkyBlue2 #0
DeepSkyBlue3 #0
DeepSkyBlue4 #0
DimGray #6
DodgerBlue1 #1
DodgerBlue2 #1
DodgerBlue3 #1
DodgerBlue4 #1
F color names
There is given a list of 7 color names that starts with F letter.
134
firebrick #b2222
firebrick1 #ff303
firebrick2 #ee2c2
firebrick3 #cd262
firebrick4 #8b1a1
FloralWhite #fffaf0
ForestGreen #228b2
G color names
There is given a list of 115 color names that starts with G letter.
gainsboro #dcdcd
GhostWhite #f8f8ff
gold1 #ffd70
gold2 #eec90
gold3 #cdad0
gold4 #8b75
135
goldenrod #daa52
goldenrod1 #ffc125
goldenrod2 #eeb42
goldenrod3 #cd9b1
goldenrod4 #8b69
gray #bebeb
gray1 #0303
gray10 #1a1a1
gray11 #1c1c1
gray12 #1f1f1
gray13 #2121
gray14 #2424
gray15 #2626
gray16 #2929
gray17 #2b2b
gray18 #2e2e2
136
gray19 #3030
gray2 #0505
gray20 #3333
gray21 #3636
gray22 #3838
gray23 #3b3b
gray24 #3d3d
gray25 #4040
gray26 #4242
gray27 #4545
gray28 #4747
gray29 #4a4a4
gray3 #0808
gray30 #4d4d
gray31 #4f4f4
gray32 #5252
137
gray33 #5454
gray34 #5757
gray35 #5959
gray36 #5c5c5
gray37 #5e5e5
gray38 #6161
gray39 #6363
gray4 #0a0a0
gray40 #6666
gray41 #6969
gray42 #6b6b
gray43 #6e6e6
gray44 #7070
gray45 #7373
gray46 #7575
gray47 #7878
138
gray48 #7a7a7
gray49 #7d7d
gray5 #0d0d
gray50 #7f7f7
gray51 #8282
gray52 #8585
gray53 #8787
gray54 #8a8a8
gray55 #8c8c8
gray56 #8f8f8
gray57 #9191
gray58 #9494
gray59 #9696
gray6 #0f0f0
gray60 #9999
gray61 #9c9c9
139
gray62 #9e9e9
gray63 #a1a1a
gray64 #a3a3a
gray65 #a6a6a
gray66 #a8a8a
gray67 #ababa
gray68 #adada
gray69 #b0b0
gray7 #1212
gray70 #b3b3
gray71 #b5b5
gray72 #b8b8
gray73 #babab
gray74 #bdbdb
gray75 #bfbfb
gray76 #c2c2c
140
gray77 #c4c4c
gray78 #c7c7c
gray79 #c9c9c
gray8 #1414
gray80 #ccccc
gray81 #cfcfcf
gray82 #d1d1
gray83 #d4d4
gray84 #d6d6
gray85 #d9d9
gray86 #dbdbd
gray87 #deded
gray88 #e0e0e
gray89 #e3e3e
gray9 #1717
gray90 #e5e5e
141
gray91 #e8e8e
gray92 #ebebe
gray93 #edede
gray94 #f0f0f0
gray95 #f2f2f2
gray97 #f7f7f7
gray98 #fafafa
gray99 #fcfcfc
green1 #00ff0
green2 #00ee0
green3 #00cd0
green4 #008b
GreenYellow #adff2
H color names
There is given a list of 9 color names that starts with H letter.
142
honeydew1 #f0fff0
honeydew2 #e0eee
honeydew3 #c1cdc1
honeydew4 #838b8
HotPink #ff69b4
HotPink1 #ff6eb4
HotPink2 #ee6aa
HotPink3 #cd609
HotPink4 #8b3a6
I color names
There is given a list of 9 color names that starts with I letter.
IndianRed #cd5c5c
IndianRed1 #ff6a6a
IndianRed2 #ee636
IndianRed3 #cd555
143
IndianRed4 #8b3a3
ivory1 #fffff0
ivory2 #eeeee0
ivory3 #cdcdc1
ivory4 #8b8b8
K color names
There is given a list of 5 color names that starts with K letter.
khaki #f0e68c
khaki1 #fff68f
khaki2 #eee685
khaki3 #cdc673
khaki4 #8b864e
L color names
There is given a list of 55 color names that starts with L letter.
144
Color Name Color Co
lavender
LavenderBlush1
LavenderBlush2
LavenderBlush3
LavenderBlush4
LawnGreen
LemonChiffon1
LemonChiffon2
LemonChiffon3
LemonChiffon4
light
LightBlue
LightBlue1
LightBlue2
LightBlue3
145
LightBlue4
LightCoral
LightCyan1
LightCyan2
LightCyan3
LightCyan4
LightGoldenrod1
LightGoldenrod2
LightGoldenrod3
LightGoldenrod4
LightGoldenrodYellow
LightGray
LightPink
LightPink1
LightPink2
LightPink3
146
LightPink4
LightSalmon1
LightSalmon2
LightSalmon3
LightSalmon4
LightSeaGreen
LightSkyBlue
LightSkyBlue1
LightSkyBlue2
LightSkyBlue3
LightSkyBlue4
LightSlateBlue
LightSlateGray
LightSteelBlue
LightSteelBlue1
LightSteelBlue2
147
LightSteelBlue3
LightSteelBlue4
LightYellow1
LightYellow2
LightYellow3
LightYellow4
LimeGreen
linen
M color names
There is given a list of 34 color names that starts with M letter.
magenta #
magenta2 #
magenta3 #
magenta4 #
maroon #
148
maroon1 #
maroon2 #
maroon3 #
maroon4 #
medium #
MediumAquamarine #
MediumBlue #
MediumOrchid #
MediumOrchid1 #
MediumOrchid2 #
MediumOrchid3 #
MediumOrchid4 #
MediumPurple #
MediumPurple1 #
MediumPurple2 #
MediumPurple3 #
149
MediumPurple4 #
MediumSeaGreen #
MediumSlateBlue #
MediumSpringGreen #
MediumTurquoise #
MediumVioletRed #
MidnightBlue #
MintCream #
MistyRose1 #
MistyRose2 #
MistyRose3 #
MistyRose4 #
moccasin #
N color names
There is given a list of 5 color names that starts with N letter.
150
NavajoWhite1 #ffde
NavajoWhite2 #eecf
NavajoWhite3 #cdb3
NavajoWhite4 #8b7
NavyBlue #000
O color names
There is given a list of 18 color names that starts with O letter.
OldLace #fdf5e
OliveDrab #6b8e2
OliveDrab1 #c0ff3e
OliveDrab2 #b3ee3
OliveDrab4 #698b
orange1 #ffa50
orange2 #ee9a0
orange3 #cd850
151
orange4 #8b5a0
OrangeRed1 #ff450
OrangeRed2 #ee400
OrangeRed3 #cd370
OrangeRed4 #8b25
orchid #da70d
orchid1 #ff83fa
orchid2 #ee7ae
orchid3 #cd69c
orchid4 #8b47
P color names
There is given a list of 38 color names that starts with P letter.
pale #db7
PaleGoldenrod #eee
PaleGreen #98f
152
PaleGreen1 #9af
PaleGreen2 #90e
PaleGreen3 #7cc
PaleGreen4 #548
PaleTurquoise #afe
PaleTurquoise1 #bbf
PaleTurquoise2 #aee
PaleTurquoise3 #96c
PaleTurquoise4 #668
PaleVioletRed #db7
PaleVioletRed1 #ff8
PaleVioletRed2 #ee7
PaleVioletRed3 #cd6
PaleVioletRed4 #8b4
PapayaWhip #ffe
PeachPuff1 #ffd
153
PeachPuff2 #eec
PeachPuff3 #cda
PeachPuff4 #8b7
pink #ffc0
pink1 #ffb
pink2 #eea
pink3 #cd9
pink4 #8b6
plum #dda
plum1 #ffb
plum2 #eea
plum3 #cd9
plum4 #8b6
PowderBlue #b0e
purple #a02
purple1 #9b3
154
purple2 #912
purple3 #7d2
purple4 #551
R color names
There is given a list of 14 color names that starts with R letter.
red1 #ff000
red2 #ee000
red3 #cd000
red4 #8b00
RosyBrown #bc8f8
RosyBrown1 #ffc1c1
RosyBrown2 #eeb4b
RosyBrown3 #cd9b9
RosyBrown4 #8b69
RoyalBlue #4169
155
RoyalBlue1 #4876
RoyalBlue2 #436ee
RoyalBlue3 #3a5fc
RoyalBlue4 #2740
S color names
There is given a list of 48 color names that starts with S letter.
SaddleBrown #8b4
salmon #fa80
salmon1 #ff8c6
salmon2 #ee82
salmon3 #cd70
salmon4 #8b4
SandyBrown #f4a4
SeaGreen1 #54ff
SeaGreen2 #4eee
156
SeaGreen3 #43cd
SeaGreen4 #2e8b
seashell1 #fff5e
seashell2 #eee5
seashell3 #cdc5
seashell4 #8b8
sienna #a052
sienna1 #ff82
sienna2 #ee79
sienna3 #cd68
sienna4 #8b4
SkyBlue #87ce
SkyBlue1 #87ce
SkyBlue2 #7ec0
SkyBlue3 #6ca6
SkyBlue4 #4a70
157
SlateBlue #6a5a
SlateBlue1 #836
SlateBlue2 #7a67
SlateBlue3 #695
SlateBlue4 #473
SlateGray #708
SlateGray1 #c6e2
SlateGray2 #b9d
SlateGray3 #9fb6
SlateGray4 #6c7b
snow1 #fffaf
snow2 #eee9
snow3 #cdc9
snow4 #8b8
SpringGreen1 #00ff
SpringGreen2 #00ee
158
SpringGreen3 #00cd
SpringGreen4 #008
SteelBlue #468
SteelBlue1 #63b
SteelBlue2 #5cac
SteelBlue3 #4f94
SteelBlue4 #366
T color names
There is given a list of 19 color names that starts with T letter.
tan #d2b48c
tan1 #ffa54f
tan2 #ee9a49
tan3 #cd853f
tan4 #8b5a2b
thistle #d8bfd8
159
thistle1 #ffe1ff
thistle2 #eed2ee
thistle3 #cdb5cd
thistle4 #8b7b8b
tomato1 #ff6347
tomato2 #ee5c42
tomato3 #cd4f39
tomato4 #8b3626
turquoise #40e0d0
turquoise1 #00f5ff
turquoise2 #00e5ee
turquoise3 #00c5cd
turquoise4 #00868b
V color names
There is given a list of 6 color names that starts with V letter.
160
violet #ee82ee
VioletRed #d02090
VioletRed1 #ff3e96
VioletRed2 #ee3a8c
VioletRed3 #cd3278
VioletRed4 #8b2252
W color names
There is given a list of 7 color names that starts with W letter.
wheat #f5deb
wheat1 #ffe7b
wheat2 #eed8
wheat3 #cdba9
wheat4 #8b7e
white #ffffff
WhiteSmoke #f5f5f5
161
Y color names
There is given a list of 5 color names that starts with A letter.
yellow1 #ffff00
yellow2 #eeee0
yellow3 #cdcd0
yellow4 #8b8b
YellowGreen #9acd3
HTML SVG
The HTML SVG is an acronym which stands for Scalable Vector Graphics.
HTML SVG is a modularized language which is used to describe graphics in XML. It describe
two-dimensional vector and mixed vector/raster graphics in XML. It is a W3C
recommendation. SVG images and their behaviors are defined in XML text files. So as XML
files, you can create and edit an SVG image with text editor, but generally drawing
programs like inkspace are preferred to create it.
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.
162
2. <circle cx="50" cy="50" r="40" stroke="yellow" stroke-width="4" fill="red" />
3. </svg>
Here, we are using cx, cy and r attributes of circle tag. These attributes can't be used with
svg rect tag.
Test it Now
Output:
Test it Now
Output:
Test it Now
Output:
163
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.
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.
164
HTML5 Drag and Drop Example
Let's see an example of HTML 5 drag and drop feature.
1. <script>
2. function allowDrop(ev) {ev.preventDefault();}
3. function drag(ev) {ev.dataTransfer.setData("text/html", ev.target.id);}
4. function drop(ev) {
5. ev.preventDefault();
6. var data = ev.dataTransfer.getData("text/html");
7. ev.target.appendChild(document.getElementById(data));
8. }
9. </script>
10. <p>Drag the javatpoint image into the rectangle:</p>
11. <div id="div1" style="width:350px;height:100px;padding:10px;border:1px solid #aaaaaa;
"
12. ondrop="drop(event)" ondragover="allowDrop(event)"></div>
13. <br>
14. <img id="drag1" src="/htmlpages/images/javatpoint.png" alt="javatpoint image"
15. draggable="true" ondragstart="drag(event)"/>
In the above example, we have used ondrop and ondragover events on div element,
and ondragstart event on img tag.
Test it Now
Output:
If you want to make an element draggable, set the draggable attribute to "true" on the
element. For example:
165
2) What to drag:
3) Where to Drop:
4) Do the Drop:
166