HTML
HTML
1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>Web page title</title>
5. </head>
6. <body>
7. <h1>Write Your First Heading</h1>
8. <p>Write Your First Paragraph.</p>
9. </body>
10. </html>
Test it Now
HTML Index
HTML Tutorial
o Introduction to HTML
o What is HTML
o HTML tags
o HTML Formatting
o HTML Heading
o HTML Paragraph
o HTML Anchor
o HTML Image
o HTML Table
o HTML Lists
o HTML Ordered List
o HTML Unordered List
o HTML Description List
o HTML Form
o HTML Classes
o HTML Id
o HTML Iframes
o HTML JavaScript
o HTML File Path
o HTML Head
o HTML Layout
o HTML Responsive
o HTML Computercode
o HTML Entities
o HTML Symbols
o HTML Charset
o HTML URL Encode
HTML Tags
o HTML Marquee
o HTML Textarea
o HTML Quotes
o HTML Style
o HTML Title
o HTML DOCTYPE
o HTML Div Tag
o HTML Pre Tag
o HTML Code Tag
o HTML Label Tag
o HTML Input Tag
o HTML Button Tag
o HTML HR Tag
o HTML BR Tag
o HTML Script Tag
o HTML NoScript Tag
o HTML b Tag
HTML5 Tutorial
o HTML5 tutorial
o HTML5 User Manual
o HTML 5 Tags
o HTML Audio
o HTML Video
o HTML Progress
o HTML Meter
o HTML Data Tag
o HTML Datalist Tag
o HTML Header Tag
o HTML Footer Tag
o HTML Figure Tag
o HTML Figcaption Tag
o HTML Article Tag
o HTML Aside Tag
o HTML Dialog Tag
o HTML Details Tag
o HTML Summary Tag
o HTML Section Tag
o HTML Time Tag
o HTML Main Tag
o HTML Wbr Tag
o HTML Canvas
o HTML SVG
o HTML Drag & Drop
o HTML Google Maps
o HTML5 Semantics
o HTML5 Migration
Interview Questions
Prerequisite
Before learning HTML, you must have the basic knowledge of Computer
Fundamental.
Audience
Our HTML tutorial is designed to help beginners and professionals both.
Problem
We assure, you will not find any problem in HTML tutorial. But, if you find
any problem or mistake in our HTML tutorial, you can report to us.
What is HTML
HTML is an acronym which stands for Hyper Text Markup
Language which is used for creating web pages and web applications.
Let's see what is meant by Hypertext Markup Language, and Web page.
Hyper Text: HyperText simply means "Text within Text." A text has a link
within it, is a hypertext. Whenever you click on a link which brings you to
a new webpage, you have clicked on a hypertext. HyperText is a way to
link two or more web pages (HTML documents) with each other.
1. <!DOCTYPE>
2. <html>
3. <head>
4. <title>Web page title</title>
5. </head>
6. <body>
7. <h1>Write Your First Heading</h1>
8. <p>Write Your First Paragraph.</p>
9. </body>
10.</html>
Test it Now
<html > :This tag informs the browser that it is an HTML document. Text
between html tag describes the web document. It is a container for all
other elements of HTML except <!DOCTYPE>
<head>: It should be the first element inside the <html> element, which
contains the metadata(information about the document). It must be
closed before the body tag opens.
<title>: As its name suggested, it is used to add title of that HTML page
which appears at the top of the browser window. It must be placed inside
the head tag and should close immediately. (Optional)
ADVERTISEMENT
<body> : Text between body tag describes the body content of the page
that is visible to the end user. This tag contains the main content of the
HTML document.
<h1> : Text between <h1> tag describes the first level heading of the
webpage.
<p> : Text between <p> tag describes the paragraph of the webpage.
HTML Versions
Since the time HTML was invented there are lots of HTML versions in
market, the brief introduction about the HTML version is given below:
HTML 1.0: The first version of HTML was 1.0, which was the barebones
version of HTML language, and it was released in1991.
HTML 2.0: This was the next version which was released in 1995, and it
was standard language version for website design. HTML 2.0 was able to
support extra features such as form-based file upload, form elements such
as text box, option button, etc.
HTML 3.2: HTML 3.2 version was published by W3C in early 1997. This
version was capable of creating tables and providing support for extra
options for form elements. It can also support a web page with complex
mathematical equations. It became an official standard for any browser till
January 1997. Today it is practically supported by most of the browsers.
HTML 4.01: HTML 4.01 version was released on December 1999, and it is
a very stable version of HTML language. This version is the current official
standard, and it provides added support for stylesheets (CSS) and
scripting ability for various multimedia elements.
HTML5 : HTML5 is the newest version of HyperText Markup language.
The first draft of this version was announced in January 2008. There are
two major organizations one is W3C (World Wide Web Consortium), and
another one is WHATWG( Web Hypertext Application Technology Working
Group) which are involved in the development of HTML 5 version, and still,
it is under development.
Features of HTML
1) It is a very easy and simple language. It can be easily understood
and modified.
ADVERTISEMENT
To run the HTML page, you need to open the file location, where you have
saved the file and then either double-click on file or click on open with
option
B. HTML code with Sublime Text-editor.(Recommended after
learning basics of HTML)
When you will learn the basics of HTML, then you can use some
professional text editors, which will help you to write an efficient and fast
code. So to use Sublime Text editors, first it needs to download and install
from internet. You can easily download it from
this [Link] link and can install in your PC.
When installation of Sublime text editor done then you can follow the
simple steps to use it:
To execute or open this page in Web browser just right click by mouse
on sublime text page and click on Open in Browser.
Note: You can execute HTML file in any browser, but there are some tags which
are not supported by Some Web browser.
ADVERTISEMENT
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>
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>The basic building blocks of HTML</title>
5. </head>
6. <body>
7. <h2>The building blocks</h2>
8. <p>This is a paragraph tag</p>
9. <p style="color: red">The style is attribute of paragraph tag</
p>
10. <span>The element contains tag, attribute and content<
/span>
11. </body>
12. </html>
Test it Now
Output:
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>
Test it Now
<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.
A
<a> It is termed as anchor tag and it creates a hyperlink or link.
<aside> It defines content aside from main content. Mainly represented as sidebar.
B
<b> It is used to make a text bold.
<base> This tag defines the base URL for all relative URL within the document.
<basefont> This tag is used to set default font, size and color for all elements
document. (Not supported in HTML5)
<bdi> This tag is used to provide isolation for that part of text which may be formatt
in different directions from its surrounding text.
<big> This tag is used to make font size one level larger than its surroundi
content. (Not supported in HTML5)
C
<canvas> It is used to provide a graphics space within a web document.
<cite> It is used to define the title of the work, book, website, etc.
D
<data> It is used to link the content with the machine-readable translation.
<del> It defines a text which has been deleted from the document.
<details> It defines additional details which user can either view or hide.
<dir> It is used as container for directory list of files. (Not supported in HTML5)
E
<em> It is used to emphasis the content applied within this element.
F
<fieldset> It is used to group related elements/labels within a web form.
<figure> It is used to define the self-contained content, and s mostly refer as single unit
<font> It defines the font, size, color, and face for the content. (Not supported
HTML5)
<footer> It defines the footer section of a webpage.
H
<h1> to It defines headings for an HTML document from level 1 to level 6.
<h6>
I
<i> It is used to represent a text in some different voice.
<ins> It represent text that has been inserted within an HTML document.
<isindex> It is used to display search string for current document. (Not supported
HTML5)
K
<kbd> It is used to define keyboard input.
L
<label> It defines a text label for the input field of form.
M
<main> It represents the main content of an HTML document.
N
<nav> It represents section of page to represent navigation links.
<noframes> It provides alternate content to represent in browser which does not support t
<frame> elements. (Not supported in HTML5)
P
<p> It represents a paragraph in an HTML document.
<picture> It defines more than one source element and one image element.
Q
<q> It defines short inline quotation.
R
<rp> It defines an alternative content if browser does not supports ruby annotations
<small> It is used to make text font one size smaller than document?s base font size.
<source>> It defines multiple media recourses for different media element such
<picture>, <video>, and <audio> element.
<strike> It is used to render strike through the text. (Not supported in HTML5)
T
<table> It is used to present data in tabular form or to create a table within HT
document.
<tbody> It represents the body content of an HTML table and used along with <thea
and <tfoot>.
<td> It is used to define cells of an HTML table which contains table data
<template> It is used to contain the client side content which will not display at time of pa
load and may render later using JavaScript.
<textarea> It is used to define multiple line input, such as comment, feedback, and revie
etc.
<thead> It defines the header of an HTML table. It is used along with <tbody> a
<tfoot> tags.
<track> It is used to define text tracks for <audio> and <video> elements.
U
<u> It is used to render enclosed text with an underline.
V
<var> It defines variable name used in mathematical or programming context.
<video> It is used to embed a video content with an HTML document
W
<wbr> It defines a position within text where break line is possible.
HTML Attribute
ADVERTISEMENT
Syntax
1. <element attribute_name="value">content</element>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h1> This is Style attribute</h1>
7. <p style="height: 50px; color: blue">It will add style property in e
lement</p>
8. <p style="color: red">It will change the color of content</p>
9. </body>
10.</html>
Test it Now
Output:
1. <p style="height: 50px; color: blue">It will add style property in ele
ment</p>
Test it Now
Note: There are some commonly used attributes are given below, and the
complete list and explanation of all attributes are given in HTML attributes List.
Example
With <h1> tag:
Code:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6.
7. <h1 title="This is heading tag">Example of title attribute</h1>
8. <p title="This is paragraph tag">Move the cursor over the heading and
paragraph, and you will see a description as a tooltip</p>
9.
10.</body>
11. </html>
Test it Now
Output:
The href attribute in HTML
Description: The href attribute is the main attribute of <a> anchor tag.
This attribute gives the link address which is specified in that link. The
href attribute provides the hyperlink, and if it is blank, then it will
remain in same page.
Example
With link address:
Example
1. <img src="[Link]" height="400" width="600">
Test it Now
Note: The above example also have height and width attribute, which define the
height and width of image on web page.
Output:
Quotes: single quotes or double quotes?
In this chapter you have seen that, we have used attribute with double
quotes, but some people might use single quotes in HTML. So use of
single quotes with HTML attribute, is also allowed. The following both
statements are absolutely fine.
IN HTML5, you can also omit use of quotes around attribute values.
HTML Elements
An HTML file is made of elements. These elements are responsible for
creating web pages and define content in that webpage. An element in
HTML usually consist of a start tag <tag name>, close tag </tag name>
and content inserted between them. Technically, an element is a
collection of start tag, attributes, end tag, content between them.
Note: Some elements does not have end tag and content, these elements are
termed as empty elements or self-closing element or void elements.
Such as:
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>WebPage</title>
5. </head>
6. <body>
7. <h1>This is my first web page</h1>
8. <h2> How it looks?</h2>
9. <p>It looks Nice!!!!!</p>
10.</body>
11. </html>
Test it
Now
o All the content written between body elements are visible on web page.
Void element: All the elements in HTML do not require to have start tag
and end tag, some elements does not have content and end tag such
elements are known as Void elements or empty elements. These
elements are also called as unpaired tag.
o Block-level element
o Inline element
Block-level element:
o These are the elements, which structure main part of web page, by
dividing a page into coherent blocks.
o A block-level element always start with new line and takes the full width of
web page, from left to right.
o These elements can contain block-level as well as inline elements.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <div style="background-color: lightblue">This is first div</div>
7. <div style="background-color: lightgreen">This is second div</
div>
8. <p style="background-color: pink">This is a block level element</p>
9. </body>
10.</html>
Test it Now
Output:
tag, which defines a section in a web page, and takes full width of page.
We have used style attribute which is used to styling the HTML content,
and the background color are showing that it's a block level element.
Inline elements:
o Inline elements are those elements, which differentiate the part of a given
text and provide it a particular function.
o These elements does not start with new line and take width as per
requirement.
o The Inline elements are mostly used with other elements.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <a href="[Link] on link</a>
7. <span style="background-color: lightblue">this is inline elemen
t</span>
8. <p>This will take width of text only</p>
9. </body>
10.</html>
Test it Now
Output:
<h1> ...... These are headings </h1>??..</ These elements are used to provide t
<h6> of HTML h6> headings of page.
<div> This is div section </div> This element is used to provide a section
web page.
<br> This element is used to provide a li
break. ( void element)
HTML Formatting
HTML Formatting is a process of formatting text for better look and feel.
HTML provides us ability to format text without using CSS. There are many
formatting tags in HTML. These tags are used to make text bold, italicized,
or underlined. There are almost 14 options available that how text
appears in HTML and XHTML.
o Physical tag: These tags are used to provide the visual appearance to the
text.
o Logical tag: These tags are used to add some logical or semantic value to
the text.
NOTE: There are some physical and logical tags which may give same visual
appearance, but they will be different in semantics.
Here, we are going to learn 14 HTML formatting tags. Following is the list
of HTML formatting text.
<b> This is a physical tag, which is used to bold the text written between it.
<strong> This is a logical tag, which tells the browser that the text is important.
<strike> This tag is used to draw a strikethrough on a section of text. (Not supported
HTML5)
<big> This tag is used to increase the font size by one conventional unit.
<small> This tag is used to decrease the font size by one unit from base font size.
1) Bold Text
HTML<b> and <strong> formatting elements
The HTML <b> element is a physical tag which display text in bold font,
without any logical importance. If you write anything within
<b>............</b> element, is shown in bold letters.
Output:
The HTML <strong> tag is a logical tag, which displays the content in bold
font and informs the browser about its logical importance. If you write
anything between <strong>???????. </strong>, is shown important text.
Output:
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of formatting element</h1>
8. <p><strong>This is an important content</strong>, and this is normal
content</p>
9. </body>
10.</html>
Test it Now
2) Italic Text
HTML <i> and <em> formatting elements
The HTML <i> element is physical element, which display the enclosed
content in italic font, without any added importance. If you write anything
within <i>............</i> element, is shown in italic letters.
Output:
The HTML <em> tag is a logical element, which will display the enclosed
content in italic font, with added semantics importance.
Output:
ADVERTISEMENT
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of italic formatting element</h1>
8. <p><em>This is an important content</em>, which displayed in italic fo
nt.</p>
9. </body>
10.</html>
Test it Now
Output:
ADVERTISEMENT
4) Underlined Text
If you write anything within <u>.........</u> element, is shown in
underlined text.
Output:
5) Strike Text
Anything written within <strike>.......................</strike> element is
displayed with strikethrough. It is a thin line which cross the statement.
Output:
6) Monospaced Font
If you want that each letter has the same width then you should write the
content within <tt>.............</tt> element.
Note: We know that most of the fonts are known as variable-width fonts
because different letters have different width. (for example: 'w' is wider
than 'i'). Monospaced Font provides similar space among every letter.
7) Superscript Text
If you put the content within <sup>..............</sup> element, is shown in
superscript; means it is displayed half a character's height above the
other characters.
Output:
8) Subscript Text
If you put the content within <sub>..............</sub> element, is shown in
subscript ; means it is displayed half a character's height below the other
characters.
ADVERTISEMENT
Output:
9) Deleted Text
Anything that puts within <del>..........</del> is displayed as deleted text.
See this example:
Output:
Hello
ADVERTISEMENT
Output:
Output:
Output:
HTML Heading
A HTML heading or HTML h tag can be defined as a title or a subtitle which
you want to display on the webpage. When you place the text within the
heading tags <h1>.........</h1>, it is displayed on the browser in the bold
format and size of the text depends on the number of heading.
There are six different HTML headings which are defined with the <h1> to
<h6> tags, from highest level h1 (main heading) to the least level h6
(least important heading).
h1 is the largest heading tag and h6 is the smallest one. So h1 is used for
most important heading and h6 is used for least important.
ADVERTISEMENT
Note: The main keyword of the whole content of a webpage should be display by
h1 heading tag.
Output:
Heading no. 1
Heading no. 2
Heading no. 3
Heading no. 4
Heading no. 5
Heading no. 6
Heading elements (h1....h6) should be used for headings only. They should not be
used just to make text bold or big.
o HTML headings can also be used with nested elements. Following
are different codes to display the way to use heading elements.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Heading elements</title>
5. </head>
6. <body>
7. <h1>This is main heading of page. </h1>
8. <p>h1 is the most important heading, which is used to display the key
word of page </p>
9. <h2>This is first sub-heading</h2>
10. <p>h2 describes the first sub heading of page. </p>
11. <h3>This is Second sub-heading</h3>
12. <p>h3 describes the second sub heading of page.</p>
13. <p>We can use h1 to h6 tag to use the different sub-
heading with their paragraphs if
14. required.
15. </p>
16. </body>
17. </html>
Output:
Supporting Browsers
HTML Paragraph
HTML paragraph or HTML p tag is used to define a paragraph in a
webpage. Let's take a simple example to see how it work. It is a notable
point that a browser itself add an empty line before and after a paragraph.
An HTML <p> tag indicates starting of new paragraph.
Note: If we are using various <p> tags in one HTML file then browser
automatically adds a single blank line between the two paragraphs.
Output:
1. <p>
2. I am
3. going to provide
4. you a tutorial on HTML
5. and hope that it will
6. be very beneficial for you.
7. </p>
8. <p>
9. Look, I put here a lot
[Link] spaces but I know, Browser will ignore it.
11. </p>
12.<p>
13. You cannot determine the display of HTML</p>
14.<p>because resized windows may create different result.
15. </p>
Test it Now
Output:
I am going to provide you a tutorial on HTML and hope that it will be very
beneficial for you.
Look, I put here a lot of spaces but I know, Browser will ignore it.
As you can see, all the extra lines and unnecessary spaces are removed
by the browser.
How to Use <br> and <hr> tag with paragraph?
An HTML <br> tag is used for line break and it can be used with
paragraph elements. Following is the example to show how to use <br>
with <p> element.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h2> Use of line break with pragraph tag</h2>
7. <p><br>Papa and mama, and baby and Dot,
8. <br>Willie and me?the whole of the lot
9. <br>Of us all went over in Bimberlie's sleigh,
10. <br>To grandmama's house on Christmas day.
11. </p>
12. </body>
13. </html>
Test it Now
Output:
An HTML <hr> tag is used to apply a horizontal line between two
statements or two paragraphs. Following is the example which is showing
use of <hr> tag with paragraph.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h2> Example to show a horizontal line with paragraphs</h2>
7. <p> An HTML hr tag draw a horizontal line and separate two par
agraphs with that line.<hr> it will start a new paragraph.
8. </p>
9. </body>
10.</html>
Test it Now
Output:
Supporting Browsers
Example
1. <p>An <abbr title = "Hypertext Markup language">HTML </
abbr>language is used to create web pages. </p>
Test it Now
Output:
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>
Test it Now
Output:
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>
Test it Now
Output:
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.
ADVERTISEMENT
Example
1. <p>HTML is an <em>easy </em>to learn language.</p>
Test it Now
Output:
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>
Test it Now
Output:
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="[Link]
quotes/"><p>?The first step toward success is taken when you refu
se to be a captive of the environment in which you first find yourself
.?</p></blockquote>
2. <cite>-Mark Caine</cite>
Test it Now
Output:
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 Y
ou.</q>?</p>
Test it Now
Output:
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.
Output:
9. Keyboard Tag
In HTML the keyboard tag, <kbd>, indicates that a section of content is a
user input from keyboard.
Output:
Output:
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="[Link] targe
t="_blank"> this-link </a>to go on home page of JavaTpoint.</p>
8. </body>
9. </html>
Test it Now
Output:
Note:
ADVERTISEMENT
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.
Supporting Browsers
Output:
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="[Link]" height="180" width="300" alt="animal ima
ge">
Test it Now
Output:
Note: Always try to insert the image with height and width, else it may flicker while
displaying on webpage.
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:
Output:
Example:
1. <a href="[Link] sr
c="[Link]" height="100" width="100"></a>
Test it Now
Output:
Supporting Browsers
HTML Table
HTML table tag is used to display data in tabular form (row * column).
There can be many columns in a row.
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 .
Tag Description
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>
Test it Now
Output:
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>
Test it Now
Output:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. }
5. </style>
Test it Now
1. <style>
2. table, th, td {
3. border: 2px solid black;
4. border-collapse: collapse;
5. }
6. </style>
Test it Now
Output:
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>
Test it Now
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
HTML Table width:
We can specify the HTML table width using the CSS width property. It
can be specify in pixels or percentage.
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>
Test it Now
Output:
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>
Test it Now
Output:
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>
Test it Now
Output:
7503520801
Mobile No.
9555879135
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>
Test it Now
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>
Test it Now
Output:
NOTE: You can also create various types of tables using different CSS properties in
your table.
Supporting Browsers
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>
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>john123@[Link]</td>
26. </tr>
27.
28. <tr>
29. <td>122</td>
30. <td>William </td>
31. <td>william56@[Link]</td>
32. </tr>
33.
34. <tr>
35. <td>123</td>
36. <td>Amit</td>
37. <td>amitk98@[Link]</td>
38. </tr>
39. </tbody>
40.</table>
41. </body>
42.</html>
Test it Now
Output:
Attribute:
Tag-specific attributes:
Attribute Value Description
align right It determines the alignment of the content inside the <tbod
left element. (Not Supported in HTML5)
center
justify
char
char charact It specifies the alignment of the <tbody> content to the character. (N
er Supported in HTML5)
charoff Number It specifies the number of characters the content will be aligned from t
character specified by the char attribute. (Not Supported in HTML5)
valign top It determines the vertical alignment of the content inside the <tbod
middle element. (Not Supported in HTML5)
bottom
baselin
e
Global attribute:
The <tbody> tag supports the Global attributes in HTML.
Event attribute:
The <tbody> tag supports the Event attributes in HTML.
Supporting Browsers
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>
Test it Now
Output:
<td> tag width attribute: The <td> tag width attribute is used to fix
the width of a particular column. With this, we can assign a numeric value
to this attribute or in terms of percentage.
Example 1
1. <! DOCTYPE html>
2. <html>
3. <head>
4. <title> HTML td tag with fixed width </title>
5. <meta charset = "UTF-8" />
6. <meta name = "viewport" content = "width=device-width,
7. initial-scale = 1.0" />
8. <style>
9. @import url([Link]
10. body {
11. text-transform: uppercase;
12. text-align: center;
13. white-space: nowrap;
14. color: #fff;
15. background-color: #E1332D;
16.}
17. [Link] {
18. margin-left: auto;
19. margin-right: auto;
20.}
21. th {
22. background-color: #6495ed;
23. }
24. th,td {
25. border: 1px solid red;
26. padding: 10px;
27. }
[Link] {
29. display: table-header-group;
[Link]: green;
31. font-weight: bold;
32.}
33. h2 {
34. text-align: center;
35. font-weight: normal;
36. color: #fff;
37. text-transform: uppercase;
38. font-size: 1em;
39. white-space: nowrap;
40. font-size: 4vw;
41. z-index: 1000;
42. font-family: 'Bangers', cursive;
43. text-shadow: 5px 5px 0 rgba(0, 0, 0, 0.7);
44. @include skew(0, -6.7deg, false);
45. @include transition-property(font-size);
46. @include transition-duration(0.5s);
47.
48.}
49. thead {
50. border-top: 1px solid #ccc;
51. padding:10px;
52. width: 120px;
53. background-color: #004496;
54. color: #fff;
55. font-family: arial;
56. font-size: 12px;
57.
58. }
59. td {
60. border-top: 1px solid #ccc;
61. padding:10px;
62. width: 120px;
63. background-color: #004496;
64. color: #fff;
65. font-family: arial;
66. font-size: 12px;
67.
68. }
69. th {
70. border-top: 1px solid #ccc;
71. padding:10px;
72. width: 120px;
73. background-color: #004496;
74. color: #fff;
75. font-family: arial;
76. font-size: 12px;
77.
78. }
79. h3 {
80. text-align: center;
81. font-weight: normal;
82. color: #fff;
83. text-transform: uppercase;
84. font-size: 1em;
85. white-space: nowrap;
86. font-size: 3vw;
87. z-index: 1000;
88. font-family: 'Bangers', cursive;
89. text-shadow: 5px 5px 0 rgba(0, 0, 0, 0.7);
90. @include skew(0, -6.7deg, false);
91. @include transition-property(font-size);
92. @include transition-duration(0.5s);
93.
94.}
95. </style>
96.</head>
97. <body>
98. <h2> Example </h2>
99. <h3> Fixed column width using td Tag </h3>
100. <table class = "center" style = " border-collapse: collapse; backgr
ound-color:#dcdcdc;">
101. <thead>
102. <tr>
103. <td width = "10%" style = "color:red;"> Sr. No </td>
104. <td width = "40%"> Product </td>
105. <td width = "20%"> Quantity </td>
106. <td width = "30%"> Price </td>
107. </tr>
108. </thead>
109.
110. <tr>
111. <td style = "color:red;"> 1 </td>
112. <td> Books </td>
113. <td> 5 </td>
114. <td> 589 </td>
115. </tr>
116.
117. <tr>
118. <td style = "color:red;"> 2 </td>
119. <td> T-shirt </td>
120. <td> 5 </td>
121. <td> 3500 </td>
122. </tr>
123. <tr>
124. <td style = "color:red;"> 3 </td>
125. <td> Jeans </td>
126. <td> 2 </td>
127. <td> 5000 </td>
128. </tr>
129. <tr>
130. <td style = "color:red;"> 4 </td>
131. <td> Suits </td>
132. <td> 3 </td>
133. <td> 6000 </td>
134. </tr>
135.
136. </table>
137. </body>
138. </html>
Explanation:
Output:
Explanation:
Output:
Example 1:
1. <! DOCTYPE html>
2. <html>
3. <head>
4. <title> Html fixed width using col tag </title>
5. <meta charset = "UTF-8" />
6. <meta name = "viewport"
7. content = "width=device-width,
8. initial-scale = 1.0" />
9. <style>
10. @import url([Link]
11. body {
12. text-transform: uppercase;
13. text-align: center;
14. white-space: nowrap;
15. color: #fff;
16. background-color: #E1332D;
17. }
[Link] {
19. border: 1px solid black;
20. border-collapse: collapse;
21. margin-left: auto;
22. margin-right: auto;
23. }
[Link] {
25. border: 1px solid black;
26. border-collapse: collapse;
27. margin-left: auto;
28. margin-right: auto;
29. }
[Link] {
31. border: 1px solid black;
32. border-collapse: collapse;
33. margin-left: auto;
34. margin-right: auto;
35. }
36.
37. table {
38. width: 50%;
39. }
40. [Link] {
41. table-layout: fixed;
42. }
43. [Link] td {
44. overflow: hidden;
45. }
46. thead {
47. display: table-header-group;
[Link]: green;
49. font-weight: bold;
50.}
51. h2 {
52. text-align: center;
53. font-weight: normal;
54. color: #fff;
55. text-transform: uppercase;
56. font-size: 1em;
57. white-space: nowrap;
58. font-size: 4vw;
59. z-index: 1000;
60. font-family: 'Bangers', cursive;
61. text-shadow: 5px 5px 0 rgba(0, 0, 0, 0.7);
62. @include skew(0, -6.7deg, false);
63. @include transition-property(font-size);
64. @include transition-duration(0.5s);
65.
66.}
67. thead {
68. border-top: 1px solid #ccc;
69. padding:10px;
70. width: 120px;
71. background-color: #004496;
72. color: #fff;
73. font-family: arial;
74. font-size: 12px;
75.
76. }
77. td {
78. border-top: 1px solid #ccc;
79. padding:10px;
80. width: 120px;
81. background-color: #004496;
82. color: #fff;
83. font-family: arial;
84. font-size: 12px;
85.
86. }
87. th {
88. border-top: 1px solid #ccc;
89. padding:10px;
90. width: 120px;
91. background-color: #004496;
92. color: #fff;
93. font-family: arial;
94. font-size: 12px;
95.
96. }
97. h3 {
98. text-align: center;
99. font-weight: normal;
100. color: #fff;
101. text-transform: uppercase;
102. font-size: 1em;
103. white-space: nowrap;
104. font-size: 3vw;
105. z-index: 1000;
106. font-family: 'Bangers', cursive;
107. text-shadow: 5px 5px 0 rgba(0, 0, 0, 0.7);
108. @include skew(0, -6.7deg, false);
109. @include transition-property(font-size);
110. @include transition-duration(0.5s);
111.
112. }
113. </style>
114. </head>
115. <body>
116. <h2> Example </h2>
117. <h3> Fixed column width using col Tag </h3>
118. <div style = "overflow-x: auto;">
119. <table>
120. <col style = "width: 10%;" />
121. <col style = "width: 40%;" />
122. <col style = "width: 20%;" />
123. <col style = "width: 30%;" />
124. <tr>
125. <th> Sr. No </th>
126. <th> Product </th>
127. <th> Quantity </th>
128. <th> Price </th>
129. </tr>
130. <tr>
131. <td style = "color:red;"> 1 </td>
132. <td> Books </td>
133. <td> 5 </td>
134. <td> 589 </td>
135. </tr>
136. <tr>
137. <td style = "color:red;"> 2 </td>
138. <td> T-shirt </td>
139. <td> 5 </td>
140.
141. <td> 3500 </td>
142. </tr>
143. <tr>
144. <td style = "color:red;"> 3 </td>
145. <td> Jeans </td>
146. <td> 2 </td>
147. <td> 5000 </td>
148. </tr>
149. <tr>
150. <td style = "color:red;"> 4 </td>
151. <td> Suits </td>
152. <td> 3 </td>
153. <td> 6000 </td>
154. </tr>
155. </table>
156. </div>
157. </body>
158. </html>
Explanation:
ADVERTISEMENT
Attribute:
Tag-specific attributes:
Attribute Value Description
bgcolor rgb(x,x,x) It sets the background color of the cell. (Not Supported
#xxxxxx HTML5)
Color_name
char character It specifies the alignment of the content of cell to t
character. (Not Supported in HTML5)
charoff number It determines the number of characters the content aligned from t
character specified by the char attribute. (Not Supported
HTML5)
headers header_id It determines one or more header cells to which a cell is related.
nowrap nowrap If it sets then content inside the cell should not wrap. (N
Supported in HTML5)
scope col It specifies the cells that the header element relates to. (N
colgroup 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.
Supporting Browsers
In this article, we'll learn about HTML template tags, how to use them, and
their advantages and disadvantages.
It can also be helpful if we want to reuse the same material in our HTML
document repeatedly without making any changes.
ADVERTISEMENT
Syntax:
1. <template>.........</template>
When choosing a website template, make sure it already has the features,
scripts, and apps we need for our web development project because web
template styles and code differ greatly from vendor to vendor. The pre-
made pages may be customized by adding text, stock images, scripts, and
third-party plugins. The provided stock photos can be altered or swapped
out with the user's [Link] files as needed for the project.
First of all, even though it typically requires a correct surrounding tag, its
content can be any acceptable HTML.
1. <template>
2. <tr>
3. <td>Contents</td>
4. </tr>
5. </template>
An Example for Template
1. <!DOCTYPE html>
2. <html>
3. <body>
4.
5. <h1>Template Element Example</h1>
6.
7. <p>To view the template element's concealed content, click the bu
tton below.</p>
8.
9. <button onclick="showContent()">show content</button>
10.
11. <template>
12. <h2>Flower</h2>
13. <img src="C:\Users\Maram Ujwala\Pictures\Saved Pictures\
Images\Flower [Link]" width="60" height="40">
14.</template>
15.
16.<script>
17. function showContent() {
18. let temp = [Link]("template")[0];
19. let clon = [Link](true);
20. [Link](clon);
21. }
22.</script>
23.
24.</body>
25. </html>
Output:
Output:
Let's deconstruct it:
1. Line 1: This special tag, which appears at the beginning of the page and
specifies the kind of code being used, is used to identify the type of code.
2. The HTML page is opened and closed by the HTML tags on lines 2 and
12. The paper includes all of its contents.
3. The head tags on lines 3 and 7 specify where the document's head will
appear. Items below are supplemental information that goes with the
paper.
4. The title tag in line 4 specifies the document's title. It will be shown at the
very top of the browser window.
5. The meta tags on lines 5 and 6 are used to describe the document.
6. The body tags on lines 9 and 11 enclose the document's actual content.
The Doctype
This tag should always be the first one on a page. It ought to be placed
just before the html tag at the top. You'll see that this tag starts with an
exclamation point (!) as opposed to the other tags.
1. <!doctype html>
The Head
1. <head> </head>
Ancillary data is placed in the HTML document's head section. While not a
part of the text, this information relates to it. There are several things.
The Title
We may give the document a title by using the title tag. This is employed
several times:
Meta Tags
1. <meta name="description" value=" ">
2. <meta name="keywords" value=" ">
The two meta tags for the description and keywords follow in the head.
These can be utilized by other systems (like when your page is linked to
social networking and other sharing sites) and are used by search engines
(to varying degrees).
The keywords meta tag is used to offer a list of terms that would fit the
subject matter of the page. Previously, search engines gave this feature of
your page some weight, but because of misuse, it currently carries very
little weight. However, you should still include it for completeness' sake
and also because you could get black-listed by some search engines if you
don't include it. They argue that the quality of your page will be lower if
you are lazy and can't be bothered to include this tag since you are likely
to be lazy in other areas as well.
The Body
1. <body> < /body>
The actual content of your page goes here. All of this stuff would typically
be included in tags that describe the sort of content it is. To keep things
simple, we omitted this form from the previous example. We'll begin
demonstrating the many types of tags that may be applied in the next
section.
Summary to Sum Up
Any syntactically sound HTML can be used as <template> content.
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:
Supporting Browsers
Attribute Description
autofocus It specifies that a text area should be automatically get focused when t
page is loaded.
maxlengt It specifies the maximum number of characters allowed in the text area.
h
placehold It specifies a short hint that describes the expected value of a textarea.
er
wrap It specifies that how the texts in the textarea are wrapped at the time
the submission of the form.
Output:
Name:
The textarea element above is outside the form , but it is still the part of
the form.
Note: The form attribute is not supported in Internet Explorer.
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
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>
Test it Now
Output:
Attribute:
Tag-specific attributes:
Attribute Value Description
align right It determines the alignment of the content inside the <tfoo
left element. (Not Supported in HTML5)
center
justify
char
char Charact It specifies the alignment of the content inside the <tfoot> element
er the character. (Not Supported in HTML5)
charoff Number It specifies the number of characters the content will be aligned from t
character specified by the char attribute. (Not Supported in HTML5)
valign top It determines the vertical alignment of the content inside the <tfoo
middle element. (Not Supported in HTML5)
bottom
baseline
Global attribute:
The <tfoot> tag supports the Global attributes in HTML.
Event attribute:
The <tfoot> tag supports the Event attributes in HTML.
ADVERTISEMENT
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>
Test it Now
Output:
Attribute:
Tag-specific attributes:
Attribute Value Description
abbr text It defines the abbreviated version of content of the header cell. (N
Supported in HTML5)
align left It specifies the alignment of the content of the header cell. (N
right Supported in HTML5)
center
justify
char
char character It specifies the alignment of the content of the header cell to t
character. (Not Supported in HTML5)
charoff number It specifies the number of characters the header cell content will
aligned from the character specified by the char attribute. (N
Supported in HTML5)
colspan number It determines the number of columns a header cell should span.
nowrap nowrap If it sets then content inside the header cell should not wrap. (N
Supported in HTML5)
scope col It specifies the cells that the header element relates to. (N
colgroup 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.
HTML <thead> tag
HTML <thead> elements is used to define header of an HTML table. The
<thead> tag is used along with <tbody> and <tfoot> tags which defines
table header, table body, and table footer in an HTML table.
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>
Test it Now
Output:
Attribute:
Tag-specific attributes:
Attribute Value Description
align right It determines the alignment of the content inside the <thea
left element. (Not Supported in HTML5)
center
justify
char
char Charact It specifies the alignment of the content inside the <thead> element
er the character. (Not Supported in HTML5)
charoff Number It specifies the number of characters the content that will be aligned fro
the character specified by the char attribute. (Not Supported
HTML5)
valign top It determines the vertical alignment of the content inside the <thea
middle element. (Not 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.
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.
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>
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>
Test it Now
Here you see that we are using two elements, the head tag and the title
tag. The whole title element is within the head tag.
The head element which appears before body element just contains the
information about the page but it doesn't display on the browser window.
So, to display a title name on the web page, title element is used.
If you look at the above example, you will see that "First web page" will be
displayed on the tab/ title bar of the browser. Content(text) between
<title>.............</title> is shown on the title bar.
Syntax
1. <tr>.......</tr>
Display Inline
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML tr tag</title>
5. <style>
6. table{
7. border-collapse: collapse;
8. margin-left: 350px;
9. }
10. th,td{
11. padding: 25px;}
12. th{
13. background-color: #005cb9;}
14. td{
15. background-color:#98f5ff;}
16. </style>
17. </head>
18.<body>
19. <h2>Example of tr tag</h2>
20. <table border="1">
21. <caption><b>Top Three performers of Winter Olympic Me
dals</b></caption>
22. <tr>
23. <th>Rank</th>
24. <th>Country</th>
25. <th>Total medals</th>
26. </tr>
27. <tr>
28. <td>1</td>
29. <td>Norway</td>
30. <td>329</td>
31. </tr>
32. <tr>
33. <td>2</td>
34. <td>United State</td>
35. <td>282</td>
36. </tr>
37. <tr>
38. <td>3</td>
39. <td>Germany</td>
40. <td>228</td>
41. </tr>
42. </table>
43. </body>
44.</html>
Test it Now
Output:
Attribute:
Tag-specific attributes:
Attribute Value Description
align right It determines the alignment of the content in the table row. (N
left Supported in HTML5)
center
justify
char
bgcolor rgb(x,x,x) It defines the background color of the table row. (Not Supported
#xxxxx HTML5)
color_na
me
char character It specifies the alignment of content to the character. (Not Support
in HTML5)
charoff number It specifies the number of character the table row content will
aligned from the character, and which is specified by ch
attribute. (Not Supported in HTML5)
valign Top It specifies the vertical alignment of the table row content. (N
Middle Supported in HTML5)
Bottom
baseline
Global attribute:
The <tr> tag supports the Global attributes in HTML.
Event attribute:
The <tr> tag supports the Event attributes in 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=" ">
Display None
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="[Link]" kind="subtitles" srclang="en" label="English">
In the above example, we have used [Link] file to add subtitle in the
video file. Following is the [Link] file:
Attribute:
Tag-specific attributes:
Attribute Value Description
default default It specifies that the track should be enabled unless the use
preferences indicate that another track is more important.
kind captions It specifies that which type of text track you want to add.
chapters
descriptions
metadata
subtitles
srclang language_co It defines the language of the track text content, such as Engli
de Germany, etc.
Global attribute:
The <track> tag supports the Global attributes in HTML.
Event attribute:
The <track> tag supports the Event attributes in HTML.
Syntax
Following are some specifications about the HTML <tt> tag
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>
Test it Now
Output:
Attribute:
Tag-specific attributes:
The <tt> tag does not contain any specific attribute.
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>
Test it Now
Output:
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.
o disc
o circle
o square
1. <dl>
2. <dt>HTML</dt>
3. <dd>is a markup language</dd>
4. <dt>Java</dt>
5. <dd>is a programming language and platform</dd>
6. <dt>JavaScript</dt>
7. <dd>is a scripting language</dd>
8. <dt>SQL</dt>
9. <dd>is a query language</dd>
10.</dl>
Test it Now
Output:
HTML
is a markup language
Java
is a programming language and platform
JavaScript
is a scripting language
SQL
is a query language
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. .
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>
Output:
HTML TextField Control
The type="text" attribute of input tag creates textfield control also known
as single line textfield control. The name attribute is optional, but it is
required for the server side component such as JSP, ASP, PHP etc.
1. <form>
2. First Name: <input type="text" name="firstname"/> <br/>
3. Last Name: <input type="text" name="lastname"/> <br/>
4. </form>
Output:
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>
Output:
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>
Output:
1. <form>
2. <label for="password">Password: </label>
3. <input type="password" id="password" name="password
"/> <br/>
4. </form>
Output:
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:
The radio button is used to select one option from multiple options. It is
used for selection of gender, quiz questions etc.
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="femal
e"/>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" valu
e="cricket"/>
4. <label for="cricket">Cricket</label> <br>
5. <input type="checkbox" id="football" name="football" val
ue="football"/>
6. <label for="football">Football</label> <br>
7. <input type="checkbox" id="hockey" name="hockey" val
ue="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.
Output:
Syntax:
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>
Output:
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>
[Link];/form>
Output:
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 <br/>
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>
Test it Now
Output:
1. <form action="#">
2. <table>
3. <tr>
4. <td class="tdLabel"><label for="register_name" class="label">Enter
name:</label></td>
5. <td><input type="text" name="name" value="" id="register_n
ame" style="width:160px"/></td>
6. </tr>
7. <tr>
8. <td class="tdLabel"><label for="register_password" class="label">En
ter password:</label></td>
9. <td><input type="password" name="password" id="register_p
assword" style="width:160px"/></td>
10.</tr>
11. <tr>
12. <td class="tdLabel"><label for="register_email" class="label">Enter
Email:</label></td>
13. <td
14.><input type="email" name="email" value="" id="register_email" style
="width:160px"/></td>
15. </tr>
16.<tr>
17. <td class="tdLabel"><label for="register_gender" class="
label">Enter Gender:</label></td>
18. <td>
19. <input type="radio" name="gender" id="register_gendermal
e" value="male"/>
20.<label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfem
ale" 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">Sele
ct 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="subm
it" id="register_0" value="register"/>
38.</div></td>
39. </tr>
40.</table>
41. </form>
button Defines a simple push button, which can be programmed to perform a task on
event.
datetime-local Defines an input field for entering a date without time zone.
month Defines a control with month and year, without time zone.
week Defines a field to enter the date with week-year, without time zone.
search Defines a single line text field for entering a search string.
1. <input type="text">:
<input> element of type "text" are used to define a single-line input text
field.
Example:
1. <form>
2. <label>Enter first name</label><br>
3. <input type="text" name="firstname"><br>
4. <label>Enter last name</label><br>
5. <input type="text" name="lastname"><br>
6. <p><strong>Note:</strong>The default maximum cahracter lenght i
s 20.</p>
7. </form>
Test it Now
Output:
2. <input type="password">:
The <input> element of type "password" allow a user to enter the
password securely in a webpage. The entered text in password filed
converted into "*" or ".", so that it cannot be read by another user.
Example:
1. <form>
2. <label>Enter User name</label><br>
3. <input type="text" name="firstname"><br>
4. <label>Enter Password</label><br>
5. <input type="Password" name="password"><br>
6. <br><input type="submit" value="submit">
7. </form>
Test it Now
Output:
Enter Password
3. <input type="submit">:
The <input> element of type "submit" defines a submit button to submit
the form to the server when the "click" event occurs.
Example:
1. <form action="[Link]
2. <label>Enter User name</label><br>
3. <input type="text" name="firstname"><br>
4. <label>Enter Password</label><br>
5. <input type="Password" name="password"><br>
6. <br><input type="submit" value="submit">
7. </form>
Test it Now
Output:
Enter Password
After clicking on submit button, this will submit the form to server and will
redirect the page to action [Link] will learn about "action" attribute in
later chapters
4. <input type="reset">:
The <input> type "reset" is also defined as a button but when the user
performs a click event, it by default reset the all inputted values.
Example:
1. <form>
2. <label>User id: </label>
3. <input type="text" name="user-id" value="user">
4. <label>Password: </label>
5. <input type="password" name="pass" value="pass"><br><br
>
6. <input type="submit" value="login">
7. <input type="reset" value="Reset">
8. </form>
Test it Now
Output:
Try to change the input values of user id and password, then when you
click on reset, it will reset input fields with default values.
5. <input type="radio">:
The <input> type "radio" defines the radio buttons, which allow choosing
an option between a set of related options. At a time only one radio
button option can be selected at a time.
Example:
1. <form>
2. <p>Kindly Select your favorite color</p>
3. <input type="radio" name="color" value="red"> Red <br>
4. <input type="radio" name="color" value="blue"> blue <br>
5. <input type="radio" name="color" value="green">green <br>
6. <input type="radio" name="color" value="pink">pink <br>
7. <input type="submit" value="submit">
8. </form>
Test it Now
Output:
6. <input type="checkbox">:
The <input> type "checkbox" are displayed as square boxes which can be
checked or unchecked to select the choices from the given options.
Note: The "radio" buttons are similar to checkboxes, but there is an important
difference between both types: radio buttons allow the user to select only one
option at a time, whereas checkbox allows a user to select zero to multiple
options at a time.
Example:
1. <form>
2. <label>Enter your Name:</label>
3. <input type="text" name="name">
4. <p>Kindly Select your favourite sports</p>
5. <input type="checkbox" name="sport1" value="cricket">Crick
et<br>
6. <input type="checkbox" name="sport2" value="tennis">Tennis<br>
Output:
Registration Form
Enter your Name:
Kindly Select your favorite sports
Cricket
Tennis
Football
Baseball
Badminton
7. <input type="button">:
The <input> type "button" defines a simple push button, which can be
programmed to control a functionally on any event such as, click event.
Output:
Note: In the above example we have used the "alert" of JS, which you will learn in
our JS tutorial. It is used to show a pop window.
8. <input type="file">:
The <input> element with type "file" is used to select one or more files
from user device storage. Once you select the file, and after submission,
this file can be uploaded to the server with the help of JS code and file API.
Example:
1. <form>
2. <label>Select file to upload:</label>
3. <input type="file" name="newfile">
4. <input type="submit" value="submit">
5. </form>
Test it Now
Output:
9. <input type="image">:
The <input> type "image" is used to represent a submit button in the
form of image.
ADVERTISEMENT
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Input "image" type.</h2>
5. <p>We can create an image as submit button</p>
6. <form>
7. <label>User id:</label><br>
8. <input type="text" name="name"><br><br>
9. <input type="image" alt="Submit" src="[Link]" width="100
px">
10. </form>
11.
12. </body>
13. </html>
Note: The "color" type only supports color value in hexadecimal format, and the
default value is #000000 (black).
Example:
1. <form>
2. Pick your Favorite color: <br><br>
3. <input type="color" name="upclick" value="#a52a2a"> Upclick
<br><br>
4. <input type="color" name="downclick" value="#f5f5dc"> Downclick
5. </form>
Test it Now
Output:
Up-click
Down-click
2. <input type="date">:
The <input> element of type "date" generates an input field, which allows
a user to input the date in a given format. A user can enter the date by
text field or by date picker interface.
Example:
1. <form>
2. Select Start and End Date: <br><br>
3. <input type="date" name="Startdate"> Start date:<br><br>
4. <input type="date" name="Enddate"> End date:<br><br>
5. <input type="submit">
6. </form>
Test it Now
Output:
Start date:
End date:
3. <input type="datetime-local">:
The <input> element of type "datetime-local" creates input filed which
allow a user to select the date as well as local time in the hour and minute
without time zone information.
Example:
1. <form>
2. <label>
3. Select the meeting schedule: <br><br>
4. Select date & time: <input type="datetime-local" nam
e="meetingdate"> <br><br>
5. </label>
6. <input type="submit">
7. </form>
Test it Now
Output:
Example:
1. <form>
2. <label><b>Enter your Email-address</b></label>
3. <input type="email" name="email" required>
4. <input type="submit">
5. <p><strong>Note:</strong>User can also enter multiple e
mail addresses separating by comma or whitespace as following: </
p>
6. <label><b>Enter multiple Email-addresses</b></label>
7. <input type="email" name="email" multiple>
8. <input type="submit">
9. </form>
Test it Now
Output:
5. <input type="month">:
The <input> type "month" creates an input field which allows a user to
easily enter month and year in the format of "MM, YYYY" where MM
defines month value, and YYYY defines the year value. New
Example:
1. <form>
2. <label>Enter your Birth Month-year: </label>
3. <input type="month" name="newMonth">
4. <input type="submit">
5. </form>
Test it Now
Output:
6. <input type="number">:
The <input> element type number creates input filed which allows a user
to enter the numeric value. You can also restrict to enter a minimum and
maximum value using min and max attribute.
Example:
1. <form>
2. <label>Enter your age: </label>
3. <input type="number" name="num" min="50" max="80">
4. <input type="submit">
5. </form>
Test it Now
Output:
Note:It will allow to enter number in range of 50-80. If you want to enter
number other than range, it will show an error.
7. <input type="url">:
The <input> element of type "url" creates an input filed which enables
user to enter the URL.
Example:
1. <form>
2. <label>Enter your website URL: </label>
3. <input type="url" name="website" placeholder="http://
[Link]"><br>
4. <input type="submit" value="send data">
5. </form>
Test it Now
Output:
8. <input type="week">:
The <input> type week creates an input field which allows a user to select
a week and year form the drop-down calendar without time zone.
Example:
1. <form>
2. <label><b>Select your best week of year:</b></label><br><br>
3. <input type="week" name="bestweek">
4. <input type="submit" value="Send data">
5. </form>
Test it Now
Output:
9. <input type="search">:
The <input> type "search" creates an input filed which allows a user to
enter a search string. These are functionally symmetrical to the text input
type, but may be styled differently.
Example:
1. <form>
2. <label>Search here:</label>
3. <input type="search" name="q">
4. <input type="submit" value="search">
5. </form>
Test it Now
Output:
Example:
1. <form>
2. <label><b>Enter your Telephone Number(in format of xxx-xxx-
xxxx):</b></label>
3. <input type="tel" name="telephone" pattern="[0-9]{3}-[0-9]
{3}-[0-9]{4}" required>
4. <input type="submit"><br><br>
5. </form>
Test it Now
Output:
Note: Here we are using two attributes that are "pattern" and"required"
which will allow user to enter the number in given format and it is
required to enter the number in input field.
The action attribute value defines the web page where information
proceed. It can be .php, .jsp, .asp, etc. or any URL where you want to
process your form.
Note: If action attribute value is blank then form will be processed to the same
page.
Example:
1. <form action="[Link]" method="post">
2. <label>User Name:</label><br>
3. <input type="text" name="name"><br><br>
4. <label>User Password</label><br>
5. <input type="password" name="pass"><br><br>
6. <input type="submit">
7. </form>
Test it Now
Output:
User Password
Example:
1. <form action="[Link]" method="post">
o get: The get value of method attribute is default value while submitting
the form. But this is not secure as it displays data in URL after submitting
the form.
Example:
1. <form action="[Link]" method="get">
When submitting the data, it will display the entered data in the form of:
1. [Link]
o _self: If we use _self as an attribute value, then the response will display
in current page only.
Example:
1. <form action="[Link]" method="get" target="_self">
o _blank: If we use _blank as an attribute it will load the response in a new
page.
Example:
1. <form action="[Link]" method="get" target="_blank">
Example:
1. <form action="[Link]" method="post" enctype="application/
x-www-form-urlencoded" >
o multipart/form-data: It does not encode any character. It is used when
our form contains file-upload controls.
Example:
1. <form action="[Link]" method="post" enctype="multipart/
form-data">
o text/plain (HTML5): In this encoding type only space are encoded into +
symbol and no any other special character encoded.
Example:
1. <form action="[Link]" method="post" enctype="text/plain" >
Output:
Enter age:
Enter email:
Note: One should not omit the name attribute as when we submit the form the
HTTP request includes both name-value pair and if name is not available it will not
process that input field.
Example:
1. <form action = "[Link]" method = "get">
2. Enter name:<br><input type="name" name="uname"><br>
3. Enter age:<br><input type="number" name="age"><br>
4. Enter email:<br><input type="email"><br>
5. <input type="submit" value="Submit">
6. </form>
Test it Now
Output:
Enter age:
Enter email:
Note: If you will not use name attribute in any input field, then
that input field will not be submitted, when submit the form.
Click on submit and see the URL where email is not included in HTTP
request as we have not used name attribute in the email input field
Example:
1. <form>
2. <label>Enter your Name</label><br>
3. <input type="text" name="uname" value="Enter Name"><b
r><br>
4. <label>Enter your Email-address</label><br>
5. <input type="text" name="uname" value="Enter email"><br
><br>
6. <label>Enter your password</label><br>
7. <input type="password" name="pass" value=""><br><br>
8. <input type="submit" value="login">
9. </form>
Test it Now
Output:
Example:
1. <form>
2. <label>Enter your Email-address</label><br>
3. <input type="text" name="uname" required><br><br>
4. <label>Enter your password</label><br>
5. <input type="password" name="pass"><br><br>
6. <input type="submit" value="login">
7. </form>
Test it Now
Output:
If you will try to submit the form without completing email field
then it will give an error pop up.
The placeholder attribute can be used with text, password, email, and URL
values.
When the user enters the value, the placeholder will be automatically
removed.
Example:
1. <form>
2. <label>Enter your name</label><br>
3. <input type="text" name="uname" placeholder="Your name"
><br><br>
4. <label>Enter your Email address</label><br>
5. <input type="email" name="email" placeholder="example@g
[Link]"><br><br>
6. <label>Enter your password</label><br>
7. <input type="password" name="pass" placeholder="your pas
sword"><br><br>
8. <input type="submit" value="login">
9. </form>
Test it Now
Output:
Registration form
Enter your name
Enter your Email address
The disabled input filed does not receive click events, and these input
value will not be sent to the server when submitting the form.
Example:
1. <input type="text" name="uname" disabled><br><br>
Test it Now
Output:
Registration form
Enter User name
Example:
1. <label>Account holder name</label><br>
2. <input type="text" name="uname" size="40" required><br><br>
3. <label>Account number</label><br>
4. <input type="text" name="an" size="30" required><br><br>
5. <label>CVV</label><br>
6. <input type="text" name="cvv" size="1" required><br><br>
Test it Now
Output:
Account number
CVV
Example:
1. User email: <br><input type="email" name="email" form="fcont
rol" required><br>
2. <input type="submit" form="fcontrol">
Test it Now
Output:
User Name:
User password:
The email field is outside the form but still it will remain part of the form
User email:
CSS is used to apply the style in the web page which is made up of HTML
elements. It describes the look of the webpage.
Note: In this chapter, we have given a small overview of CSS. You will learn
everything in depth about CSS in our CSS tutorial.
Example:
1. <body style="text-align: center;">
2. <h2 style="color: red;">Welcome to javaTpoint</h2>
3. <p style="color: blue; font-size: 25px; font-style: italic ;">This is
a great website to learn technologies in very simple way. </p>
4. </body>
Test it Now
Output:
Welcome to javaTpoint
This is a great website to learn technologies in
very simple way.
o Inline CSS: Define CSS properties using style attribute in the HTML
elements.
o Internal or Embedded CSS: Define CSS using <style> tag in <head>
section.
o External CSS: Define all CSS property in a separate .css file, and then
include the file with HTML file using tag in section.
Inline CSS:
Inline CSS is used to apply CSS in a single element. It can apply style
uniquely in each element.
To apply inline CSS, you need to use style attribute within HTML element.
We can use as many properties as we want, but each property should be
separated by a semicolon (;).
Example:
1. <h3 style="color: red;
2. font-style: italic;
3. text-align: center;
4. font-size: 50px;
5. padding-top: 25px;">Learning HTML using Inline CSS</h3>
Test it Now
Output:
We can use internal CSS to apply a style for a single HTML page.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. /*Internal CSS using element name*/
6. body{background-color:lavender;
7. text-align: center;}
8. h2{font-style: italic;
9. font-size: 30px;
10. color: #f08080;}
11. p{font-size: 20px;}
12. /*Internal CSS using class name*/
13. .blue{color: blue;}
14. .red{color: red;}
15. .green{color: green;}
16. </style>
17. </head>
18. <body>
19. <h2>Learning HTML with internal CSS</h2>
20. <p class="blue">This is a blue color paragraph</p>
21. <p class="red">This is a red color paragraph</p>
22. <p class="green">This is a green color paragraph</p>
23. </body>
24.</html>
Test it Now
Note: In the above example, we have used a class attribute which you will learn in
the next chapter.
External CSS:
An external CSS contains a separate CSS file which only contains style
code using the class name, id name, tag name, etc. We can use this CSS
file in any HTML file by including it in HTML file using <link> tag.
If we have multiple HTML pages for an application and which use similar
CSS, then we can use external CSS.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <link rel="stylesheet" type="text/css" href="[Link]">
5. </head>
6. <body>
7. <h2>Learning HTML with External CSS</h2>
8. <p class="blue">This is a blue color paragraph</p>
9. <p class="red">This is a red color paragraph</p>
10. <p class="green">This is a green color paragraph</p>
11. </body>
12.</html>
Test it Now
CSS file:
body{
background-color:lavender;
text-align: center;
}
h2{
font-style: italic;
size: 30px;
color: #f08080;
}
p{
font-size: 20px;
}
.blue{
color: blue;
}
.red{
color: red;
}
.green{
color: green;
}
Commonly used CSS properties:
Type Description
Type "disc" This is the default style. In this style, the list items are marked with bullets.
Type "circle" In this style, the list items are marked with circles.
Type "square" In this style, the list items are marked with squares.
Type "none" In this style, the list items are not marked .
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="circle"
1. <ul type="circle">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Test it Now
Output:
ADVERTISEMENT
o HTML
o Java
o JavaScript
o SQL
ul type="square"
1. <ul type="square">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Test it Now
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="none"
1. <ul type="none">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Test it Now
Output:
o HTML
o Java
o JavaScript
o SQL
Note: The type attribute is not supported in HTML5, instead of type you can use
CSS property of list-style-type. Following is the example to show the CSS
property for ul tag.
1. <ul style="list-style-type: square;">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ul>
Code:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h2>The type attribute with CSS property</h2>
7. <ul style="list-style-type: square;">
8. <li>HTML</li>
9. <li>Java</li>
10. <li>JavaScript</li>
11. <li>SQL</li>
12. </ul>
13. </body>
14.</html>
Test it Now
Output:
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>
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>
Test it Now
Output:
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.
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.
Browser mp4 webM ogg
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="[Link]" type="video/ogg">
3. Your browser does not support the html video tag.
4. </video>
Supporting Browsers
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 n
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
completed.
preload It specifies the author view to upload video file when the page loads.
mp4 video/mp4
ogg video/ogg
webM video/webM
HTML SVG
The HTML SVG is an acronym which stands for Scalable Vector Graphics.
SVG is mostly used for vector type diagrams like pie charts, 2-Dimensional
graphs in an X,Y coordinate system etc.
The <svg> element specifies the root of a SVG fragment. You can
animate every element and every attribute in SVG files.
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:
SVG images and their behaviors are defined in XML text files, so they can
be created and edited with any text editor.
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:
Note: It is always necessary to specify the id attribute and the height & width
attribute to define the size of the canvas. You can have multiple canvas elements
on one HTML page.
Supporting Browsers
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:
ADVERTISEMENT
moveTo(x,y): It is used to define the starting point of the line.
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:
To sketch circle on HTML canvas, use one of the ink() methods, like
stroke() or fill().
ADVERTISEMENT
font property: It is used to define the font property for the text.
Output:
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.
Test it Now
Output:
2) What to drag:
3) Where to Drop:
4) Do the Drop:
HTML5 Geolocation
The Geolocation is one of the best HTML5 API which is used to identify the
user's geographic location for the web application.
This new feature of HTML5 allows you to navigate the latitude and
longitude coordinates of the current website's visitor. These coordinates
can be captured by JavaScript and send to the server which can show your
current location on the website
Tips: To completely understand the concept of Geolocation API you must have
some knowledge of JavaScript.
User privacy:
The user's location is the privacy concern, so geolocation API protects the
user's privacy by taking the user's permission before getting the location.
Geolocation API sends a notification prompt box which user can allow or
deny, and if the user allows then only his location will be identified.
Note: Your browser must support the geolocation to use it for the web application.
Although most of the browsers and mobile devices support the Geolocation API,
and this API is only available for HTTPS request.
Geolocation object
The Geolocation API is work with the [Link] object. Its
read-only property returns a Geolocation object which identifies the
location of the user and can generate a customized result based on user
location.
Syntax:
1. geo=navigator. geolocation;
If this object is present, then you can get the geolocation services.
Geolocation Methods
The Geolocation API uses three methods of Geolocation interface which
are given following:
Methods Description
getCurrentPositio It identifies the device or the user's current location and returns a positi
n() object with data.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Geolocation API</title>
5. </head>
6. <body>
7. <h1>Find your Current location</h1>
8. <button onclick="getlocation()">Click me</button>
9. <div id="location"></div>
10.<script>
11. var x= [Link]("location");
12.
The below example will return the longitude and latitude of the visitor's
current location.
ADVERTISEMENT
ADVERTISEMENT
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Geolocation API</title>
5. </head>
6. <body>
7. <h1>Find your Current location</h1>
8. <button onclick="getlocation()">Click me</button>
9. <div id="location"></div>
10.<script>
11. var x= [Link]("location");
12. function getlocation() {
13. if([Link]){
14. [Link](showPosition)
15. }
16. else
17. {
18. alert("Sorry! your browser is not supporting")
19. }}
20.
21. function showPosition(position){
22. var x = "Your current location is (" + "Latitude: " + [Link]
tude + ", " + "Longitude: " + [Link] + ")";
23. [Link]("location").innerHTML =
x;
24. }
25. </script>
26.</body>
27. </html>
Test it Now
Explanation:
o First checking the browser support
o Getting current position with getCurrentPosition()
o Getting latitude and longitude values with showPosition() method which is
call back method of getCurrentPosition().
Following are the possible options for invoking the error call back function:
Example
1. function showError(error) {
2. switch([Link]){
3. case error.PERMISSION_DENIED:
4. alert("User denied the request for Geolocation API.");
5. break;
6. case error.POSITION_UNAVAILABLE:
7. alert("USer location information is unavailable.");
8. break;
9. case [Link]:
10. alert("The request to get user location timed out.");
11. break;
12. case error.UNKNOWN_ERROR:
13. alert("An unknown error occurred.");
14. break;
15. }
16. }
Test it Now
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Geolocation API</title>
5. </head>
6. <body>
7. <h2>Find Your Location in below Map</h2>
8. <button onclick="getlocation();"> Show Position</button>
9. <div id="demo" style="width: 600px; height: 400px; margin-
left: 200px;"></div>
10.
11. <script src="[Link]
sensor=false"> </script>
12.
13. <script type="text/javascript">
14. function getlocation(){
15. if([Link]){
16. [Link](showPos, showErr);
17. }
18. else{
19. alert("Sorry! your Browser does not support Geoloca
tion API")
20. }
21. }
22. //Showing Current Poistion on Google Map
23. function showPos(position){
24. latt = [Link];
25. long = [Link];
26. var lattlong = new [Link](latt, long);
27. var myOptions = {
28. center: lattlong,
29. zoom: 15,
30. mapTypeControl: true,
31. navigationControlOptions: {style:[Link]
[Link]}
32. }
33. var maps = new [Link]([Link]
entById("demo"), myOptions);
34. var markers =
35. new [Link]({position:lattlong, map:maps
, title:"You are here!"});
36. }
37.
38. //Handling Error and Rejection
39. function showErr(error) {
40. switch([Link]){
41. case error.PERMISSION_DENIED:
42. alert("User denied the request for Geolocation API.");
43. break;
44. case error.POSITION_UNAVAILABLE:
45. alert("USer location information is unavailable.");
46. break;
47. case [Link]:
48. alert("The request to get user location timed out.");
49. break;
50. case error.UNKNOWN_ERROR:
51. alert("An unknown error occurred.");
52. break;
53. }
54. } </script>
55. </body>
56.</html>
Test it Now
To learn more about Google Maps JavaScript API, you can click on the
following link:
[Link]
Location properties
The getCurrentPosition() method of Geolocation API returns callback
methods which retrieve the user location information. This callback
method returns a Position Object which contains all location information
and specifies different properties. It always returns latitude and longitude
properties, but the following table describes some other properties of
Position object.
Properties Description
[Link] It returns altitude in meters above the sea level (Only if available).
[Link] It returns the accuracy of the user's position.
Syntax:
1. var id = [Link](success[, error[, option
s]])
Syntax:
1. [Link](id);
Browser Support:
Storing data with the help of web storage is similar to cookies, but it is
better and faster than cookies storage.
o Web Storage can use storage space upto 5MB per domain. (The browser
software may prompt the user if the space limit is reached).
o It will not send data to the server side, hence it is faster than cookies
storage.
o The data stored by local Storage never expires, but cookies data expires
after some time or session.
o Web Storage is more secure than cookies.
Note: For both storage type, web storage data will not be available for different
browsers, and Storage size may vary from browser to browser.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <div id="result"></div>
5. <script>
6. if(typeof(Storage)!=="undefined") {
7. [Link]("result").innerHTML = "Hey, Your brow
ser supports the Web Storage.";
8. }
9. else{
[Link]("result").innerHTML = "Sorry, your browser doe
s not support Web Storage";
11. }
12.</script>
13. </body>
14.</html>
Test it Now
Each piece of data is stored in simple key-value pairs. The key/values are
always stored as String, and can be accessed with [Link]()
and [Link]() methods.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Web Storage API</title>
5. <style>
6. body{
7. color: green;
8. text-align: center;
9. font-size: 30px;
10. margin-top: 30px;
11. font-style: italic;
12. }
13. </style>
14.</head>
15. <body>
16.<script>
17. if(typeof(Storage)!=="undefined") {
18. [Link]("name","Harshita");
19. [Link]("Country", "India");
20. [Link]("Hi"+" "+[Link]+" "+"from" +" "+ localStor
[Link]);
21. }
22. else{
23. alert("Sorry! your browser is not supporting the browser")
24. }
25. </script>
26.</body>
27. </html>
Test it Now
Example Explanation:
o In the above example, we have used typeof(Storage)!
=="undefined" to check browser support.
o [Link]("name","Harshita") is used to set the key and
value data where "name" is key and "Harshita" is value.
o The [Link] is used to retrieve the values using key. You can
also use another method:
[Link] to retrieve the value.
Note: You can check the local storage items in the form of key/value pair by
inspecting elements on the web page and then go to the Application option where
you will find the local storage and Session storage and can check stored items in
the list.
Example Explanation:
In the above example, we have shown a counter which will increase as
you will click on the counter button.
Note: It will show the total number of count even if you close the browser.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div{
6. background-color: pink;
7. height: 50px;
8. }
9. </style>
10.</head>
11. <body>
12. <h2>Example of counter Using Session Storage</h2>
13. <button onclick="counter();">click me</button>
14. <div id="output">See the result here:</div>
15. <script type="text/javascript">
16. function counter() {
17. if([Link]){
18. [Link]=Number([Link])+1;
19. }
20. else{
21. [Link]=1;
22. }
23. [Link]('output').innerHTML= "You have cl
icked counter button for"+ " "+ [Link] +" "+"times";
24.}
25. </script>
26. <p>Click the counter button to see the total counts. </p>
27. <p>Now, if you close the browser then it will reset to initial v
alue. </p>
28.</body>
29. </html>
Test it Now
Example Explanation:
The above example is working same as local storage counter example,
but the difference is we have used [Link] for session
storage.
Here the counter will reset if you close the browser and it will start from
the initial value.
Tips: You can make these examples more attractive and useful by using jQuery
with JavaScript.
Hence to delete the local storage data, you need to call two methods:
Example Explanation:
In the above example we have
used [Link]("name"); Which will delete the value
for the key "name".
You can remove id for a particular key, or you can also remove all data
using [Link]() method.
Browser Support:
Web Workers are the multithreaded object which can execute multiple
JavaScript in parallel without affecting the performance of the application
or webpage.
Tips: Before working with HTML Web Workers you must have knowledge of
JavaScript as the Web Worker depends on JavaScript.
The dedicated worker can be accessed by only one script which has called
it. The dedicated worker thread end as its parent thread ends. Dedicated
workers are only used by one or single main thread.
It can be shared by multiple scripts and can communicate using the port.
Shared workers can be accessed by different windows, iframes or workers.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Web Worker API</title>
5. </head>
6. <body>
7. <h2>Example to check the browser support of Web Workers</h2>
8. <div id="supported"></div>
9. <div id="unsupported"></div>
10.<button onclick="worker();">click me</button>
11. <script type="text/javascript">
12. function worker()
13. {
14. if(typeof(Worker)!=="undefined"){
15. [Link]("supported").innerHTML="Supp
orting the browser";
16. }
17. else
18. {
19. [Link]("unsupported").innerHTML="N
ot supporting";}
20. }
21. </script>
22.</body>
23. </html>
Test it Now
Here we have created a web worker file for calculating the square of the
number. And saved it with the name "[Link]".
1. onmessage =function(event){
2. var num= [Link];
3. var sqr=num*num;
4. var result="";
5. for(var i=1;i<=sqr; i++)
6. {
7. result= "Sqaure result is:"+ " "+i;
8. }
9. postMessage(result);
10.}
1. [Link]();
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. .div1{
6. margin-left: 350px;
7. }
8. </style>
9. </head>
10.<body>
11. <!-- Sqaure Output Result -->
12.<div class="div1">
13. <h2>Example of Web Worker</h2>
14.<label>Enter the number to find the square</label>
15. <br><input type="text" name="num" id="num"><br>
16.<br><button id="submit">Submit</button>
17. <button id="other">Wait</button>
18.<div id="text"></div>
19. </div>
20.<script type="text/javascript">
21.
[Link]("other").onclick=function() {
23. alert("Hey! Web Worker is working, and you can wait for the
result.");
24.}
25.
26.//Web-worker Code.....
27. var worker= new Worker("[Link]");
28. [Link]= function(event){
29. [Link]("text").innerText= [Link];}
30. [Link]("submit").onclick= function(){
31. var num= [Link]("num").value;
32. [Link](num);
33. }
34.</script>
35. <p><b>Note:Try to enter a big number, and then click on oth
er button. The page will respond properly</b></p>
36.</body>
37. </html>
Test it Now
[Link] file:
1. onmessage=function(event){
2. var num= [Link];
3. var sqr=num*num;
4. var result="";
5. for(var i=1;i<=sqr; i++)
6. {
7. result= "Sqaure result is:"+ " "+i;
8. }
9. postMessage(result);
10.}
Example Explanation:
In the above example in HTML file we have used
o var worker= new Worker("[Link]"); To create the web Worker
object.
o [Link]= function(event): It is used to send the message
between the main thread and Worker thread.
o [Link](num); This is the method used to communicate
between the Worker thread and main thread. Using this method Worker
thread return the result to the main thread.
Example:
1. if(typeof(EventSource) !== "undefined") {
2. var source = new EventSource("[Link]");
3. [Link] = function(event) {
4. [Link]("output").innerHTML += [Link] + "<br
>";
5. }
Code Explanation:
o First, create the new EventSource object, and define the URI of
the page which sends server updates. Here we have taken
[Link] for sending the updates to the web browser.
o Each time when an update occurs from the server, then the onmessage
event occurs and print the message on the web page.
o The occurred message can be displayed on div using id "output".
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>HTML5 SSE API</title>
5. </head>
6. <body>
7. <div id="output"></div>
8. <script type="text/javascript">
9.
10. if(typeof(EventSource)!=="undefined"){
11. alert("Hey! Your browser is supporting.");
12. }
13. else{
14. alert("Sorry! Your browser is not supporting.");
15. }
16. </script>
17. </body>
18.</html>
Test it Now
[Link]:
Example:
1. <?php
2. header('Content-Type: text/event-stream');
3. header('Cache-Control: no-cache');
4. /Get the current time of server
5. $time = date('r');
6. echo "data: The Current Server time is: {$time}\n\n";
7. flush();
8. ?>
Code Explanation:
o In the first line of the code, we have set the "Content-type" header to
"text/event-stream". It is required for server-side event standard.
o The second line informs the server to turn off the caching else the server
updates may be cached.
o echo "data: The Current Server time is: {$time}\n\n"; It creates the output
of data to send, and it must always start with data: .
o Then, we have used the flush () method, which makes sure that data is
sent right away to the web page.
Complete Example:
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style type="text/css">
5. div{
6. text-align: center;
7. background-color: #98f5ff;
8. }
9. </style>
10.</head>
11. <body>
12.
13. <h1 align="center">Dynamic Server Updates</h1>
14.<div id="output"></div>
15. <script>
[Link](typeof(EventSource) !== "undefined") {
17. var source = new EventSource("[Link]");
18. [Link] = function(event) {
19. [Link]("output").innerHTML += event.d
ata + "<br>";
20. }
21. } else {
22. alert("Sorry, your browser does not support the server sent updates");}
23. </script>
24.</body>
25. </html>
Test it Now
Note: To execute the above code on your browser, you need a server installed on
your system, and then run this on localhost. You can install any server such as
MYSQL, XAMPP, etc.
Browser Support:
A color names
There is given a list of 13 color names that starts with A letter.
AliceBlue #f0f8ff
AntiqueWhite #faebd7
AntiqueWhite1 #ffefdb
AntiqueWhite2 #eedfcc
AntiqueWhite3 #cdc0b0
AntiqueWhite4 #8b8378
aquamarine1 #7fffd4
aquamarine2 #76eec6
aquamarine4 #458b74
azure1 #f0ffff
azure2 #e0eeee
azure3 #c1cdcd
azure4 #838b8b
B color names
There is given a list of 21 color names that starts with B letter.
Color Name Color Color Code
beige #f5f5dc
bisque1 #ffe4c4
bisque2 #eed5b7
bisque3 #cdb79e
bisque4 #8b7d6b
black #000000
BlanchedAlmond #ffebcd
blue1 #0000ff
blue2 #0000ee
blue4 #00008b
BlueViolet #8a2be2
brown #a52a2a
brown1 #ff4040
brown2 #ee3b3b
brown3 #cd3333
brown4 #8b2323
burlywood #deb887
burlywood1 #ffd39b
burlywood2 #eec591
burlywood3 #cdaa7d
burlywood4 #8b7355
C color names
There is given a list of 27 color names that starts with C letter.
CadetBlue #5f9ea0
CadetBlue1 #98f5ff
CadetBlue2 #8ee5ee
CadetBlue3 #7ac5cd
CadetBlue4 #53868b
chartreuse1 #7fff00
chartreuse2 #76ee00
chartreuse3 #66cd00
chartreuse4 #458b00
chocolate #d2691e
chocolate1 #ff7f24
chocolate2 #ee7621
chocolate3 #cd661d
coral #ff7f50
coral1 #ff7256
coral2 #ee6a50
coral3 #cd5b45
coral4 #8b3e2f
CornflowerBlue #6495ed
cornsilk1 #fff8dc
cornsilk2 #eee8cd
cornsilk3 #cdc8b1
cornsilk4 #8b8878
cyan1 #00ffff
cyan2 #00eeee
cyan3 #00cdcd
cyan4 #008b8b
D color names
There is given a list of 49 color names that starts with D letter.
DarkGoldenrod #b8860b
DarkGoldenrod1 #ffb90f
DarkGoldenrod2 #eead0e
DarkGoldenrod3 #cd950c
DarkGoldenrod4 #8b6508
DarkGreen #006400
DarkKhaki #bdb76b
DarkOliveGreen #556b2f
DarkOliveGreen1 #caff70
DarkOliveGreen2 #bcee68
DarkOliveGreen3 #a2cd5a
DarkOliveGreen4 #6e8b3d
DarkOrange #ff8c00
DarkOrange1 #ff7f00
DarkOrange2 #ee7600
DarkOrange3 #cd6600
DarkOrange4 #8b4500
DarkOrchid #9932cc
DarkOrchid1 #bf3eff
DarkOrchid2 #b23aee
DarkOrchid3 #9a32cd
DarkOrchid4 #68228b
DarkSalmon #e9967a
DarkSeaGreen #8fbc8f
DarkSeaGreen1 #c1ffc1
DarkSeaGreen2 #b4eeb4
DarkSeaGreen3 #9bcd9b
DarkSeaGreen4 #698b69
DarkSlateBlue #483d8b
DarkSlateGray #2f4f4f
DarkSlateGray1 #97ffff
DarkSlateGray2 #8deeee
DarkSlateGray3 #79cdcd
DarkSlateGray4 #528b8b
DarkTurquoise #00ced1
DarkViolet #9400d3
DeepPink1 #ff1493
DeepPink2 #ee1289
DeepPink3 #cd1076
DeepPink4 #8b0a50
DeepSkyBlue1 #00bfff
DeepSkyBlue2 #00b2ee
DeepSkyBlue3 #009acd
DeepSkyBlue4 #00688b
DimGray #696969
DodgerBlue1 #1e90ff
DodgerBlue2 #1c86ee
DodgerBlue3 #1874cd
DodgerBlue4 #104e8b
F color names
There is given a list of 7 color names that starts with F letter.
firebrick #b22222
firebrick1 #ff3030
firebrick2 #ee2c2c
firebrick3 #cd2626
firebrick4 #8b1a1a
FloralWhite #fffaf0
ForestGreen #228b22
G color names
There is given a list of 115 color names that starts with G letter.
Color Name Color Color Code
gainsboro #dcdcdc
GhostWhite #f8f8ff
gold1 #ffd700
gold2 #eec900
gold3 #cdad00
gold4 #8b7500
goldenrod #daa520
goldenrod1 #ffc125
goldenrod2 #eeb422
goldenrod3 #cd9b1d
goldenrod4 #8b6914
gray #bebebe
gray1 #030303
gray10 #1a1a1a
gray11 #1c1c1c
gray12 #1f1f1f
gray13 #212121
gray14 #242424
gray15 #262626
gray16 #292929
gray17 #2b2b2b
gray18 #2e2e2e
gray19 #303030
gray2 #050505
gray20 #333333
gray21 #363636
gray22 #383838
gray23 #3b3b3b
gray24 #3d3d3d
gray25 #404040
gray26 #424242
gray27 #454545
gray28 #474747
gray29 #4a4a4a
gray3 #080808
gray30 #4d4d4d
gray31 #4f4f4f
gray32 #525252
gray33 #545454
gray34 #575757
gray35 #595959
gray36 #5c5c5c
gray37 #5e5e5e
gray38 #616161
gray39 #636363
gray4 #0a0a0a
gray40 #666666
gray41 #696969
gray42 #6b6b6b
gray43 #6e6e6e
gray44 #707070
gray45 #737373
gray46 #757575
gray47 #787878
gray48 #7a7a7a
gray49 #7d7d7d
gray5 #0d0d0d
gray50 #7f7f7f
gray51 #828282
gray52 #858585
gray53 #878787
gray54 #8a8a8a
gray55 #8c8c8c
gray56 #8f8f8f
gray57 #919191
gray58 #949494
gray59 #969696
gray6 #0f0f0f
gray60 #999999
gray61 #9c9c9c
gray62 #9e9e9e
gray63 #a1a1a1
gray64 #a3a3a3
gray65 #a6a6a6
gray66 #a8a8a8
gray67 #ababab
gray68 #adadad
gray69 #b0b0b0
gray7 #121212
gray70 #b3b3b3
gray71 #b5b5b5
gray72 #b8b8b8
gray73 #bababa
gray74 #bdbdbd
gray75 #bfbfbf
gray76 #c2c2c2
gray77 #c4c4c4
gray78 #c7c7c7
gray79 #c9c9c9
gray8 #141414
gray80 #cccccc
gray81 #cfcfcf
gray82 #d1d1d1
gray83 #d4d4d4
gray84 #d6d6d6
gray85 #d9d9d9
gray86 #dbdbdb
gray87 #dedede
gray88 #e0e0e0
gray89 #e3e3e3
gray9 #171717
gray90 #e5e5e5
gray91 #e8e8e8
gray92 #ebebeb
gray93 #ededed
gray94 #f0f0f0
gray95 #f2f2f2
gray97 #f7f7f7
gray98 #fafafa
gray99 #fcfcfc
green1 #00ff00
green2 #00ee00
green3 #00cd00
green4 #008b00
GreenYellow #adff2f
H color names
There is given a list of 9 color names that starts with H letter.
Color Name Color Color Code
honeydew1 #f0fff0
honeydew2 #e0eee0
honeydew3 #c1cdc1
honeydew4 #838b83
HotPink #ff69b4
HotPink1 #ff6eb4
HotPink2 #ee6aa7
HotPink3 #cd6090
HotPink4 #8b3a62
I color names
There is given a list of 9 color names that starts with I letter.
IndianRed #cd5c5c
IndianRed1 #ff6a6a
IndianRed2 #ee6363
IndianRed3 #cd5555
IndianRed4 #8b3a3a
ivory1 #fffff0
ivory2 #eeeee0
ivory3 #cdcdc1
ivory4 #8b8b83
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.
lavender #e6e6fa
LavenderBlush1 #fff0f5
LavenderBlush2 #eee0e5
LavenderBlush3 #cdc1c5
LavenderBlush4 #8b8386
LawnGreen #7cfc00
LemonChiffon1 #fffacd
LemonChiffon2 #eee9bf
LemonChiffon3 #cdc9a5
LemonChiffon4 #8b8970
light #eedd82
LightBlue #add8e6
LightBlue1 #bfefff
LightBlue2 #b2dfee
LightBlue3 #9ac0cd
LightBlue4 #68838b
LightCoral #f08080
LightCyan1 #e0ffff
LightCyan2 #d1eeee
LightCyan3 #b4cdcd
LightCyan4 #7a8b8b
LightGoldenrod1 #ffec8b
LightGoldenrod2 #eedc82
LightGoldenrod3 #cdbe70
LightGoldenrod4 #8b814c
LightGoldenrodYellow #fafad2
LightGray #d3d3d3
LightPink #ffb6c1
LightPink1 #ffaeb9
LightPink2 #eea2ad
LightPink3 #cd8c95
LightPink4 #8b5f65
LightSalmon1 #ffa07a
LightSalmon2 #ee9572
LightSalmon3 #cd8162
LightSalmon4 #8b5742
LightSeaGreen #20b2aa
LightSkyBlue #87cefa
LightSkyBlue1 #b0e2ff
LightSkyBlue2 #a4d3ee
LightSkyBlue3 #8db6cd
LightSkyBlue4 #607b8b
LightSlateBlue #8470ff
LightSlateGray #778899
LightSteelBlue #b0c4de
LightSteelBlue1 #cae1ff
LightSteelBlue2 #bcd2ee
LightSteelBlue3 #a2b5cd
LightSteelBlue4 #6e7b8b
LightYellow1 #ffffe0
LightYellow2 #eeeed1
LightYellow3 #cdcdb4
LightYellow4 #8b8b7a
LimeGreen #32cd32
linen #faf0e6
M color names
There is given a list of 34 color names that starts with M letter.
magenta #ff00ff
magenta2 #ee00ee
magenta3 #cd00cd
magenta4 #8b008b
maroon #b03060
maroon1 #ff34b3
maroon2 #ee30a7
maroon3 #cd2990
maroon4 #8b1c62
medium #66cdaa
MediumAquamarine #66cdaa
MediumBlue #0000cd
MediumOrchid #ba55d3
MediumOrchid1 #e066ff
MediumOrchid2 #d15fee
MediumOrchid3 #b452cd
MediumOrchid4 #7a378b
MediumPurple #9370db
MediumPurple1 #ab82ff
MediumPurple2 #9f79ee
MediumPurple3 #8968cd
MediumPurple4 #5d478b
MediumSeaGreen #3cb371
MediumSlateBlue #7b68ee
MediumSpringGreen #00fa9a
MediumTurquoise #48d1cc
MediumVioletRed #c71585
MidnightBlue #191970
MintCream #f5fffa
MistyRose1 #ffe4e1
MistyRose2 #eed5d2
MistyRose3 #cdb7b5
MistyRose4 #8b7d7b
moccasin #ffe4b5
N color names
There is given a list of 5 color names that starts with N letter.
NavajoWhite1 #ffdead
NavajoWhite2 #eecfa1
NavajoWhite3 #cdb38b
NavajoWhite4 #8b795e
NavyBlue #000080
O color names
There is given a list of 18 color names that starts with O letter.
OliveDrab #6b8e23
OliveDrab1 #c0ff3e
OliveDrab2 #b3ee3a
OliveDrab4 #698b22
orange1 #ffa500
orange2 #ee9a00
orange3 #cd8500
orange4 #8b5a00
OrangeRed1 #ff4500
OrangeRed2 #ee4000
OrangeRed3 #cd3700
OrangeRed4 #8b2500
orchid #da70d6
orchid1 #ff83fa
orchid2 #ee7ae9
orchid3 #cd69c9
orchid4 #8b4789
P color names
There is given a list of 38 color names that starts with P letter.
Color Name Color Color Code
pale #db7093
PaleGoldenrod #eee8aa
PaleGreen #98fb98
PaleGreen1 #9aff9a
PaleGreen2 #90ee90
PaleGreen3 #7ccd7c
PaleGreen4 #548b54
PaleTurquoise #afeeee
PaleTurquoise1 #bbffff
PaleTurquoise2 #aeeeee
PaleTurquoise3 #96cdcd
PaleTurquoise4 #668b8b
PaleVioletRed #db7093
PaleVioletRed1 #ff82ab
PaleVioletRed2 #ee799f
PaleVioletRed3 #cd6889
PaleVioletRed4 #8b475d
PapayaWhip #ffefd5
PeachPuff1 #ffdab9
PeachPuff2 #eecbad
PeachPuff3 #cdaf95
PeachPuff4 #8b7765
pink #ffc0cb
pink1 #ffb5c5
pink2 #eea9b8
pink3 #cd919e
pink4 #8b636c
plum #dda0dd
plum1 #ffbbff
plum2 #eeaeee
plum3 #cd96cd
plum4 #8b668b
PowderBlue #b0e0e6
purple #a020f0
purple1 #9b30ff
purple2 #912cee
purple3 #7d26cd
purple4 #551a8b
R color names
There is given a list of 14 color names that starts with R letter.
red1 #ff0000
red2 #ee0000
red3 #cd0000
red4 #8b0000
RosyBrown #bc8f8f
RosyBrown1 #ffc1c1
RosyBrown2 #eeb4b4
RosyBrown3 #cd9b9b
RosyBrown4 #8b6969
RoyalBlue #4169e1
RoyalBlue1 #4876ff
RoyalBlue2 #436eee
RoyalBlue3 #3a5fcd
RoyalBlue4 #27408b
S color names
There is given a list of 48 color names that starts with S letter.
Color Name Color Color Code
SaddleBrown #8b4513
salmon #fa8072
salmon1 #ff8c69
salmon2 #ee8262
salmon3 #cd7054
salmon4 #8b4c39
SandyBrown #f4a460
SeaGreen1 #54ff9f
SeaGreen2 #4eee94
SeaGreen3 #43cd80
SeaGreen4 #2e8b57
seashell1 #fff5ee
seashell2 #eee5de
seashell3 #cdc5bf
seashell4 #8b8682
sienna #a0522d
sienna1 #ff8247
sienna2 #ee7942
sienna3 #cd6839
sienna4 #8b4726
SkyBlue #87ceeb
SkyBlue1 #87ceff
SkyBlue2 #7ec0ee
SkyBlue3 #6ca6cd
SkyBlue4 #4a708b
SlateBlue #6a5acd
SlateBlue1 #836fff
SlateBlue2 #7a67ee
SlateBlue3 #6959cd
SlateBlue4 #473c8b
SlateGray #708090
SlateGray1 #c6e2ff
SlateGray2 #b9d3ee
SlateGray3 #9fb6cd
SlateGray4 #6c7b8b
snow1 #fffafa
snow2 #eee9e9
snow3 #cdc9c9
snow4 #8b8989
SpringGreen1 #00ff7f
SpringGreen2 #00ee76
SpringGreen3 #00cd66
SpringGreen4 #008b45
SteelBlue #4682b4
SteelBlue1 #63b8ff
SteelBlue2 #5cacee
SteelBlue3 #4f94cd
SteelBlue4 #36648b
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
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.
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 #f5deb3
wheat1 #ffe7ba
wheat2 #eed8ae
wheat3 #cdba96
wheat4 #8b7e66
white #ffffff
WhiteSmoke #f5f5f5
Y color names
There is given a list of 5 color names that starts with A letter.
yellow1 #ffff00
yellow2 #eeee00
yellow3 #cdcd00
yellow4 #8b8b00
YellowGreen #9acd32
HTML SVG
The HTML SVG is an acronym which stands for Scalable Vector Graphics.
SVG is mostly used for vector type diagrams like pie charts, 2-Dimensional
graphs in an X,Y coordinate system etc.
The <svg> element specifies the root of a SVG fragment. You can
animate every element and every attribute in SVG files.
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:
ADVERTISEMENT
Test it Now
Output:
SVG images and their behaviors are defined in XML text files, so they can
be created and edited with any text editor.
HTML Lists
HTML Lists are used to specify lists of information. All lists may contain
one or more list elements. There are three different types of HTML lists:
Note: We can create a list inside another list, which will be termed as nested List.
1. <ol>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ol>
Test it Now
Output:
1. Aries
2. Bingo
3. Leo
4. Oracle
Click here for full details of HTML ordered list. HTML Ordered List
ADVERTISEMENT
1. <ul>
2. <li>Aries</li>
3. <li>Bingo</li>
4. <li>Leo</li>
5. <li>Oracle</li>
6. </ul>
Test it Now
Output:
o Aries
o Bingo
o Leo
o Oracle
Click here for full details of HTML unordered list. HTML Unordered List
The definition list is very appropriate when you want to present glossary,
list of terms or other name-value list.
1. <dl>
2. <dt>Aries</dt>
3. <dd>-One of the 12 horoscope sign.</dd>
4. <dt>Bingo</dt>
5. <dd>-One of my evening snacks</dd>
6. <dt>Leo</dt>
7. <dd>-It is also an one of the 12 horoscope sign.</dd>
8. <dt>Oracle</dt>
9. <dd>-It is a multinational technology corporation.</dd>
10.</dl>
Test it Now
Output:
Aries
-One of the 12 horoscope sign.
Bingo
-One of my evening snacks
Leo
-It is also an one of the 12 horoscope sign.
Oracle
-It is a multinational technology corporation.
Click here for full details of HTML description list. HTML Description List
Code:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Nested list</title>
5. </head>
6. <body>
7. <p>List of Indian States with thier capital</p>
8. <ol>
9. <li>Delhi
10. <ul>
11. <li>NewDelhi</li>
12. </ul>
13. </li>
14. <li>Haryana
15. <ul>
16. <li>Chandigarh</li>
17. </ul>
18. </li>
19. <li>Gujarat
20. <ul>
21. <li>Gandhinagar</li>
22. </ul>
23. </li>
24. <li>Rajasthan
25. <ul>
26. <li>Jaipur</li>
27. </ul>
28. </li>
29. <li>Maharashtra
30. <ul>
31. <li>Mumbai</li>
32. </ul>
33. </li>
34. <li>Uttarpradesh
35. <ul>
36. <li>Lucknow</li></ul>
37. </li>
38.</ol>
39. </body>
40.</html>
Test it Now
Output:
HTML
Ordered List | HTML Numbered List
HTML Ordered List or Numbered List displays elements in numbered
format. The HTML ol tag is used for ordered list. We can use ordered list to
represent items either in numerical order format or alphabetical order
format, or any format where an order is emphasized. There can be
different types of numbered list:
Type Description
Type "1" This is the default type. In this type, the list items are numbered with numbers.
Type "I" In this type, the list items are numbered with upper case roman numbers.
Type "i" In this type, the list items are numbered with lower case roman numbers.
Type "A" In this type, the list items are numbered with upper case letters.
Type "a" In this type, the list items are numbered with lower case letters.
1. <ol>
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
1. HTML
2. Java
3. JavaScript
4. SQL
ol type="I"
Let's see the example to display list in roman number uppercase.
1. <ol type="I">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
I. HTML
II. Java
III. JavaScript
IV. SQL
ol type="i"
Let's see the example to display list in roman number lowercase.
1. <ol type="i">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
i. HTML
ii. Java
iii. JavaScript
iv. SQL
ol type="A"
Let's see the example to display list in alphabet uppercase.
1. <ol type="A">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
ADVERTISEMENT
A. HTML
B. Java
C. JavaScript
D. SQL
ol type="a"
Let's see the example to display list in alphabet lowercase.
1. <ol type="a">
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
a. HTML
b. Java
c. JavaScript
d. SQL
start attribute
The start attribute is used with ol tag to specify from where to start the
list items.
<ol type="1" start="5"> : It will show numeric values starting with "5".
<ol type="i" start="5"> : It will show Roman lower case value starting
with "v".
Output:
v. HTML
vi. Java
vii. JavaScript
viii. SQL
reversed Attribute:
This is a Boolean attribute of HTML <ol> tag, and it is new in HTML5
version. If you use the reversed attribute with
tag then it will numbered the list in descending order (7, 6, 5, 4......1).
Example:
1. <ol reversed>
2. <li>HTML</li>
3. <li>Java</li>
4. <li>JavaScript</li>
5. <li>SQL</li>
6. </ol>
Test it Now
Output:
HTML style using CSS
Let's suppose we have created our web page using a simple HTML code,
and we want something which can present our page in a correct format,
and visibly attractive. So to do this, we can style our web page with CSS
(Cascading Stylesheet) properties.
CSS is used to apply the style in the web page which is made up of HTML
elements. It describes the look of the webpage.
Note: In this chapter, we have given a small overview of CSS. You will learn
everything in depth about CSS in our CSS tutorial.
Example:
1. <body style="text-align: center;">
2. <h2 style="color: red;">Welcome to javaTpoint</h2>
3. <p style="color: blue; font-size: 25px; font-style: italic ;">This is
a great website to learn technologies in very simple way. </p>
4. </body>
Test it Now
Welcome to javaTpoint
This is a great website to learn technologies in
very simple way.
ADVERTISEMENT
ADVERTISEMENT
o Inline CSS: Define CSS properties using style attribute in the HTML
elements.
o Internal or Embedded CSS: Define CSS using <style> tag in <head>
section.
o External CSS: Define all CSS property in a separate .css file, and then
include the file with HTML file using tag in section.
Inline CSS:
Inline CSS is used to apply CSS in a single element. It can apply style
uniquely in each element.
To apply inline CSS, you need to use style attribute within HTML element.
We can use as many properties as we want, but each property should be
separated by a semicolon (;).
Example:
1. <h3 style="color: red;
2. font-style: italic;
3. text-align: center;
4. font-size: 50px;
5. padding-top: 25px;">Learning HTML using Inline CSS</h3>
Test it Now
Output:
ADVERTISEMENT
We can use internal CSS to apply a style for a single HTML page.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. /*Internal CSS using element name*/
6. body{background-color:lavender;
7. text-align: center;}
8. h2{font-style: italic;
9. font-size: 30px;
10. color: #f08080;}
11. p{font-size: 20px;}
12. /*Internal CSS using class name*/
13. .blue{color: blue;}
14. .red{color: red;}
15. .green{color: green;}
16. </style>
17. </head>
18. <body>
19. <h2>Learning HTML with internal CSS</h2>
20. <p class="blue">This is a blue color paragraph</p>
21. <p class="red">This is a red color paragraph</p>
22. <p class="green">This is a green color paragraph</p>
23. </body>
24.</html>
Test it Now
Note: In the above example, we have used a class attribute which you will learn in
the next chapter.
External CSS:
An external CSS contains a separate CSS file which only contains style
code using the class name, id name, tag name, etc. We can use this CSS
file in any HTML file by including it in HTML file using <link> tag.
If we have multiple HTML pages for an application and which use similar
CSS, then we can use external CSS.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <link rel="stylesheet" type="text/css" href="[Link]">
5. </head>
6. <body>
7. <h2>Learning HTML with External CSS</h2>
8. <p class="blue">This is a blue color paragraph</p>
9. <p class="red">This is a red color paragraph</p>
10. <p class="green">This is a green color paragraph</p>
11. </body>
12.</html>
Test it Now
CSS file:
body{
background-color:lavender;
text-align: center;
}
h2{
font-style: italic;
size: 30px;
color: #f08080;
}
p{
font-size: 20px;
}
.blue{
color: blue;
}
.red{
color: red;
}
.green{
color: green;
}
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.
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:
Let's use a class name "Fruit" with CSS to style all elements.
1. <style>
2. .fruit {
3. background-color: orange;
4. color: white;
5. padding: 10px;
6. }
7. </style>
8.
9. <h2 class="fruit">Mango</h2>
10.<p>Mango is king of all fruits.</p>
11.
12.<h2 class="fruit">Orange</h2>
13. <p>Oranges are full of Vitamin C.</p>
14.
15. <h2 class="fruit">Apple</h2>
16.<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 user click on
the button.
1. <!DOCTYPE html>
2. <html>
3. <body>
4.
5. <h2>Class Attribute with JavaScript</h2>
6. <p>Click the button, to hide all elements with the class name "fruit", with
JavaScript:</p>
7.
8. <button onclick="myFunction()">Hide elements</button>
9.
10.
11. <h2 class="fruit">Mango</h2>
12.<p>Mango is king of all fruits.</p>
13.
14.<h2 class="fruit">Orange</h2>
15. <p>Oranges are full of Vitamin C.</p>
16.
17. <h2 class="fruit">Apple</h2>
18.<p>An apple a day, keeps the Doctor away.</p>
19.
20.<script>
21. function myFunction() {
22. var x = [Link]("fruit");
23. for (var i = 0; i < [Link]; i++) {
24. x[i].[Link] = "none";
25. }
26.}
27. </script>
28.
29. </body>
30.</html>
Test it Now
Note: You will learn more about JavaScript in our JavaScript tutorial.
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".
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .fruit {
5. background-color: orange;
6. color: white;
7. padding: 10px;
8. }
9.
10..center {
11. text-align: center;
12.}
13. </style>
14.<body>
15.
16.<h2>Multiple Classes</h2>
17. <p>All three elements have the class name "fruit". In addition
, Mango also have the class name "center", which center-aligns the t
ext.</p>
18.
19. <h2 class="fruit center">Mango</h2>
20.<h2 class="fruit">Orange</h2>
21. <h2 class="fruit">Apple</h2>
22.
23. </body>
24.</html>
Test it Now
You can see that the first element <h2> belongs to both the "fruit" class
and the "center" class.
Example:
1. <!DOCTYPE html>
2. <html>
3. <style>
4. .fruit {
5. background-color: orange;
6. color: white;
7. padding: 10px;
8. }
9. </style>
10.<body>
11. <h2>Same Class with Different Tag</h2>
12.<h2 class="fruit">Mango</h2>
13. <p class="fruit">Mango is the king of all fruits.</p>
14.</body>
15. </html>
HTML Id Attribute
The id attribute is used to specify the unique ID for an element of the
HTML document. It allocates the unique identifier which is used by
the CSS and the JavaScript for performing certain tasks.
Note: In the Cascading Style sheet (CSS), we can easily select an element with the
specific id by using the # symbol followed by id.
Note: JavaScript can access an element with the given ID by using the
getElementById() method.
Syntax
1. <tag id="value">
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Id attribute in CSS
6. </title>
7. <style>
8. #Cars {
9. padding: 40px;
[Link]-color: lightblue;
11. color: black;
[Link]-align: center;
13. }
14.
15. #Bikes
16.{
17. padding: 50px;
[Link]-color: lightGreen;
19. text-align: center;
20.}
21. </style>
22.</head>
23. <body>
24.<p> Use CSS to style an element with the id: </p>
25. <h1 id="Cars"> Cars </h1>
26.<h1 id="Bikes"> Bikes </h1>
27. </body>
28.</html>
Test it Now
Output:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title> Date Attribute </title>
5. <script>
6. function viewdate() {
7. var x = [Link]("dob").value;
8. [Link]("demo").innerHTML = x;
9. </script>
10.</head>
11. <body>
[Link] Name: <input type="text" placeholder="Your Good name"/>
13. <br>
14.<br>
15. Date of Joining:
16.<input type="date" id="dob">
17. <br>
18.<button onclick="viewdate()"> Submit
19. </button>
20.<br>
21. <h2 id="demo"> </h2>
22.</body>
23. </html>
Test it Now
Output:
HTML
List Box
The list box is a graphical control element in the HTML document that
allows a user to select one or more options from the list of options.
Syntax
To create a list box, use the HTML element <select> which contains two
attributes Name and Size. The Name attribute is used to define the
name for calling the list box, and size attribute is used to specify the
numerical value that shows the how many options it contains.
1. <!DOCTYPE html>
2. <html>
3. <title>
4. Example of List Box
5. </title>
6. <body>
7. Customer Name: <input type="text" Placeholder="Enter the Custo
mer Name"/>
8. <br>
9. <br>
10.<select name="Cars" size="5">
11. <option value="Merceders"> Merceders </option>
12. <option value="BMW"> BMW </option>
13. <option value="Jaguar"> Jaguar </option>
14. <option value="Lamborghini"> Lamborghini </option>
15. <option value="Ferrari"> Ferrari </option>
16. <option value="Ford"> Ford </option>
17. </select>
18.</body>
19. </html>
Test it Now
Output:
Example 2: Below example uses the multiple attribute for selecting the
multiple options in a list. We can select multiple options from list box by
holding the ctrl key.
1. <!DOCTYPE html>
2. <html>
3. <title>
4. Example of List Box with multiple attribute
5. </title>
6. <body>
7. Customer Name: <input type="text" Placeholder="Enter the Custo
mer Name"/>
8. <br>
9. <br>
10.<select name="Cars" size="5" multiple="multiple">
11. <option value="Merceders"> Merceders </option>
12. <option value="BMW"> BMW </option>
13. <option value="Jaguar"> Jaguar </option>
14. <option value="Lamborghini"> Lamborghini </option>
15. <option value="Ferrari"> Ferrari </option>
16. <option value="Ford"> Ford </option>
17. </select>
18.</body>
19. </html>
Test it Now
Output:
Add
JavaScript to HTML
There are following three ways through which we can add the JavaScript
code into the HTML document:
Syntax
1. <html>
2. <head>
3. <script>
4. JavaScript Code
5. Statement 1
6. Statement 2
7. ......
8. Statement N
9. </script>
10.</head>
11. <body>
12.</body>
13. </html>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Include JavaScript in head tag
7. </title>
8.
9. <script>
[Link] check()
11. {
12./* The following statement is used to display a Confirm dialog box on a we
bpage with the statement which is enclosed in the brackets. */
13. confirm("Your JavaScript Code Run");
14.}
15. </script>
16.<style>
17. /* The following tag selector button use the different propertie
s for the Button. */
[Link] {
19. background-color: red;
[Link]: 16px 20px;
21. margin: 8px 0;
22. border: none;
23. cursor: pointer;
24. color: white;
25. width: 100%;
26. opacity: 0.9;
27. }
28./* The following tag selector hover use the opacity property for the Button
which select button when you mouse over it. */
29. button:hover {
[Link]: 1;
31. }
32.</style>
33. </head>
34.<body>
35. <form>
36.<!-- The following statement use the Button type which is used to call a fu
nction of JavaScript when this button is clicked. -->
37. <button type="button" onclick="check()"> Click Me for runni
ng a JavaScript Code </button>
38.
39. </form>
40.</body>
41. </html>
Test it Now
Output:
2. i) Include the JavaScript code in the <body> tag.
In this section, you will learn about how to include the JavaScript code in-
between the <body> and </body> tag.
Syntax
1. <html>
2. <head>
3. </head>
4. <body>
5.
6. <script>
7. JavaScript Code
8. Statement 1
9. Statement 2
10.......
11. Statement N
12.</script>
13. </body>
14.</html>
In the above syntax, the JavaScript code written between the
<script>……. </script> tag is put in-between of the <body> and </body>
tag in HTML file.
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Include JavaScript in body tag
7. </title>
8. <style>
9. /* The following tag selector button use the different properties for t
he Button. */
[Link] {
11. background-color: red;
12. padding: 16px 20px;
13. margin: 8px 0;
14. border: none;
15. cursor: pointer;
16. color: white;
17. width: 100%;
18. opacity: 0.9;
19. }
20./* The following tag selector hover use the opacity property for the Button
which select button when you mouse over it. */
21. button:hover {
[Link]: 1;
23. }
24.</style>
25. </head>
26.<body>
27. <form>
28.<script>
29. function bdy_JS ()
30.{
31. /* The following statement is used to display a Confirm dialog
box on a webpage with the statement which is enclosed in the brack
ets. */
[Link]("Your JavaScript Code Run which is used in the Body tag");
33. }
34.</script>
35.
36.<!-- The following statement use the Button type which is used to call a fu
nction of JavaScript when this button is clicked. -->
37. <button type="button" onclick="bdy_JS()"> Click Me for runn
ing a JavaScript Code </button>
38.</form>
39. </body>
40.</html>
Test it Now
Output:
Syntax
1. <html>
2. <head>
3. </head>
4. <body>
5. </body>
6. <script>
7. JavaScript Code
8. Statement 1
9. Statement 2
10.......
11. Statement N
12.</script>
13.
14.</html>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Include JavaScript code after the body tag
7. </title>
8. <style>
9. /* The following tag selector button use the different properties for t
he Button. */
[Link] {
11. background-color: red;
12. color: white;
13. margin: 8px 0;
14. border: none;
15. cursor: pointer;
16. width: 100%;
17. padding: 16px 20px;
18. opacity: 0.9;
19. }
20./* The following tag selector hover use the opacity property for the Button
which select button when you mouse over it. */
21. button:hover {
[Link]: 1;
23. }
24.</style>
25. </head>
26.<body>
27. <form>
28.<!-- The following statement use the Button type which is used to call a fu
nction of JavaScript when this button is clicked. -->
29. <button type="button" onclick="bdy_JS()"> Click Me for runn
ing a JavaScript Code </button>
30.
31. </form>
32.</body>
33. <script>
[Link] bdy_JS ()
35. {
36./* The following statement is used to display a Confirm dialog box on a we
bpage with the statement which is enclosed in the brackets. */
37. confirm("Your JavaScript Code Run which is used after the Bod
y tag");
38.}
39. </script>
40.</html>
Test it Now
Output:
Link the Separate file of JavaScript in HTML
In this section, you will learn to include the file of JavaScript code in the
HTML file.
Syntax
1. <html>
2. <head>
3. <script src="Name_of_JavaScript_file>
4. </script>
5. </head>
6. <body>
7. </body>
8. </html>
In the above syntax, the src is an attribute of <script> tag used for
specifying the name of the JavaScript file.
Example
1. function funcjs ()
2. {
3. /* The following statement displays a Confirm dialog box on a webpa
ge with the statement which is enclosed in the brackets. */
4. confirm("Your JavaScript Code Run which is used after the Body tag");
5. }
The following code is written in an HTML file which uses the src attribute
in the <script> tag to specify the above JavaScript file.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Include JavaScript file in head tag of HTML file
7. </title>
8. <script src="[Link]">
9. </script>
10.<style>
11. /* The following tag selector button use the different propertie
s for the Button. */
[Link] {
13. background-color: red;
14. color: white;
15. margin: 8px 0;
16. border: none;
17. cursor: pointer;
18. width: 100%;
19. padding: 16px 20px;
20. opacity: 0.9;
21. }
22./* The following tag selector hover use the opacity property for the Button
which select button when you mouse over it. */
23. button:hover {
[Link]: 1;
25. }
26.</style>
27. </head>
28.<body>
29. <form>
30.<!-- The following statement use the Button type which is used to call a fu
nction of JavaScript when this button is clicked. -->
31.
32.<button type="button" onclick="funcjs()"> Click Me for running a JavaScr
ipt Code </button>
33. </form>
34.</body>
35. </html>
Test it Now
Output:
HTML Background Image
The <background> attribute in the HTML document is used to specify
the background image on a HTML page or a table. You can pass the path
of an image as a value of background attribute to set the image of your
HTML page or table.
Syntax
1. <tag background="Path_of_an_image">
Note: The Background attribute is not supported in HTML5. Use the following
syntax of CSS:
1. <tag style="background-image:Path_of_an_image)">
Example 1: This example uses the background attribute with the body
tag for displaying the image as a background of the web page.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Background image
6. </title>
7. </head>
8. <body background="[Link]
kotenko1403/kotenko140300008/26854631-snowy-winter-in-a-mountain-
forest-sunny-cold-day-with-snow-covered-trees-carpathian-mountains-
[Link]">
9.
10.<font color="red">
11. <h1> click on this <a href="[Link] li
nk </a> for the Home page of Our Website </h1>
12.</font>
13. </body>
14.</html>
Test it Now
Output:
Example 2: This example uses the background attribute with the table
tag for displaying the image as a background of html table.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Background image
6. </title>
7. </head>
8. <body>
9. <center>
10.
11. In this example, we use the background attribute with the tabl
e tag, which displays the image as a background of the HTML table.
12.
13. <table background="[Link]
237272/[Link]?
auto=compress&cs=tinysrgb&dpr=1&w=500" height="300" border
="1" width="500">
14.
15. <tr>
16. <td> Roll No. </td>
17. <td> Name </td>
18. </tr>
19. <tr>
20. <td> 101 </td>
21. <td> Abhay </td>
22. </tr>
23. <tr>
24. <td> 102 </td>
25. <td> Chetan </td>
26. </tr>
27. <tr>
28. <td> 103 </td>
29. <td> Manpreet </td>
30. </tr>
31. <tr>
32. <td> 104 </td>
33. <td> Rakesh </td>
34. </tr>
35. <tr>
36. <td> 105 </td>
37. <td> Sumit </td>
38. </tr>
39. </table>
40.</center>
41. </body>
42.</html>
Test it Now
Output:
Example 3: This example uses the CSS syntax for the background-
image property of the style attribute with the body tag.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Background image
6. </title>
7. </head>
8.
9. <body style="background-image:url('[Link]
images/kotenko/kotenko1403/kotenko140300008/26854631-snowy-
winter-in-a-mountain-forest-sunny-cold-day-with-snow-covered-
[Link]');">
10.
11. <font size="4" color="green">
12.
13. In this example, we use the <b> background-image </b> pro
perty in the <b>style</b> attribute with the <b> body tag </b> w
hich display the image as a background on the web page.
14.
15. </font>
16.<center>
17. <font size="4" color="red">
18.<table height="300" border="1" width="500">
19. <tr>
20. <td> Roll No. </td>
21. <td> Name </td>
22. </tr>
23. <tr>
24. <td> 101 </td>
25. <td> Abhay </td>
26. </tr>
27. <tr>
28. <td> 102 </td>
29. <td> Chetan </td>
30. </tr>
31. <tr>
32. <td> 103 </td>
33. <td> Manpreet </td>
34. </tr>
35. <tr>
36. <td> 104 </td>
37. <td> Rakesh </td>
38. </tr>
39. <tr>
40. <td> 105 </td>
41. <td> Sumit </td>
42. </tr>
43. </table>
44.</font>
45. </center>
46.</body>
47. </html>
Test it Now
Output:
Example 4: This example uses the CSS syntax for the background-image
property in the style attribute with the table tag.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Background image
6. </title>
7. </head>
8. <body>
9. <font size="4" color="orange">
[Link] this example, we use the <b> background-image property </b> in the
<b> style attribute </b> with the <b> table tag </b> which display the i
mage as a background of HTML table.
11. </font>
12.<font size="4" color="red">
13. <center>
14.
15. <table style="background-image:url('https://
[Link]/photos/237272/[Link]?
auto=compress&cs=tinysrgb&dpr=1&w=500');">
16. <tr>
17. <td> Roll No. </td>
18. <td> Name </td>
19. </tr>
20.
21. <tr>
22. <td> 101 </td>
23. <td> Abhay </td>
24. </tr>
25. <tr>
26. <td> 102 </td>
27. <td> Chetan </td>
28. </tr>
29. <tr>
30. <td> 103 </td>
31. <td> Manpreet </td>
32. </tr>
33. <tr>
34. <td> 104 </td>
35. <td> Rakesh </td>
36. </tr>
37. <tr>
38. <td> 105 </td>
39. <td> Sumit </td>
40. </tr>
41. </table>
42.</center>
43. </font>
44.</body>
45. </html>
Test it Now
Output:
Example 5: This example uses the CSS syntax for the background-
repeat and background-size property of the style attribute with the
body tag.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Background image
6. </title>
7. </head>
8.
9. <body style="background-image:url('[Link]
photos/237272/[Link]?
auto=compress&cs=tinysrgb&dpr=1&w=500');
[Link]-repeat:no-repeat; background-size: 100% 100%">
11.
12.<font size="4" color="green">
13.
[Link] this example, we use the <b> background-repeat and background-size
property </b> in the <b> style attribute </b> with the <b> body </b> t
ag
15. which display the image without repeatition.
16.
17. </font>
18.<center>
19.
20.<font size="4" color="red">
21. <table height="300" border="1" width="500">
22. <tr>
23. <td> Roll No. </td>
24. <td> Name </td>
25. </tr>
26. <tr>
27. <td> 101 </td>
28. <td> Abhay </td>
29. </tr>
30. <tr>
31. <td> 102 </td>
32. <td> Chetan </td>
33. </tr>
34. <tr>
35. <td> 103 </td>
36. <td> Manpreet </td>
37. </tr>
38. <tr>
39. <td> 104 </td>
40. <td> Rakesh </td>
41. </tr>
42. <tr>
43. <td> 105 </td>
44. <td> Sumit </td>
45. </tr>
46.</table>
47. </font>
48.</center>
49. </body>
50.</html>
Syntax
1. <element or tag hidden> Any statement or content </element or
tag>
Examples:T he following examples are specified to understand easily
how to use the hidden attribute with different elements or tags:
Example 1: This example uses the hidden attribute with the paragraph
tag.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. First Example of Hidden attribute
6. </title>
7. </head>
8. <body>
9. <center>
10.<h1> JavaTpoint </h1>
11. </center>
12.<p hidden> This paragraph should be hidden.
13. </p>
14.</body>
15. </html>
Test it Now
Output:
Example 2: The following example uses the hidden attribute with the
<input type=text> element.
In this example, we have used the hidden attribute with two input tags.
These input fields will not display on the web page, when the following
program executes.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of Hidden attribute in input tag
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
[Link] {
11. font-family: Calibri, Helvetica, sans-serif;
[Link]-color: pink;
13. }
14./* Following container class used padding for generate space around it, an
d also use a background-color for specify the color lightblue as a backgrou
nd */
15. .container {
[Link]: 50px;
17. background-color: lightblue;
18.}
19. /* The following tag selector input use the different properties
for the text filed. */
[Link][type=text] {
21. width: 100%;
22. padding: 15px;
23. margin: 5px 0 22px 0;
24. border: none;
25. background: #f1f1f1;
26.}
27.
[Link][type=text]:focus {
29. background-color: orange;
[Link]: none;
31. }
32./* The following div tag selector is used to provide the space or gap betwe
en the content or elements on a web page. */
33. div {
34. padding: 10px 0;
35. }
[Link] {
37. border: 1px solid #f1f1f1;
38. margin-bottom: 25px;
39. }
40.</style>
41. </head>
42.<body>
43. <form>
44.<div class="container">
45. <center> <h1> Registration Form</h1> </center>
46.
47. <hr>
48.<label for="fn"> Firstname: </label>
49. <!-- The following input field not display on the web page beca
use the hidden attribute is used in this <input> tag. -->
50.<input hidden type="text" name="firstname" id= "fn" size="15" require
d />
51. <div>
52.<label for="mn"> Middlename: </label>
53. <input type="text" name="middlename" id="mn" size="15"
required />
54.</div>
55. <label for="Ln"> Lastname: </label>
56.<input type="text" name="lastname" id="Ln" size="15"required />
57.
58.<label for="pn">
59. Phone :
60.</label>
61. <input type="text" name="country code" placeholder="Cou
ntry Code" value="+91" size="2"/>
62.<!-- The following input field not display on the web page because it is als
o use the hidden attribute-->
63. <input hidden type="text" name="phone" id="pn" size="10
"/ required>
64.</hr>
65. </div>
66.</form>
67. </body>
68.</html>
Test it Now
Output:
HTML
Reset Button
The Reset is the value of the type attribute of the <Button> element. It
is used to reset the filled values of a form to its initial values.
Syntax
1. <Button type="reset">
Example
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of Reset Button
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
10.
11. body {
[Link]-family: Calibri, Helvetica, sans-serif;
13. background-color: pink;
14.}
15. /* Following container class used padding for generate space a
round it, and also use a background-color for specify the color lightbl
ue as a background */
16..container {
17. padding: 50px;
[Link]-color: lightblue;
19. }
20./* The following tag selector input use the different properties for the text
filed. */
21. input[type=text] {
22. width: 100%;
23. padding: 15px;
[Link]: 5px 0 22px 0;
25. display: inline-block;
26. border: none;
27. background: #f1f1f1;
28.}
29. input[type=text]:focus {
[Link]-color: orange;
31. outline: none;
32.}
33. div {
34. padding: 10px 0;
35. }
[Link] {
37. border: 1px solid #f1f1f1;
38. margin-bottom: 25px;
39. }
40./* The following tag selector button use the different properties for the But
ton. */
41. button {
42. background-color: #4CAF50;
43. color: white;
[Link]: 8px 0;
45. border: none;
46. cursor: pointer;
47.
48. padding: 16px 20px;
49. width: 100%;
50. opacity: 0.9;
51. }
52./* The following tag selector hover use the opacity property for the Button
which select button when you mouse over it. */
53. button:hover {
[Link]: 1;
55. }
56.
57. </style>
58.</head>
59. <body>
60.<form>
61. <div class="container">
62.<center> <h1> Form</h1> </center>
63.
64.<hr>
65. <label for="fn"> Firstname </label>
66.<input type="text" id="fn" name="firstname" placeholder= "Firstname"
size="15" required />
67. <label for="mn"> Middlename: </label>
68.<input type="text" id="mn" name="middlename" placeholder="Middlen
ame" size="15" required />
69. <label for="ln"> Lastname: </label>
70.<input type="text" id="ln" name="lastname" placeholder="Lastname" si
ze="15"required />
71.
72.<div>
73. <label>
[Link] :
75. </label><br>
76.<input type="radio" value="Male" name="gender" checked > Male
77. <input type="radio" value="Female" name="gender"> Fema
le
78.<input type="radio" value="Other" name="gender"> Other
79.
80.</div>
81. <label for="phn">
[Link] :
83. </label>
84.<input type="text" name="country code" placeholder="Country Code" v
alue="+91" size="2"/>
85. <input type="text" id="phn" name="phone" placeholder="p
hone no." size="10"/ required/>
86.
87.
88.<label for="em">
89. Email
90.</label>
91. <input type="text" id="em" placeholder="Enter Email" nam
e="email" required>
92.
93. The below button displays as the reset button which is used to
reset the filled values of a form to its initial values.
94.<button type="reset" value="submit">Reset</button>
95. </form>
96.</body>
97. </html>
Test it Now
Output:
HTML
Search Box
The HTML Search Box allows a user to search the content.
The Search is a value of type attribute of an <input> element.
Syntax
1. <input type="search">
Examples: The following examples have used the different CSS codes for
displaying the different Search boxes on the web page.
Example 1:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of search box
6. </title>
7. <style>
8. /* The following tag selector body use the text-align and background-color
properties. The text-align property is used to align the text as center, and t
he background-color is used to specify the blue colour as a background of
a page*/
9. body {
[Link]-align: center;
11. background-color: blue;
12.}
13. /* The following tag selector form uses the different properties
for displaying a form. */
14.
15. form{
16. display: block;
17. left: 30%;
18. position: absolute;
19. top: 30%;
20.}
21. /* The following tag selector input uses the different properties
for the search box. */
22. input[type=search]{
23. border: 5px orange;
24. box-sizing: border-box;
25. font-size:1em;
26. height: 2em;
27. margin-left: 10vw;
28. padding: .5em;
29. transition: all 2s ease-in;
30. width: 30vw;
31. z-index:1;
32. &:focus {
33. border: solid 3px #09f;
34. outline: solid #fc0 2000px;
35. }
36. }
37. </style>
38.</head>
39. <body>
40.<form>
41. <input type="search" placeholder="Search for any site"/>
42.</form>
43. </body>
44.</html>
Test it Now
Output:
Example 2: In this example, we have not used the search value of the
type attribute of an input element. But we have used the text input field
using CSS, which is working as a search field.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Second Example of search box
6. </title>
7. <style>
8. *
9. {
10. outline: none;
11. }
12./* The following tag selector form uses one property for specifying the heig
ht of a form. */
13.
[Link]
15. {
16. height: 96px;
17. }
18./* The following tag selector input use the different properties for specifyin
g the text field. */
19.
[Link][type="text"]
21. {
22. width: 100%;
23. height: 80px;
24. font-size: 40px;
25. line-height: 1;
26.}
27. /* The following tag selector uses the color of placeholder as o
range for the input text field. */
[Link][type="text"]::placeholder
29. {
30. color: orange;
31. }
32.
33. .tb
34.{
35. display: table;
36. width: 100%;
37. }
38..td
39. {
40. display: table-cell;
41. vertical-align: middle;
42.}
43. /* The following tag selector uses the different properties for s
pecifying all the inputs and buttons used in the body tag in this html
file. */
44.
45. input, button
46.{
47. color: #fff;
48. font-family: Arial;
49. padding: 0;
50. margin: 0;
51. border: 0;
52. background-color: transparent;
53. }
54./* the following id selector cover uses the different attribute which are use
d between the body tag */
55. #cover
56.{
57. position: absolute;
58. top: 50%;
59. width: 550px;
60. padding: 35px;
61. margin: -83px auto 0 auto;
62. background-color: #ff7575;
63. border-radius: 20px;
64. left: 0;
65. right: 0;
66. box-shadow: 0 10px 40px #ff7c7c, 0 0 0 20px #ffffffeb;
67. transform: scale(0.6);
68.}
69. /* The following tag selector button uses the different proprtie
s for specifying the button on a web page. */
[Link]
71. {
72. position: relative;
73. display: block;
74. width: 84px;
75. height: 96px;
76. cursor: pointer;
77. }
78./* The following id selector uses the different properties for searching butt
on */
79. #s-circle
80.{
81. position: relative;
82. top: -8px;
83. left: 0;
84. width: 43px;
85. height: 43px;
86. margin-top: 0;
87. border-width: 15px;
88. border: 15px solid #fff;
89. background-color: transparent;
90. border-radius: 50%;
91. transition: 0.5s ease all;
92.}
93. button span
94.{
95. position: absolute;
96. top: 68px;
97. left: 43px;
98. display: block;
99. width: 45px;
100. height: 15px;
101. background-color: transparent;
102. border-radius: 10px;
103. transform: rotateZ(52deg);
104. transition: 0.5s ease all;
105. }
106. button span:before, button span:after
107. {
108. content: '';
109. position: absolute;
110. bottom: 0;
111. right: 0;
112. width: 45px;
113. height: 15px;
114. background-color: #fff;
115. border-radius: 10px;
116. transform: rotateZ(0);
117. transition: 0.5s ease all;
118. }
119. #s-cover:hover #s-circle
120. {
121. top: -1px;
122. width: 67px;
123. height: 15px;
124. border-width: 0;
125. background-color: #fff;
126. border-radius: 20px;
127. }
128. /* The following hover effect use the different properties when you t
ake mouse to that element where thr s-cover is selector is used. */
129. #s-cover:hover span
130. {
131. top: 50%;
132. left: 56px;
133. width: 25px;
134. margin-top: -9px;
135. transform: rotateZ(0);
136. }
137. #s-cover:hover button span:before
138. {
139. bottom: 11px;
140. transform: rotateZ(52deg);
141. }
142. #s-cover:hover button span:after
143. {
144. bottom: -11px;
145. transform: rotateZ(-52deg);
146. }
147. #s-cover:hover button span:before, #s-cover:hover button sp
an:after
148. {
149. right: 6px;
150. width: 40px;
151. background-color: #fff;
152. }
153. </style>
154. </head>
155. <body>
156. <div id="cover">
157. <form method="get" action="">
158. <div class="tb">
159. <div class="td">
160. <!-- The following tag is input for the text input field which is used a
s a seach field on a web page -->
161. <input type="text" placeholder="Search" required></div>
162. <div class="td" id="s-cover">
163. <button type="submit">
164. <div id="s-circle"> </div>
165. <span> </span>
166. </button>
167. </div>
168. </div>
169. </form>
170. </div>
171. </body>
172. </html>
Test it Now
Output:
HTML Selected Attribute
The Selected is an attribute of the <option> element, which is used to
define the default selection in a dropdown-list.
When any option uses this attribute, then that option should be pre-
selected and displayed first, when the web page loads.
Syntax
1. <option selected>
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of selected attribute
6. </title>
7. </head>
8. <body>
9. <h4> Select Your favourite Car from the following given options: </
h4>
10.<br>
11. <select name="cars">
12. <option value="Mercedes"> Mercedes </option>
13. <option value="Lamborghini"> Lamborghini </option>
14.<!-- In the following option tag we specify the selected attribute for the Jag
uar value, which is display as selected on the web page by default. -->
15. <option value="Jaguar" selected> Jaguar </option>
16. <option value="BMW" > BMW </option>
17. <option value="Audi"> Audi </option>
18.</select>
19. </body>
20.</html>
Test it Now
Output:
Example 2: The following example uses the Selected attribute in
the <option> tag with the Pomegranate value.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Second Example of selected attribute
6. </title>
7. </head>
8. <body>
9. <h4> Select Your favourite fruit from the following list of fruits: </
h4>
10.<br>
11. <select name="fruits">
12. <option value="Apple"> Apple </option>
13. <option value="Banana"> Banana </option>
14. <option value="Orange"> Orange </option>
15. <!-- In the following option tag we specify the selected attribut
e for the Pomegranate value, which is display as selected on the we
b page by default.-->
16. <option value="Pomegranate" selected> Pomegranate </option>
17. <option value="Grapes"> Grapes </option>
18. <option value="Mango"> Mango </option>
19. </select>
20.</body>
21. </html>
Test it Now
Output:
Simple
HTML Pages
There are the following different examples implemented for
creating the simple HTML pages using the different basic tags:
In the following example, we have not specified the title of the web page
in the Head tag, so it will display the name of Html file as its title.
1. <Html> <!-- This tag is compulsory for any HTML document. -->
2. <Head>
3. <!-- The Head tag is used to create a title of web page, CSS syntax f
or a web page, and helps in written a JavaScript code. -->
4. </Head>
5. <Body>
6. <!-- The Body tag is used to display the content on a web page. In this exa
mple we do not specify any content or any tag, so in output nothing will di
splay on the web page. -->
7. </Body>
8. </Html>
Test it Now
Output:
Example 2: This example creates a page which helps in understanding
how to give a title to a web page.
1. <Html>
2. <Head>
3. <!-- In this example the title tag is used to specify the title of the we
b page. -->
4. <title>
5. Example of Title tag
6. </title>
7. </Head>
8. <Body>
9. </Body>
10.</Html>
Test it Now
Output:
Example 3: This example creates a web page which helps in
understanding how to make the text bold, italic, and underline.
1. <Html>
2. <Head>
3. <title>
4. Example of make a text B,I,U
5. </title>
6. </Head>
7. <Body>
8. <b> [This text is Bold......] </b>
9. <I> [This text is Italic......] </I>
10.<U> [This text is Underline......] </U>
11. </Body>
12.</Html>
Test it Now
Output:
Example 4: This example creates a web page which helps in
understanding how to use the <p> tag.
1. <Html>
2. <Head>
3. <title>
4. Example of Paragraph tag
5. </title>
6. </Head>
7. <Body>
8. <p> <!-- It is a Paragraph tag for creating the paragraph -->
9. <b> HTML </b> stands for <i> <u> Hyper Text Markup Language.
</u> </i> It is used to create a web pages and applications. This la
nguage
[Link] easily understandable by the user and also be modifiable. It is actually a
Markup language, hence it provides a flexible way for designing the
11. web pages along with the text.
12.</p>
13. HTML file is made up of different elements. <b> An element <
/b> is a collection of <i> start tag, end tag, attributes and the text
between them</i>.
14.</p>
15. </Body>
16.</Html>
Test it Now
Output:
1. <Html>
2. <Head>
3. <title>
4. Example of Header-levels
5. </title>
6. </Head>
7. <Body>
8.
9. <h6> JavaTpoint </h6>
10.<h5> JavaTpoint </h5>
11. <h4> JavaTpoint </h4>
12.<h3> JavaTpoint </h3>
13. <h2> JavaTpoint </h2>
14.<h1> JavaTpoint </h1>
15. </Body>
16.</Html>
Test it Now
Output:
Example 6: This example creates a web page which helps in
understanding how to align the text in center, and how to break a line.
1. <Html>
2. <Head>
3. <title>
4. Example of center and BR tag
5. </title>
6. </Head>
7. <Body>
8. <!-- In this example we use the center tag which specify the content at ce
ntre of the webpage.-->
9. <center>
[Link] tutorial in JavaTpoint <br> <!-- The BR tag is used to break a line. --
>
11. CSS tutorial in JavaTpoint <br>
12.</center>
13. JavaScript tutorial in JavaTpoint <!-- Here BR tag is not used, s
o the next statement is in continuous with one space after this state
ment. -->
[Link] tutorial in JavaTpoint <br>
15. </Body>
16.</Html>
Test it Now
Output:
1. <Html>
2. <Head>
3. <title>
4. Example of anchor or hyperlink
5. </title>
6. </Head>
7. <Body>
8. <!-- In this example we use the anchor tag for linking one page to another
by using the href attribute
9. which specify the url of the second page which you want to link.-->
Output:
Create
Html Page
You can create your first HTML page by the following steps:
The following block describes the syntax for creating any HTML page:
ADVERTISEMENT
1. <HTML>
2. <HEAD>
3. <!-- The Head tag is used to create a title of web page, CSS syntax f
or a web page, and helps in written a JavaScript code. -->
4. </HEAD>
5. <BODY>
6. <!-- The Body tag is used to display the content on a web page, which is s
pecified between the body tag. -->
7. </BODY>
8. </HTML> <!-- It is the opening tag of any HTML -->
In the above syntax, some important tags or elements are used, which are
given below:
<HEAD>: The Head tag is used to create a title of the web page, CSS
syntax for a web page, and helps in written a JavaScript code The <head>
must be closed before the opening of <body> tag.
<BODY>: The Body tag is used to display the content or text on a web
page, which is specified between the body tag.-->
Syntax
1. <button disabled> Text you want to show on the button </
button>
Examples: The following examples are using different buttons and make
them disabled.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of Submit Disabled
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
10.
11. body {
[Link]-family: Calibri, Helvetica, sans-serif;
13. background-color: pink;
14.}
15. /* Following container class used padding for generate space a
round it, and also use a background-color for specify the color lightbl
ue as a background */
16..container {
17. padding: 50px;
[Link]-color: lightblue;
19. }
20./* The following tag selector input uses the different properties for the text
filed. */
21.
[Link][type=text] {
23. width: 100%;
24. padding: 15px;
25. margin: 5px 0 22px 0;
[Link]: inline-block;
27. border: none;
28. background: #f1f1f1;
29. }
[Link][type=text]:focus {
31. background-color: orange;
[Link]: none;
33. }
34. div {
35. padding: 10px 0;
36. }
37. /* The following tag selector button uses the different properti
es for the Button. */
38.
39. button {
40. color: red;
41. padding: 16px 20px;
42. margin: 8px 0;
43. border: none;
44. cursor: pointer;
45. width: 100%;
46.
47. opacity: 0.9;
48.}
49. </style>
50.</head>
51. <body>
52.<form>
53. <div class="container">
54.<center>
55. <h1> Registration Form </h1>
56.</center>
57. <label> Firstname: </label>
58.<input type="text" name="firstname" placeholder= "Enter your Firstnam
e" size="15" required />
59. <label> Middlename: </label>
60.<input type="text" name="middlename" placeholder="Enter your Middle
name" size="15" />
61. <label> Lastname: </label>
62.<input type="text" name="lastname" placeholder="Enter your Lastname
" size="15"required />
63. <div>
64.<label>
65. Gender :
66.</label><br>
67. <input type="radio" value="Male" name="gender" checked
> Male
68.<input type="radio" value="Female" name="gender"> Female
69. <input type="radio" value="Other" name="gender"> Other
70.</div>
71. <label for="email"> Email: <label>
72.<input type="text" placeholder="Enter Your Email ID" name="email" req
uired>
73.
[Link] this example, the disabled attribute is used to disable the Submit button
. If you click on the "Submit Form" button, without filling the values, then it
will not show the constraints included.
75.
76.<button type="submit" value="submit" disabled> Submit Form </
button>
77. </form>
78.</body>
79. </html>
Test it Now
Output:
Example 2: The following example disables the reset button.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of Reset button disabled
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
10.
11. body {
[Link]-family: Calibri, Helvetica, sans-serif;
13. background-color: pink;
14.}
15. /* Following container class used padding for generate space a
round it, and also use a background-color for specify the color lightbl
ue as a background */
16.
17. .container {
[Link]: 50px;
19. background-color: lightblue;
20.}
21. /* The following tag selector input uses the different properties
for the text filed. */
[Link][type=text] {
23. width: 100%;
24. padding: 15px;
25. margin: 5px 0 22px 0;
[Link]: inline-block;
27. border: none;
28. background: #f1f1f1;
29. }
[Link][type=text]:focus {
31. background-color: orange;
[Link]: none;
33. }
34. div {
35. padding: 10px 0;
36. }
37. /* The following tag selector button uses the different properti
es for the Button. */
[Link] {
39. color: red;
40. padding: 16px 20px;
41. margin: 8px 0;
42. border: none;
43. cursor: pointer;
44. width: 100%;
45. opacity: 0.9;
46.}
47. </style>
48.</head>
49. <body>
50.<form>
51. <div class="container">
52.<center>
53. <h1> Registration Form </h1>
54.</center>
55. <label> Firstname: </label>
56.<input type="text" name="firstname" placeholder= "Enter your Firstnam
e" size="15" required />
57. <label> Middlename: </label>
58.<input type="text" name="middlename" placeholder="Enter your Middle
name" size="15" />
59. <label> Lastname: </label>
60.<input type="text" name="lastname" placeholder="Enter your Lastname
" size="15"required />
61. <div>
62.<label>
63. Gender :
64.</label><br>
65. <input type="radio" value="Male" name="gender" checked
> Male
66.<input type="radio" value="Female" name="gender"> Female
67. <input type="radio" value="Other" name="gender"> Other
68.</div>
69. <label for="email"> Email: <label>
70.<input type="text" placeholder="Enter Your Email ID" name="email" req
uired>
71.
[Link] this example, the disabled attribute is used to disable the Reset button.
If you fill the form and then click on the 'Reset a form' button, then it will n
ot reset the values of the above form.
73.
74.<button type="reset" value="submit" disabled> Reset a Form </
button>
75.
76.</form>
77. </body>
78.</html>
Test it Now
Output:
HT
ML font color
The Color is an attribute of <font> tag, which specifies the text color.
Syntax
1. <font color="Color_name|rgb_number|hex_number">
We can specify the text color with the following different attribute values:
o Color_name: This value sets the color of a text by the name of a color.
Example:
1. <font Color="Blue">
o Rgb_number: This value sets the color of a text by the RGB code.
Example:
1. <font color="rgb(128,128,0)"
o Hex_number: This value sets the color of a text by the hex code.
1. <font color="#00FF00">
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of color attribute
6. </title>
7. </head>
8. <body>
9. <font color="orange">
10.<!-- The color attribute of font tag sets the color name 'orange' for the wor
d javaTpoint-->
11. <center>
12.<h1>
13. javaTpoint
14.</h1>
15. </center>
16.</font>
17. </body>
18.</html>
Test it Now
Output:
Example 2: The following example uses the hex code for defining the
text color:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of color attribute
6. </title>
7. </head>
8. <body>
9. <font color="#ff00ff">
10.<!-- The color attribute of font tag sets the color 'magenta' for the word ja
vaTpoint by busing the Hex code "#ff00ff" -->
11. <center>
12.<h1>
13. javaTpoint
14.</h1>
15. </center>
16.</font>
17. </body>
18.</html>
Test it Now
Output:
Example 3: The following example uses the rgb number for defining the
text color:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of color attribute
6. </title>
7. </head>
8. <body>
9. <font color="rgb(0,1,0)">
10.<!-- The color attribute of font tag sets the color 'maroon' for the word jav
aTpoint by using the RGB Number "rgb(0,1,0)" -->
11. <center>
12.<h1>
13. javaTpoint
14.</h1>
15. </center>
16.</font>
17. </body>
18.</html>
Test it Now
Output:
Example 4: The following example uses all the attribute values for the
font color.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of color attribute
6. </title>
7. </head>
8. <body>
9. <center>
10.<h2> The color attribute of font tag sets the color 'maroon' for the followi
ng paragraph by using the RGB Number "rgb(0,1,0)" </h2>
11. </center>
12.<font color="rgb(0,1,0)">
13. <p>
[Link] is an acronym which stands for Hyper Text Markup Language which i
s used for creating web pages and web applications. Let's see what is mea
nt by Hypertext Markup Language, and Web page.
15. </p>
16.</font>
17. <center>
18. <h2> The color attribute of font tag sets the color 'orange' for the followi
ng paragraph by using the name of colour </h2>
19. </center>
20.<font color="orange">
21. <p>
[Link] is an acronym which stands for Hyper Text Markup Language which i
s used for creating web pages and web applications. Let's see what is mea
nt by Hypertext Markup Language, and Web page.
23. </p>
24.</font>
25. <center>
26. <h2> The color attribute of font tag sets the color 'magenta' for the follo
wing paragraph by busing the Hex code "#ff00ff" </h2>
27. </center>
28.<font color="#ff00ff">
29. <p>
[Link] is an acronym which stands for Hyper Text Markup Language which i
s used for creating web pages and web applications. Let's see what is mea
nt by Hypertext Markup Language, and Web page.
31. </p>
32.</font>
33. </body>
34.</html>
Test it Now
Output:
HTML Image Button
The image buttons in the HTML document can be created by using
the type attribute of an <input> element. Image buttons also perform
the same function as submit buttons, but the only difference between
them is that you can keep the image of your choice as a button.
Syntax
1. <input type="image" name="Name of image button" src="Path of
the Image file? border="Specfiy Image Border " alt="text">
Examples
Example 1: This example is used to specify the image button without
using CSS.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of image button
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
[Link] {
11. font-family: Calibri, Helvetica, sans-serif;
12. background-color: pink;
13. }
14./* Following container class used padding for generate space around it, an
d also use a background-color for specifying the lightblue color as a backgr
ound */
15. .container {
16. padding: 50px;
17. background-color: lightblue;
18.}
19. /* The following tag selector input uses the different properties
for specifying the text field. */
[Link][type=text] {
21. width: 100%;
22. padding: 15px;
23. margin: 5px 0 22px 0;
24. display: inline-block;
25. border: none;
26. background: #f1f1f1;
27. }
[Link][type=text]:focus {
29. background-color: orange;
30. outline: none;
31. }
32. div {
33. padding: 10px 0;
34. }
35. hr {
36. border: 1px solid #f1f1f1;
37. margin-bottom: 25px;
38.}
39. </style>
40.</head>
41. <body>
42.<form>
43. <div class="container">
44.<center> <h1> Registration Form</h1> </center>
45. <hr>
46.<label> Firstname: </label>
47. <input type="text" name="firstname" placeholder= "Firstna
me" size="15" required />
48.<label> Middlename: </label>
49. <input type="text" name="middlename" placeholder="Middl
ename" size="15" required />
50.<label> Lastname: </label>
51. <input type="text" name="lastname" placeholder="Lastnam
e" size="15"required />
52.<div>
53. <label>
[Link] :
55. </label>
56.<select>
57. <option value="Course">Course</option>
58.<option value="BCA">BCA</option>
59. <option value="BBA">BBA</option>
60.<option value="[Link]">[Link]</option>
61. <option value="MBA">MBA</option>
62.<option value="MCA">MCA</option>
63. <option value="[Link]">[Link]</option>
64.</select>
65. </div>
66.<div>
67. <label>
[Link] :
69. </label>
70.<br>
71. <input type="radio" value="Male" name="gender" checked
> Male
72.<input type="radio" value="Female" name="gender"> Female
73. <input type="radio" value="Other" name="gender"> Other
74.</div>
75. <!-- The following tag input uses the type attribute which spec
ifies the image, and the src attribute for specifying the path of an im
age, with the height and width attributes. -->
76.<input type="image" src="[Link]
submit_button/[Link]" name="submit" widt
h="100" height="48" alt="submit"/>
77.
78.</form>
79. </body>
80.</html>
Test it Now
Output:
Example 2: This example is used to specify the image button using CSS
style. Its output is also same as the above example but the
implementation is different.
In the following example, we are using the <button> tag for specifying
the image button on a web page.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1">
5. <title>
6. Example of image button
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
[Link] {
11. font-family: Calibri, Helvetica, sans-serif;
12. background-color: pink;
13. }
14./* Following container class used padding for generate space around it, an
d also use a background-color for specifying the lightblue color as a backgr
ound */
15. .container {
16. padding: 50px;
17. background-color: lightblue;
18.}
19. /* The following tag selector input uses the different properties
for specifying the text field. */
[Link][type=text] {
21. width: 100%;
22. padding: 15px;
23. margin: 5px 0 22px 0;
24. display: inline-block;
25. border: none;
26. background: #f1f1f1;
27. }
28./* The following tag selector button uses the different properties for specif
ying the image button on a page. */
29. button {
30. background-image: url(
31. '[Link]
%3AANd9GcTP6zIlxzaUIA_CPMpDXoJXporQUagBpwplwm3tUro3BQD
ZgNaa');
32. width: 230px;
33. height: 150px;
34. }
35.
[Link][type=text]:focus {
37. background-color: orange;
38. outline: none;
39. }
40. div {
41. padding: 10px 0;
42. }
43. hr {
44. border: 1px solid #f1f1f1;
45. margin-bottom: 25px;
46.}
47. </style>
48.</head>
49. <body>
50.<form>
51. <div class="container">
52.<center> <h1> Registration Form</h1> </center>
53. <hr>
54.<label> Firstname: </label>
55. <input type="text" name="firstname" placeholder= "Firstna
me" size="15" required />
56.<label> Middlename: </label>
57. <input type="text" name="middlename" placeholder="Middl
ename" size="15" required />
58.<label> Lastname: </label>
59. <input type="text" name="lastname" placeholder="Lastnam
e" size="15"required />
60.<div>
61. <label>
[Link] :
63. </label>
64.<select>
65. <option value="Course">Course</option>
66.<option value="BCA">BCA</option>
67. <option value="BBA">BBA</option>
68.<option value="[Link]">[Link]</option>
69. <option value="MBA">MBA</option>
70.<option value="MCA">MCA</option>
71. <option value="[Link]">[Link]</option>
72.</select>
73. </div>
74.<div>
75. <label>
[Link] :
77. </label>
78.<br>
79. <input type="radio" value="Male" name="gender" checked
> Male
80.<input type="radio" value="Female" name="gender"> Female
81. <input type="radio" value="Other" name="gender"> Other
82.</div>
83. <button type="submit"> </Button>
84.
85. </form>
86.</body>
87. </html>
Test it Now
Output:
Browser Support
Attributes
Alt:
Border:
This attribute is used to specify the image border. If you put its value as 0,
then no border will be displayed.
Height:
Name:
Src:
This attribute is used to specify the image path which needs to appear as
a button.
Width:
Note: The inner table always has to be placed between the <td> .......... </td> of the
outer table.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>
5. Example of Nested Table
6. </title>
7. </head>
8. <body>
9. <!?The following table tag is used to create outer table on a webpag
e.
[Link] table tag contains two attributes border and bordercolor.
11. The border attribute is used to specify the border (4) of the o
uter table, and the bordercolor is used to specify the green colour of
border of an outer table. -->
12.<table border="4" bordercolor="green">
13. <tr>
14.<td> It is a 1st Cell of 1st row in the 1st Table. </td>
15. <td> It is a 2nd Cell of 1st row in the 1st Table.
16.
17. <!?The following table tag is used to create an inner table whi
ch is shown in the second cell of the first row in the outer table on a
webpage.
[Link] table tag also contains two attributes border and bordercolor.
19. The border attribute is used to specify the border (6) of the in
ner table, and the bordercolor is used to specify the blue colour of b
order of an inner table. -->
20.<table border="6" bordercolor="blue">
21. <tr>
22.<td> It is a 1st Cell of 1st row in the 2nd Table. </td>
23. </tr>
24.<tr>
25. <td> It is a 2nd Cell of 2nd row in the 2nd Table. </td></tr>
26.</table>
27. </td>
28.</tr>
29. <tr>
30.<td> It is a 3rd Cell of 2nd row in the 1st Table. </td>
31. <td> It is a 4th Cell of 2nd row in the 1st Table. </td>
32.</tr>
33. </table>
34.</body>
35. </html>
Test it Now
Output:
HT
ML Interview Questions
A list of top frequently asked HTML interview questions and HTML5
interview questions and answers are given below.
1) What is HTML?
HTML stands for Hyper Text Markup Language. It is a language of World
Wide Web. It is a standard text formatting language which is used to
create and display pages on the Web. It makes the text more interactive
and dynamic. It can turn text into images, tables, links. More details.
ADVERTISEMENT
o content, and
o tags
When a web browser reads an HTML document, the browser reads it from
top to bottom and left to right. HTML tags are used to create HTML
documents and render their properties. Each HTML tags have different
properties.
Syntax
1. <tag> content </tag>
More details.
More details.
Tag Description
<col> It is used with <colgroup> element to specify column properties for each colum
More details.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>HTML Iframes example</h2>
5. <p>Use the height and width attributes to specify the size of the ifr
ame:</p>
6. <iframe src="[Link] height="300" widt
h="400"></iframe>
7. </body>
8. </html>
Syntax
1. <a href = "..........."> Link Text </a>
More details.
16) What is a style sheet?
A style sheet is used to build a consistent, transportable, and well-
designed style template. You can add these templates on several different
web pages. It describes the look and formatting of a document written in
markup language.
ADVERTISEMENT
Following are different HTML5 elements which are used to define the
different parts of a webpage.
o <br> tag - Usually <br> tag is used to separate the line of text. It breaks
the current line and conveys the flow to the next line
o <p> tag - The <p> tag contains the text in the form of a new paragraph.
o <blockquote> tag - It is used to define a large quoted section. If you have
a large quotation, then put the entire text within
<blockquote>.............</blockquote> tag.
Here, replace the "[Link]" with the name of your image file which you
want to display on your web page.
Example:
1. <p>
2. <span style="color:#ffffff;">
3. In this page we use span.
4. </span>
5. </p>
Syntax:
1. <iframe src="URL"></iframe>
Example:
Target to a link:
o Color
o Date
o Datetime-local
o Email
o Time
o Url
o Range
o Telephone
o Number
o Search
o mp4
o WebM
o Ogg
More details.
Let's see the code to play mp3 file using HTML audio tag.
1. <audio controls>
2. <source src="koyal.mp3" type="audio/mpeg">
3. Your browser does not support the html audio tag.
4. </audio>
More details.
1. <figure>
2. <img src="htmlpages/images/[Link]" alt="Taj Mahal"/>
3. <figcaption>Fig.1.1 - A front view of the great Taj Mahal in Agra.</
figcaption>
4. </figure>
More details.
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">
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>
More details.
1. <div id="header">
2. <h1>Monday Times</h1>
3. </div>
4. .
5. .
6. .
7. <div id="footer">
8. <p>© JavaTpoint. All rights reserved.</p>
9. </div>
HTML 5 Header and Footer:
1. <header>
2. <h1>Monday Times</h1>
3. </header>
4. .
5. .
6. .
7. <footer>
8. <p>© JavaTpoint. All rights reserved.</p>
9. </footer>
Menu Example
HTML 4 Menu:
1. <div id="menu">
2. <ul>
3. <li>News</li>
4. <li>Sports</li>
5. <li>Weather</li>
6. </ul>
7. </div>
HTML 5 Menu:
1. <nav>
2. <ul>
3. <li>News</li>
4. <li>Sports</li>
5. <li>Weather</li>
6. </ul>
7. </nav>
Example:
44) What are the new <input> types for form validation in
HTML5?
The new input types for form validation are email, URL, number, tel, and
date.
Example:
1. <input type="email">
Home
HTML
XHTML
CSS
JavaScript
Bootstrap
jQuery
PHP
XML
JSON
Python
C++
Java
C#
SQL
Interview Q
HTML Tutorial
Introduction to HTMLWhat is HTML HTML Text EditorsHTML Building BlocksHTML
tagsHTML AttributesHTML ElementsHTML FormattingHTML HeadingHTML ParagraphHTML
Phrase TagsHTML AnchorHTML ImageHTML TableHTML ListsHTML Ordered ListHTML
Unordered ListHTML Description ListHTML FormHTML Form InputHTML Form
AttributeHTML with CSSHTML ClassesHTML IdHTML IframesHTML JavaScriptHTML
CommentsHTML File PathHTML HeadHTML LayoutHTML Layout TechniquesHTML
ResponsiveHTML ComputercodeHTML EntitiesHTML SymbolsHTML CharsetHTML URL
Encode
HTML Attributes
HTML Global AttributesHTML Event Attributes
HTML5 Advance
HTML5 tutorial
HTML 5 Tags
HTML5 Semantics
HTML5 Migration
HTML Audio
HTML Video
HTML SVG
HTML Canvas
HTML API
HTML Drag & Drop
HTML Geolocation
HTML SS Event
HTML Misc
HTML Button onClick
HTML favicon
HTML Background-color
HTML Date
HTML Id Attribute
What Does HTML Stand ForHow to Insert Image in HTMLHow to Change Font in HTMLHow
to Change Text Color in HtmlHow to Change Background Color in HtmlHow to Comment in
HtmlHow to Link CSS to HtmlHow to add Background Image in HtmlHow to Convert Html
to PDFHow to add Link in HtmlHow to Make a Table in HtmlHow to Change Font Size in
HtmlHow to make a Button in HtmlHow to Add a Favicon in HtmlHow to Change Image
Size in HtmlHow to align text in HtmlHow to align image in HtmlHow to add Video in
HtmlHow to Change Link color in HtmlHow to make an Image a Link in HtmlHow to add
Space in HtmlHow to Embed Youtube Video in HtmlHow to add a Line in HtmlHow to Make
a Dropdown Menu in HtmlHow to call a JavaScript Function in HtmlHow to Create a Form
in HtmlHow to make a List in HtmlHow to Rotate Image in HtmlHow to add jQuery to
HtmlHow to Move Image in HtmlHow to Create Text Box in HtmlHow to move a Text in
HtmlWhat does br mean in htmlHow to add border in HtmlWhat does Div mean in
HtmlHow to Wrap text in HtmlWhat does span do in HtmlHow to make a Navigation Bar in
HtmlHow to use PHP in HtmlHow to Highlight text in HtmlWhat does p mean in HtmlHow
to add Padding in HtmlWhat does ul mean in HtmlHow to add Social Media Icons in
HtmlHow to make a Footer in HtmlHow to make a Search bar in HtmlHow to Wrap Text
around an image in HtmlHTML vs HTML5HTML CounterIntermediate Excel TestDownload
pdf file using HTMLPassword hide in HTMLHTML CalculatorHow to sort table data in HTML
using JavaScriptHTML Color PickerHow to include image in HTMLHTML5 signature pad to
imagehidden vs aria-hidden attributes in HTMLHow to mute video in HTMLHTML vs
ASPHTML 5 Spellcheck attributeHTML 5 accept attributeHTML Color StylesHow to add a
Vertical Line in HtmlHow to create an Email Newsletter using HTML and CSSHow to align
a placeholder text in HTMLHow to Create Browsers Window using HTML and CSSConvert
an Image into Grayscale Image using HTML/CSSHide or Show Elements in HTML using
Display PropertyHow to Add a Login Form to an Image using HTML and CSS How to Set
the Margins of a Paragraph Element using CSSHow to Add Google Translate Button on
Your Webpagebody alink Attribute in HTMLBasics of AnimationDesign a Tribute Page using
HTML and CSSHow to Make Smooth Bounce Animation Using CSSHTML blink TagHow to
Create A Discord BOTHow to Divide Html Page Into Two Parts Vertically And
HorizontallyHow to Make A Responsive Website For All DevicesHow to create a simple
webpage using [Link]? (For Beginners)Simple Calculator in HTML using eval() in
JavaScript and CSSAdd and Delete rows of a table on button clicksHow to submit a HTML
form using JavaScriptSimple Calculator in HTML using for loopsCalculator using Shunting
yard algorithm in HTML using JavaScriptDifferent ways to build a calculator in HTML using
JavaScriptPublishing your Calculator website using Github pages (Beginner level) Move an
image on button clicks in HTML using CSS and JavaScript What is Public_html
directoryHow to hide scrollbar in htmlHow to Login [Link] Basics TagHTML
Code for WebsiteHTML CSSHTML to JPGHow Web 3 Will Transform Our LivesTop web 3.0
benefits
MCQ
HTML MCQ
Interview Questions
HTML Interview Questions
Syntax
1. <font size="number">
In the above syntax, the number is a value of the Size attribute, which
denotes the text size. The number for the font size is lies between the 1
and 7. By default, the font size of a text on a web page is 3.
Note: The size attribute of <font> tag is not supported in HTML5. We can use CSS
instead of it.
1. <!DOCTYPE html>
2. <html>
3. <title>
4. Example of Size attribute
5. </title>
6. <body>
7. <Center>
8. <font size="1">
9. JavaTpoint Size = "1"
10.</font>
11. <br>
12.<font size="2">
13. JavaTpoint Size = "2"
14.</font>
15. <br>
16.<font size="3">
17. JavaTpoint Size = "3"
18.</font>
19. <br>
20.<font size="4">
21. JavaTpoint Size = "4"
22.</font>
23. <br>
24.<font size="5">
25. JavaTpoint Size = "5"
26.</font>
27. <br>
28.<font size="6">
29. JavaTpoint Size = "6"
30.</font>
31. <br>
32.<font size="7">
33. JavaTpoint Size = "7"
34.</font>
35. </Center>
36.</body>
37. </html>
Test it Now
Output:
Output:
1. <button type="button|submit|reset">
5. <title>
6. Example of Button Type
7. </title>
8. <style>
9. /* The following tag selector body use the font-family and backgroun
d-color properties for body of a page*/
10.
11. body {
[Link]-family: Calibri, Helvetica, sans-serif;
13. background-color: pink;
14.}
15. /* Following container class used padding for generate space a
round it, and also use a background-color for specify the color lightbl
ue as a background */
16.
17. .container {
[Link]: 50px;
19. background-color: lightblue;
20.}
21. /* The following tag selector input use the different properties
for the text filed. */
[Link][type=text] {
23. width: 100%;
24. padding: 15px;
25. margin: 5px 0 22px 0;
[Link]: inline-block;
27. border: none;
28. background: #f1f1f1;
29. }
30.
31. input[type=text]:focus {
[Link]-color: orange;
33. outline: none;
34.}
35. div {
36. padding: 10px 0;
37. }
[Link] {
39. border: 1px solid #f1f1f1;
40. margin-bottom: 25px;
41. }
42./* The following tag selector button use the different properties for the But
ton. */
43. button {
44. background-color: #4CAF50;
45. padding: 16px 20px;
46. margin: 8px 0;
47. border: none;
48. cursor: pointer;
49. color: white;
50. width: 100%;
51. opacity: 0.9;
52.}
53. /* The following tag selector hover use the opacity property fo
r the Button which select button when you mouse over it. */
[Link]:hover {
55. opacity: 1;
56.}
57. </style>
58.</head>
59. <body>
60.<form>
61. <div class="container">
62.<center> <h1> Registration Form</h1> </center>
63.
64.<hr>
65. <label > Firstname </label>
66.<input type="text" name="firstname" placeholder= "Firstname" size="1
5" required />
67. <label> Middlename: </label>
68.<input type="text" name="middlename" placeholder="Middlename" size
="15" required />
69. <label> Lastname: </label>
70.<input type="text" name="lastname" placeholder="Lastname" size="15
"required />
71.
72.<div>
73. <label>
[Link] :
75. </label><br>
76.<input type="radio" value="Male" name="gender" checked > Male
77. <input type="radio" value="Female" name="gender"> Fema
le
78.<input type="radio" value="Other" name="gender"> Other
79.
80.</div>
81. <label>
[Link] :
83. </label>
84.<input type="text" name="country code" placeholder="Country Code" v
alue="+91" size="2"/>
85. <input type="text" name="phone" placeholder="phone no."
size="10"/ required>
86.
87.
88.<label for="email"><b>Email</b></label>
89. <input type="text" placeholder="Enter Email" id="email" na
me="email" required>
90.
91. The below button displays as the submit button, which is used
to submit the form.
92.
93. <button type="submit" value="submit">Submit</button>
94.
95. The below button displays the reset button, which is used to r
eset the form to its initial values.
96.
97. <button type="reset" value="reset">Reset</button>
98.
99. The below button displays a message on a web page when yo
u click on it. After clicking on a button, a function is called from the s
cript tag.
100.
101. <button type="button" onclick="sfun()"> Print a Simple Mes
sage </button>
102. <script>
103. function sfun()
104. {
105. [Link]("Hello Javatpoint");
106. }
107. </script>
108. </form>
109. </body>
110. </html>
Test it Now
Output: