HTml sdfsd
HTml sdfsd
HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of HTML. Our HTML tutorial is
developed for beginners and professionals. In our tutorial, every topic is given step-by-step so that you
can learn it in a very easy way. If you are new in learning HTML, then you can learn HTML from basic to
a professional level and after learning HTML with CSS and JavaScript you will be able to create your
own interactive and dynamic website. But Now We will focus on HTML only in this tutorial.
12.8K
6. MVC Model & PHP Singleton pattern | Build a CMS using OOP PHP tutorial MVC [2020]
Next
Stay
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
HTML 5 Tags
In this tutorial, we will learn HTML 5 tags such as audio tag, video tag, canvas tag, HTML svg, HTML
geolocation, HTML drag and drop etc.
Prerequisite
Before learning HTML, you must have the basic knowledge of Computer Fundamental.
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.
Markup language: A markup language is a computer language that is used to apply layout and
formatting conventions to a text document. Markup language makes text more interactive and
dynamic. It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated by a web
browser. A web page can be identified by entering an URL. A Web page can be of the static or dynamic
type. With the help of HTML only, we can create static web pages.
Hence, HTML is a markup language which is used for creating attractive web pages with the help of
styling, and which looks in a nice format on a web browser. An HTML document is made of many HTML
tags and each HTML tag contains different content.
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)
<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.
2) It is very easy to make an effective presentation with HTML because it has a lot of formatting
tags.
3) It is a markup language, so it provides a flexible way to design web pages along with the text.
4) It facilitates programmers to add a link on the web pages (by html anchor tag), so it enhances the
interest of browsing of the user.
5) It is platform-independent because it can be displayed on any platform like Windows, Linux, and
Macintosh, etc.
6) It facilitates the programmer to add Graphics, Videos, and Sound to the web pages which makes
it more attractive and interactive.
7) HTML is a case-insensitive language, which means we can use tags either in lower-case or upper-
case.
NOTE: It is recommended to write all tags in lower-case for consistency, readability, etc.
Notepad is a simple text editor and suitable for beginners to learn HTML. It is available in all versions of
Windows, from where you easily access it.
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 https://www.sublimetext.com/download 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 open Sublime Text editor go to Start screen ⤏ type Sublime Text⤏ Open it. To open a new page
press CTRL+N.
To save your page in Sublime Text press Ctrl+S or go to File option ⤏ save, to save a file use
extension .htm or .html. We recommend to save the file first then write the code because after saving
the page sublime text editor will give you suggestions to write code.
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.
← PrevNext →
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
Example:
<!DOCTYPE html>
<html>
<head>
<title>The basic building blocks of HTML</title>
</head>
<body>
<h2>The building blocks</h2>
<p>This is a paragraph tag</p>
<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:
← PrevNext →
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
Note: HTML Tags are always written in lowercase letters. The basic HTML tags are given below:
Test it Now
Some HTML tags are not closed, for example br and hr.
<br> Tag: br stands for break line, it breaks the line of the code.
<hr> Tag: hr stands for Horizontal Rule. This tag is used to put a line across the webpage.
<p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <strong>, <em>, <abbr>, <acronym>, <address>,
<bdo>, <blockquote>, <cite>, <q>, <code>, <ins>, <del>, <dfn>, <kbd>, <pre>, <samp>, <var>
and <br>
table, tr, td, th, tbody, thead, tfoot, col, colgroup and caption
form, input, textarea, select, option, optgroup, button, label, fieldset and legend
<aside> It defines content aside from main content. Mainly represented as sidebar.
<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 of
document. (Not supported in HTML5)
<bdi> This tag is used to provide isolation for that part of text which may be formatted in
different directions from its surrounding text.
<big> This tag is used to make font size one level larger than its surrounding
content. (Not supported in HTML5)
<blockquote It is used to define a content which is taken from another source.
>
<cite> It is used to define the title of the work, book, website, etc.
<col> It defines a column within a table which represent common properties of columns
and used with the <colgroup> element.
<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)
<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 in
HTML5)
<frame> It defines a particular area of webpage which can contain another HTML file. (Not
supported in HTML5)
<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 in
HTML5)
<noframes> It provides alternate content to represent in browser which does not support the
<frame> elements. (Not supported in HTML5)
<picture> It defines more than one source element and one image element.
<rp> It defines an alternative content if browser does not supports ruby annotations.
<source>> It defines multiple media recourses for different media element such as <picture>,
<video>, and <audio> element.
<strike> It is used to render strike through the text. (Not supported in HTML5)
<table> It is used to present data in tabular form or to create a table within HTML document.
<tbody> It represents the body content of an HTML table and used along with <thead> 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 page
load and may render later using JavaScript.
<textarea> It is used to define multiple line input, such as comment, feedback, and review, etc.
<track> It is used to define text tracks for <audio> and <video> elements.
HTML Attribute
o HTML attributes are special words which provide additional information about the elements or
attributes are the modifier of the HTML element.
o Each element or tag can have attributes, which defines the behaviour of that element.
o Attributes should always be applied with start tag.
o The Attribute should always be applied with its name and value pair.
o The Attributes name and values are case sensitive, and it is recommended by W3C that it
should be written in Lowercase only.
o You can add multiple attributes in one HTML element, but need to give space between two
attributes.
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 element</p>
8. <p style="color: red">It will change the color of content</p>
9. </body>
10. </html>
Test it Now
Output:
In the above statement, we have used paragraph tags in which we have applied style attribute. This
attribute is used for applying CSS property on any HTML element. It provides height to paragraph
element of 50px and turns it colour to blue.
In the above statement we have again used style attribute in paragraph tag, which turns its colour red.
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:
1. <p title="This is paragraph tag">Move the cursor over the heading and paragraph, and you will see a
description as a tooltip</p>
Test it Now
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:
Example
With link address:
Example
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.
← PrevNext →
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.
Some Void elements are <br> (represents a line break) , <hr>(represents a horizontal
line), etc.
Nested HTML Elements: HTML can be nested, which means an element can contain another
element.
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.
<address>, <article>, <aside>, <blockquote>, <canvas>, <dd>, <div>, <dl>, <dt>, <fieldset>,
<figcaption>, <figure>, <footer>, <form>, <h1>-<h6>, <header>, <hr>, <li>, <main>, <nav>,
<noscript>, <ol>, <output>, <p>, <pre>, <section>, <table>, <tfoot>, <ul> and <video>.
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.
<a>, <abbr>, <acronym>, <b>, <bdo>, <big>, <br>, <button>, <cite>, <code>, <dfn>, <em>,
<i>, <img>, <input>, <kbd>, <label>, <map>, <object>, <q>, <samp>, <script>, <select>,
<small>, <span>, <strong>, <sub>, <sup>, <textarea>, <time>, <tt>, <var>.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <a href="https://www.javatpoint.com/html-tutorial">Click on link</a>
7. <span style="background-color: lightblue">this is inline element</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 the
<h6> of HTML h6> headings of page.
<p> This is the paragraph </p> This element is used to display a content in
form of paragraph.
<div> This is div section </div> This element is used to provide a section in
web page.
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.
<tt> This tag is used to appear a text in teletype. (not supported in HTML5)
<strike> This tag is used to draw a strikethrough on a section of text. (Not supported in
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.
See this example:
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:
Output:
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.
See this example:
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.
Output:
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.
See this example:
Output:
9) Deleted Text
Anything that puts within <del>..........</del> is displayed as deleted text.
Output:
Hello
Output:
Output:
← PrevNext →
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.
Markup language: A markup language is a computer language that is used to apply layout and
formatting conventions to a text document. Markup language makes text more interactive and
dynamic. It can turn text into images, tables, links, etc.
Web Page: A web page is a document which is commonly written in HTML and translated by a web
browser. A web page can be identified by entering an URL. A Web page can be of the static or dynamic
type. With the help of HTML only, we can create static web pages.
Hence, HTML is a markup language which is used for creating attractive web pages with the help of
styling, and which looks in a nice format on a web browser. An HTML document is made of many HTML
tags and each HTML tag contains different content.
Let's see a simple example of 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 > :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)
<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.
Tim Berners-Lee is known as the father of HTML. The first available description of HTML was a
document called "HTML Tags" proposed by Tim in late 1991. The latest version of HTML is HTML5,
which we will learn later in this tutorial.
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.
2) It is very easy to make an effective presentation with HTML because it has a lot of formatting
tags.
3) It is a markup language, so it provides a flexible way to design web pages along with the text.
4) It facilitates programmers to add a link on the web pages (by html anchor tag), so it enhances the
interest of browsing of the user.
5) It is platform-independent because it can be displayed on any platform like Windows, Linux, and
Macintosh, etc.
6) It facilitates the programmer to add Graphics, Videos, and Sound to the web pages which makes
it more attractive and interactive.
7) HTML is a case-insensitive language, which means we can use tags either in lower-case or upper-
case.
NOTE: It is recommended to write all tags in lower-case for consistency, readability, etc.
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.
Headings in HTML helps the search engine to understand and index the structure of web
page.
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 keyword 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:
<p>
I am
going to provide
you a tutorial on HTML
and hope that it will
be very beneficial for you.
</p>
<p>
Look, I put here a lot
10. of 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.
Example:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2> Use of line break with pragraph tag</h2>
<p><br>Papa and mama, and baby and Dot,
<br>Willie and me?the whole of the lot
<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:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h2> Example to show a horizontal line with paragraphs</h2>
<p> An HTML hr tag draw a horizontal line and separate two paragraphs with that line.<hr> it will s
tart a new paragraph.
</p>
</body>
10. </html>
Test it Now
Output:
Supporting Browsers
← PrevNext →
Example
<p>An <abbr title = "Hypertext Markup language">HTML </abbr>language is used to create web pa
ges. </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
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
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.
Example
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
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
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:
<p>Steve Jobs said: <q>If You Are Working On Something That You Really Care About, You Don?t Hav
e To Be Pushed. The Vision Pulls You.</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:
10. Address tag
An HTML <address> tag defines the contact information about the author of the content. The content
written between <address> and </address> tag, then it will be displayed in italic font.
Output:
← PrevNext →
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.
The href attribute is used to define the address of the file to be linked. In other words, it points out the
destination page.
Example:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p>Click on <a href="https://www.javatpoint.com/" target="_blank"> this-link </a>to go on home pa
ge of JavaTpoint.</p>
</body>
</html>
Test it Now
Output:
Note:
o The target attribute can only use with href attribute in anchor tag.
o If we will not use target attribute then link will open in same page.
Supporting Browsers
← PrevNext →
HTML Image
HTML img tag is used to display image on the web page. HTML img tag is an empty tag that contains
attributes only, closing tags are not used in HTML image element.
Output:
HTML Tutorial
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:
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:
How to get image from another directory/folder?
To insert an image in your web, that image must be present in your same folder where you have put
the HTML file. But if in some case image is available in some other directory then you can access the
image like this:
Note: If src URL will be incorrect or misspell then it will not display your image on web page, so try to put correct URL.
Example:
← PrevNext →
HTML Table
HTML table tag is used to display data in tabular form (row * column). There can be many columns in
a row.
We can create a table to display data in tabular form, using <table> element, with the help of <tr> ,
<td>, and <th> elements.
In Each table, table row is defined by <tr> tag, table header is defined by <th>, and table data is
defined by <td> tags.
HTML tables are used to manage the layout of the page e.g. header section, navigation bar, body
content, footer section etc. But it is recommended to use div tag over table to manage the layout of
the page .
Tag Description
<col> It is used with <colgroup> element to specify column properties for each column.
1. <table>
2. <tr><th>First_Name</th><th>Last_Name</th><th>Marks</th></tr>
3. <tr><td>Sonoo</td><td>Jaiswal</td><td>60</td></tr>
4. <tr><td>James</td><td>William</td><td>80</td></tr>
5. <tr><td>Swati</td><td>Sironi</td><td>82</td></tr>
6. <tr><td>Chetna</td><td>Singh</td><td>72</td></tr>
7. </table>
Test it Now
Output:
In the above html table, there are 5 rows and 3 columns = 5 * 3 = 15 values.
You can use border attribute of table tag in HTML to specify border. But it is not recommended now.
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
You can collapse all the borders in one border by border-collapse property. It will collapse the border
into one.
1. <style>
2. table, th, td {
3. border: 2px solid black;
4. border-collapse: collapse;
5. }
6. </style>
Test it Now
Output:
The cellpadding attribute of HTML table tag is obselete now. It is recommended to use CSS. So let's see
the code of CSS.
1. <style>
2. table, th, td {
3. border: 1px solid pink;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 10px;
8. }
9. </style>
Test it Now
Output:
Sonoo Jaiswal 60
James William 80
Swati Sironi 82
Chetna Singh 72
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:
HTML Table with colspan
If you want to make a cell span more than one column, you can use the colspan attribute.
It will divide one cell/row into multiple columns, and the number of columns depend on the value of
colspan attribute.
CSS code:
1. <style>
2. table, th, td {
3. border: 1px solid black;
4. border-collapse: collapse;
5. }
6. th, td {
7. padding: 5px;
8. }
9. </style>
HTML code:
1. <table style="width:100%">
2. <tr>
3. <th>Name</th>
4. <th colspan="2">Mobile No.</th>
5. </tr>
6. <tr>
7. <td>Ajeet Maurya</td>
8. <td>7503520801</td>
9. <td>9555879135</td>
10. </tr>
11. </table>
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
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
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.
The HTML definition list contains following three tags:
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
Bingo
Leo
Oracle
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:
Supporting Browsers
To represent different ordered lists, there are 5 types of attributes in <ol> tag.
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:
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="A" start="5"> : It will show capital alphabets starting with "E".
<ol type="a" start="5"> : It will show lower case alphabets starting with "e".
<ol type="I" start="5"> : It will show Roman upper case value starting with "V".
<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:
Supporting Browsers
← PrevNext →
o disc
o circle
o square
o none
To represent different ordered lists, there are 4 types of attributes in <ul> tag.
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 .
1. <ul>
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="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:
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:
Supporting Browsers
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
Supporting Browsers
← PrevNext →
HTML Form
An HTML form is a section of a document which contains controls such as text fields, password
fields, checkboxes, radio buttons, submit button, menus etc.
An HTML form facilitates the user to enter data that is to be sent to the server for processing such as
name, email address, password, phone number, etc. .
For example: If a user want to purchase some items on internet, he/she must fill the form such as
shipping address and credit/debit card details so that item can be sent to the given address.
Tag Description
Tag Description
Note: The <form> element does not itself create a form but it is container to contain all required form elements, such as <input>,
<label>, etc.
Syntax:
<form>
//Form elements
</form>
Example:
<body>
<form>
Enter your name <br>
<input type="text" name="username">
</form>
</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.
<form>
First Name: <input type="text" name="firstname"/> <br/>
Last Name: <input type="text" name="lastname"/> <br/>
</form>
Output:
Note: If you will omit 'name' attribute then the text filed input will not be submitted to server.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<form>
Enter your address:<br>
<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.
<form>
<label for="firstname">First Name: </label> <br/>
<input type="text" id="firstname" name="firstname"/> <br/>
<label for="lastname">Last Name: </label>
<input type="text" id="lastname" name="lastname"/> <br/>
</form>
Output:
<form>
<label for="password">Password: </label>
<input type="password" id="password" name="password"/> <br/>
</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.
<form>
<label for="email">Email: </label>
<input type="email" id="email" name="email"/> <br/>
</form>
Note: If we will not enter the correct email, it will display error like:
Radio Button Control
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.
<form>
<label for="gender">Gender: </label>
<input type="radio" id="gender" name="gender" value="male"/>Male
<input type="radio" id="gender" name="gender" value="female"/>Female <br/>
</form>
Checkbox Control
The checkbox control is used to check multiple options from given checkboxes.
<form>
Hobby:<br>
<input type="checkbox" id="cricket" name="cricket" value="cricket"/>
<label for="cricket">Cricket</label> <br>
<input type="checkbox" id="football" name="football" value="football"/>
<label for="football">Football</label> <br>
<input type="checkbox" id="hockey" name="hockey" value="hockey"/>
<label for="hockey">Hockey</label>
</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:
<form>
<label for="name">Enter name</label><br>
<input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br>
<input type="Password" id="pass" name="pass"><br>
<input type="submit" value="submit">
</form>
Output:
Example:
<form>
<fieldset>
<legend>User Information:</legend>
<label for="name">Enter name</label><br>
<input type="text" id="name" name="name"><br>
<label for="pass">Enter Password</label><br>
<input type="Password" id="pass" name="pass"><br>
<input type="submit" value="submit">
</fieldset>
10. lt;/form>
Output:
<!DOCTYPE html>
<html>
<head>
<title>Form in HTML</title>
</head>
<body>
<h2>Registration form</h2>
<form>
<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:
<form action="#">
<table>
<tr>
<td class="tdLabel"><label for="register_name" class="label">Enter name:</label></td>
<td><input type="text" name="name" value="" id="register_name" style="width:160px"/></
td>
</tr>
<tr>
<td class="tdLabel"><label for="register_password" class="label">Enter password:</label></
td>
<td><input type="password" name="password" id="register_password" 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_gendermale" value="male"/>
20. <label for="register_gendermale">male</label>
21. <input type="radio" name="gender" id="register_genderfemale" value="female"/>
22. <label for="register_genderfemale">female</label>
23. </td>
24. </tr>
25. <tr>
26. <td class="tdLabel"><label for="register_country" class="label">Select Country:</label></td>
← PrevNext →
Next →← Prev
button Defines a simple push button, which can be programmed to perform a task on an event.
file Defines to select the file from device storage.
HTML5 added new types on <input> element. Following is the list of types of elements of
HTML5
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:
<form>
<label>Enter first name</label><br>
<input type="text" name="firstname"><br>
<label>Enter last name</label><br>
<input type="text" name="lastname"><br>
<p><strong>Note:</strong>The default maximum cahracter lenght is 20.</p>
</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:
<form>
<label>Enter User name</label><br>
<input type="text" name="firstname"><br>
<label>Enter Password</label><br>
<input type="Password" name="password"><br>
<br><input type="submit" value="submit">
</form>
Test it Now
Output:
The "password"field defines a sinlge line input password field to enter the password securely.
Enter Password
submit
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:
<form action="https://www.javatpoint.com/html-tutorial">
<label>Enter User name</label><br>
<input type="text" name="firstname"><br>
<label>Enter Password</label><br>
<input type="Password" name="password"><br>
<br><input type="submit" value="submit">
</form>
Test it Now
Output:
Enter Password
submit
After clicking on submit button, this will submit the form to server and will redirect the page
to action value.We 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:
<form>
<label>User id: </label>
<input type="text" name="user-id" value="user">
<label>Password: </label>
<input type="password" name="pass" value="pass"><br><br>
<input type="submit" value="login">
<input type="reset" value="Reset">
</form>
Test it Now
Output:
login Reset
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:
<form>
<p>Kindly Select your favorite color</p>
<input type="radio" name="color" value="red"> Red <br>
<input type="radio" name="color" value="blue"> blue <br>
<input type="radio" name="color" value="green">green <br>
<input type="radio" name="color" value="pink">pink <br>
<input type="submit" value="submit">
</form>
Test it Now
Output:
Red
blue
green
pink
submit
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:
<form>
<label>Enter your Name:</label>
<input type="text" name="name">
<p>Kindly Select your favourite sports</p>
<input type="checkbox" name="sport1" value="cricket">Cricket<br>
<input type="checkbox" name="sport2" value="tennis">Tennis<br>
<input type="checkbox" name="sport3" value="football">Football<br>
<input type="checkbox" name="sport4" value="baseball">Baseball<br>
<input type="checkbox" name="sport5" value="badminton">Badminton<br><br>
10. <input type="submit" value="submit">
11. </form>
Test it Now
Output:
Registration Form
Enter your Name:
Cricket
Tennis
Football
Baseball
Badminton
submit
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.
Example:
<form>
<input type="button" value="Clcik me " onclick="alert('you are learning HTML')">
</form>
Test it Now
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:
<form>
<label>Select file to upload:</label>
<input type="file" name="newfile">
<input type="submit" value="submit">
</form>
Test it Now
Output:
submit
Select file to upload:
9. <input type="image">:
The <input> type "image" is used to represent a submit button in the form of image.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Input "image" type.</h2>
<p>We can create an image as submit button</p>
<form>
<label>User id:</label><br>
<input type="text" name="name"><br><br>
<input type="image" alt="Submit" src="login.png" width="100px">
10. </form>
11.
12. </body>
13. </html>
1. <input type="color">:
The <input> type "color" is used to define an input field which contains a colour. It allows a user to
specify the colour by the visual colour interface on a browser.
Note: The "color" type only supports color value in hexadecimal format, and the default value is #000000 (black).
Example:
<form>
Pick your Favorite color: <br><br>
<input type="color" name="upclick" value="#a52a2a"> Upclick<br><br>
<input type="color" name="downclick" value="#f5f5dc"> Downclick
</form>
Test it Now
Output:
Up-click
Down-click
Note:The default value of "color" type is #000000 (black). It only supports color value in hexadecimal
format.
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:
<form>
Select Start and End Date: <br><br>
<input type="date" name="Startdate"> Start date:<br><br>
<input type="date" name="Enddate"> End date:<br><br>
<input type="submit">
</form>
Test it Now
Output:
Start date:
End date:
Submit
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:
<form>
<label>
Select the meeting schedule: <br><br>
Select date & time: <input type="datetime-local" name="meetingdate"> <br><br>
</label>
<input type="submit">
</form>
Test it Now
Output:
Submit
4. <input type="email">:
The <input> type "email" creates an input filed which allow a user to enter the e-mail address with
pattern validation. The multiple attributes allow a user to enter more than one email address.
Example:
<form>
<label><b>Enter your Email-address</b></label>
<input type="email" name="email" required>
<input type="submit">
<p><strong>Note:</strong>User can also enter multiple email addresses separating by comm
a or whitespace as following: </p>
<label><b>Enter multiple Email-addresses</b></label>
<input type="email" name="email" multiple>
<input type="submit">
</form>
Test it Now
Output:
Note:User can also enter multiple email addresses separating by comma or whitespace as following:
Submit
Enter multiple Email-addresses
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:
<form>
<label>Enter your Birth Month-year: </label>
<input type="month" name="newMonth">
<input type="submit">
</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:
<form>
<label>Enter your age: </label>
<input type="number" name="num" min="50" max="80">
<input type="submit">
</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:
<form>
<label>Enter your website URL: </label>
<input type="url" name="website" placeholder="http://example.com"><br>
<input type="submit" value="send data">
</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:
<form>
<label><b>Select your best week of year:</b></label><br><br>
<input type="week" name="bestweek">
<input type="submit" value="Send data">
</form>
Test it Now
Output:
Send data
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:
<form>
<label>Search here:</label>
<input type="search" name="q">
<input type="submit" value="search">
</form>
Test it Now
Output:
The <input> element of type ?tel? creates an input filed to enter the telephone number. The "tel" type
does not have default validation such as email, because telephone number pattern can vary worldwide.
Example:
<form>
<label><b>Enter your Telephone Number(in format of xxx-xxx-xxxx):</b></label>
<input type="tel" name="telephone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required>
<input type="submit"><br><br>
</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.
← PrevNext →
The action attribute of <form> element defines the process to be performed on form when form is
submitted, or it is a URI to process the form information.
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="action.html" 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
Submit
It will redirect to a new page "action.html" when you click on submit button
The method attribute defines the HTTP method which browser used to submit the form. The possible
values of method attribute can be:
o post: We can use the post value of method attribute when we want to process the sensitive
data as it does not display the submitted data in URL.
Example:
1. <form action="action.html" 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="action.html" method="get">
When submitting the data, it will display the entered data in the form of:
1. file:///D:/HTML/action.html?name=JavaTPoint&pass=123
The target attribute defines where to open the response after submitting the form. The following are
the keywords used with the target attribute.
o _self: If we use _self as an attribute value, then the response will display in current page only.
Example:
1. <form action="action.html" 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="action.html" method="get" target="_blank">
The HTML autocomplete attribute is a newly added attribute of HTML5 which enables an input field to
complete automatically. It can have two values "on" and "off" which enables autocomplete either ON
or OFF. The default value of autocomplete attribute is "on".
Example:
1. <form action="action.html" method="get" autocomplete="on">
Example:
1. <form action="action.html" method="get" autocomplete="off">
Note: it can be used with <form> element and <input> element both.
The HTML enctype attribute defines the encoding type of form-content while submitting the form to
the server. The possible values of enctype can be:
Example:
1. <form action="action.html" 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="action.html" 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="action.html" method="post" enctype="text/plain" >
The novalidate attribute is newly added Boolean attribute of HTML5. If we apply this attribute in form
then it does not perform any type of validation and submit the form.
Example:
1. <form action = "action.html" method = "get" novalidate>
Test it Now
Output:
Enter age:
Enter email:
Submit
Try to change the form detials with novalidate atttribute and without novalidate attribute
and see the difference.
The HTML name attribute defines the name of an input element. The name and value attribute are
included in HTTP request when we submit the form.
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 = "action.html" 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:
Submit
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
The HTML value attribute defines the initial value or default value of an input field.
Example:
1. <form>
2. <label>Enter your Name</label><br>
3. <input type="text" name="uname" value="Enter Name"><br><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:
login
Note: In password input filed the value attribute will always unclear
HTML required is a Boolean attribute which specifies that user must fill that filed before submitting the
form.
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:
login
If you will try to submit the form without completing email field then it will give an error
pop up.
HTML autofocus attribute HTML5
The autofocus is a Boolean attribute which enables a field automatically focused when a webpage
loads.
Example:
1. <form>
2. <label>Enter your Email-address</label><br>
3. <input type="text" name="uname" autofocus><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>
The placeholder attribute specifies a text within an input field which informs the user about the
expected input of that filed.
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="[email protected]"><br><br>
6. <label>Enter your password</label><br>
7. <input type="password" name="pass" placeholder="your password"><br><br>
8. <input type="submit" value="login">
9. </form>
Test it Now
Output:
Registration form
Enter your name
The HTML disabled attribute when applied then it disable that input field. The disabled field does not
allow the user to interact with that field.
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
USER
login
The size attribute controls the size of the input field in typed characters.
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
login
HTML form attribute allows a user to specify an input filed outside the form but remains the part of the
parent form.
Example:
1. User email: <br><input type="email" name="email" form="fcontrol" 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:
Submit
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.
CSS provides various style properties such as background color, padding, margin, border-color, and
many more, to style a webpage.
Each property in CSS has a name-value pair, and each property is separated by a semicolon (;).
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 technolog
ies in very simple way. </p>
4. </body>
Test it Now
In the above example, we have used a style attribute to provide some styling format to our code.
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:
An Internal stylesheets contains the CSS properties for a webpage in <head> section of HTML
document. To use Internal CSS, we can use class and id attributes.
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="style.css">
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;
}
padding padding: 20px; It defines the space between content and the
border.
Font-size font-size: 50px; Font-size defines a font size for a particular element.
HTML Classes
Class Attribute in HTML
The HTML class attribute is used to specify a single or multiple class names for an HTML element. The
class name can be used by CSS and JavaScript to do some tasks for HTML elements. You can use this
class in CSS with a specific class, write a period (.) character, followed by the name of the class for
selecting elements.
A class attribute can be defined within <style> tag or in separate file using the (.) character.
In an HTML document, we can use the same class attribute name with different elements.
To create an HTML class, firstly define style for HTML class using <style> tag within <head> section as
following example:
History of Java
Example:
1. <head>
2. <style>
3. .headings{
4. color: lightgreen;
5. font-family: cursive;
6. background-color: black; }
7. </style>
8. </head>
We have define style for a class name "headings", and we can use this class name with any of HTML
element in which we want to provide such styling. We just need to follow the following syntax to use it.
Example 1:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. .headings{
6. color: lightgreen;
7. font-family: cursive;
8. background-color: black; }
9. </style>
10. </head>
11. <body>
12. <h1 class="headings">This is first heading</h1>
13. <h2 class="headings">This is Second heading</h2>
14. <h3 class="headings">This is third heading</h3>
15. <h4 class="headings">This is fourth heading</h4>
16. </body>
17. </html>
Test it Now
Another Example with different class name
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.
You can use JavaScript access elements with a specified class name by using the
getElementsByClassName() method.
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 = document.getElementsByClassName("fruit");
23. for (var i = 0; i < x.length; i++) {
24. x[i].style.display = "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 "cent
er", which center-aligns the text.</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.
You can use the same class name with different tags like <h2> and <p> etc. to share the same style.
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">
Example 1: The following example describes how to use the id attribute in CSS document:
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;
10. background-color: lightblue;
11. color: black;
12. text-align: center;
13. }
14.
15. #Bikes
16. {
17. padding: 50px;
18. background-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:
Example 2: The following example describes how to use the ID attribute in JavaScript.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title> Date Attribute </title>
5. <script>
6. function viewdate() {
7. var x = document.getElementById("dob").value;
8. document.getElementById("demo").innerHTML = x;
9. </script>
10. </head>
11. <body>
12. Employee 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:
Browser Support
An HTML iframe embeds another document within the current HTML document in the rectangular
region.
The webpage content and iframe contents can interact with each other using JavaScript.
Iframe Syntax
C++ vs Java
<iframe src="URL"></iframe>
Here, "src" attribute specifies the web address (URL) of the inline frame page.
Example: (Pixels)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes example</h2>
<p>Use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="300" width="400"></iframe>
</body>
</html>
Test it Now
Example: (Percentage)
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>You can use the height and width attributes to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" height="50%" width="70%"></iframe>
</body>
</html>
Test it Now
You can also use CSS to set the height and width of the iframe.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Iframes</h2>
<p>Use the CSS height and width properties to specify the size of the iframe:</p>
<iframe src="https://www.javatpoint.com/" style="height:300px;width:400px"></iframe>
</body>
</html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Remove the Iframe Border</h2>
<p>This iframe example doesn't have any border</p>
<iframe src="https://www.javatpoint.com/" style="border:none;"></iframe>
</body>
</html>
Test it Now
You can also change the size, color, style of the iframe's border.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Custom Iframe Border</h2>
<iframe src="https://www.javatpoint.com/" style="border:2px solid tomato;"></iframe>
</body>
</html>
Test it Now
10. </body>
11. </html>
Test it Now
Output
<!DOCTYPE html>
<html>
<head>
<style>
p{ font-size: 50px;
color: red;}
</style>
</head>
<body style="background-color: #c7f15e;">
<p>This is a link below the ifarme click on link to open new iframe. </p>
</body>
</html>
Example:
<iframe width="550" height="315" src="https://www.youtube.com/embed/JHq3pL4cdy4" frameborde
r="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscree
n style="padding:20px;"></iframe>
<iframe width="550" height="315" src="https://www.youtube.com/embed/O5hShUO6wxs" fram
eborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" style
="padding:20px;">></iframe>
Test it Now
Output:
Attributes of <iframe>
Attribute Value Description
name
height Pixels It defines the height of the embedded iframe, and the default height
is 150 px.
name text It gives the name to the iframe. The name attribute is important if you
want to create a link in one frame.
frameborder 1 or 0 It defines whether iframe should have a border or not. (Not supported
in HTML5).
Width Pixels It defines the width of embedded frame, and default width is 300 px.
src URL The src attribute is used to give the path name or file name which
content to be loaded into iframe.
sandbox
This attribute is used to apply extra restrictions for the content of the
frame
allow-forms It allows submission of the form if this keyword is not used then form
submission is blocked.
allow- It will enable popups, and if not applied then no popup will open.
popups
allow-same- If this keyword is used then the embedded resource will be treated as
origin downloaded from the same source.
srcdoc The srcdoc attribute is used to show the HTML content in the inline
iframe. It overrides the src attribute (if a browser supports).
scrolling
It indicates that browser should provide a scroll bar for the iframe or
not. (Not supported in HTML5)
auto Scrollbar only shows if the content of iframe is larger than its
dimensions.
← PrevNext →
Feedback
HTML JavaScript
A Script is a small program which is used with HTML to make web pages more attractive, dynamic and
interactive, such as an alert popup window on mouse click. Currently, the most popular scripting
language is JavaScript used for websites.
Example:
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Date and Time example</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
10. </html>
Test it Now
It is mainly used to manipulate images, form validation and change content dynamically. JavaScript
uses document.getElementById() method to select an HTML element.
Example:
<!DOCTYPE html>
<html>
<body>
<h2>Use JavaScript to Change Text</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaTpoint";
</script>
</body>
10. </html>
Test it Now
History of Java
HTML provides event handler attributes which work with JavaScript code and can perform some action
on an event.
Syntax:
<element event = "JS code">
Example:
<input type="button" value="Click" onclick="alert('Hi, how are you')">
Test it Now
Output:
Click on the button and you csn see a pop-up window with a message
Note: You will learn more about JavaScript Events in our JavaScript tutorial.
Example:
<!DOCTYPE html>
<html>
<body>
<p>JavaScript can change the content of an HTML element:</p>
<button type="button" onclick="myFunction()">Click Me!</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaTpoint!";
10. }
11. </script>
12. </body>
13. </html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo">JavaScript can change the style of an HTML element.</p>
<script>
function myFunction() {
document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "brown";
document.getElementById("demo").style.backgroundColor = "lightgreen";
10. }
11. </script>
12. <button type="button" onclick="myFunction()">Click Me!</button>
13. </body>
14. </html>
Test it Now
Example:
<!DOCTYPE html>
<html>
<body>
<script>
function light(sw) {
var pic;
if (sw == 0) {
pic = "pic_lightoff.png"
} else {
10. pic = "pic_lighton.png"
11. }
12. document.getElementById('myImage').src = pic;
13. }
14. </script>
15. <img id="myImage" src="pic_lightoff.png" width="100" height="180">
16. <p>
17. <button type="button" onclick="light(1)">Light On</button>
18. <button type="button" onclick="light(0)">Light Off</button>
19. </p>
20. </body>
21. </html>
Test it Now
Note: Do not add <script> tag in the external file, and provide the complete path where you have put the JS file.
Syntax:
<script type="text/javascript" src="URL "></script>
Example:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="external.js"></script>
</head>
<body>
<h2>External JavaScript Example</h2>
<form onsubmit="fun()">
<label>Enter your name:</label><br>
10. <input type="text" name="uname" id="frm1"><br>
11. <label>Enter your Email-address:</label><br>
12. <input type="email" name="email"><br>
13. <input type="submit">
14. </form>
15. </body>
16. </html>
Test it Now
JavaScript code:
function fun() {
var x = document.getElementById("frm1").value;
alert("Hi"+" "+x+ "you have successfully submitted the details");
}
Output:
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
<noscript>This text is not visible in the browser.</noscript>
</body>
10. </html>
Test it Now
HTML Comments
Comments are some text or code written in your code to give an explanation about the code, and not
visible to the user. Comments which are used for HTML file are known as HTML comments. Anything
written between these tags will be ignored by the browser, so comments will not be visible on the
webpage.
Comments of any code make code easy to understand and increase readability of code.
Comments are also part of the code, which gives an explanation of the code.
Syntax
1. <! -- Write commented text here -->
Note: The commented code will not be visible to a webpage, and hence you can use comment tag for documentation purpose, and
debugging purpose:
Such as:
Example:
1. <!DOCTYPE html>
2. <html>
3. <!-- This is Header section -->
4. <head>
5. <!-- Internal CSS -->
6. <style>
7. body{
8. text-align: center;
9. background-color: #f0f8ff;
10. font-size: 30px;
11. color: red;
12. }
13. </style>
14. </head>
15.
16. <!-- This is body section, write code here which you want to display on web-page -->
17. <body>
18. <!-- heading tag -->
19. <h2>First WebPage</h2>
20.
21. <!-- Paragraph tag -->
22. <p>Write your Content here!!!</p>
23. </body>
24. </html>
Test it Now
Multiline Comment
In HTML code, we can also comments multiple lines at a time. In multiline comment we can use any
description about code or multiple line code to debug, etc.
Syntax
1. <!---
2. Your code is commented.
3. Write description of code.
4. It will not display at webpage.
5. -->
Example:
1. <h2>Cake Gallery</h2>
2. <!-- This is image for a yummy cake
3. you can see it on your web-page
4. of your favorite browser -->
5. <img src="https://static.javatpoint.com/htmlpages/images/cake.png" alt="cake image" height
="300px"
6. width="300px">
Test it Now
Output:
HTML Comments
Comments are some text or code written in your code to give an explanation about the code, and not
visible to the user. Comments which are used for HTML file are known as HTML comments. Anything
written between these tags will be ignored by the browser, so comments will not be visible on the
webpage.
Comments of any code make code easy to understand and increase readability of code.
Comments are also part of the code, which gives an explanation of the code.
Syntax
1. <! -- Write commented text here -->
Note: The commented code will not be visible to a webpage, and hence you can use comment tag for documentation purpose, and
debugging purpose:
Such as:
Example:
1. <!DOCTYPE html>
2. <html>
3. <!-- This is Header section -->
4. <head>
5. <!-- Internal CSS -->
6. <style>
7. body{
8. text-align: center;
9. background-color: #f0f8ff;
10. font-size: 30px;
11. color: red;
12. }
13. </style>
14. </head>
15.
16. <!-- This is body section, write code here which you want to display on web-page -->
17. <body>
18. <!-- heading tag -->
19. <h2>First WebPage</h2>
20.
21. <!-- Paragraph tag -->
22. <p>Write your Content here!!!</p>
23. </body>
24. </html>
Test it Now
Multiline Comment
In HTML code, we can also comments multiple lines at a time. In multiline comment we can use any
description about code or multiple line code to debug, etc.
Syntax
1. <!---
2. Your code is commented.
3. Write description of code.
4. It will not display at webpage.
5. -->
Example:
1. <h2>Cake Gallery</h2>
2. <!-- This is image for a yummy cake
3. you can see it on your web-page
4. of your favorite browser -->
5. <img src="https://static.javatpoint.com/htmlpages/images/cake.png" alt="cake image" height
="300px"
6. width="300px">
Test it Now
Output:
Supporting Browsers
The src or href attribute requires an attribute to link any external source to HTML file.
1. <img src="picture.jpg"> It specifies that picture.jpg is located in the same folder as the
current page.
2. <img src="images/picture.jpg"> It specifies that picture.jpg is located in the images folder
in the current folder.
3. <img src="/images/picture.jpg"> It specifies that picture.jpg is located in the images folder
at the root of the current web.
4. <img src="../picture.jpg"> It specifies that picture.jpg is located in the folder one level up
from the current folder.
History of Java
1. Web pages
2. Images
3. Style sheets
4. JavaScript
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Full URL File Path</h2>
5. <img src="https://www.javatpoint.com/images/nature-1.jpg" alt="image" style="width:300px">
6. </body>
7. </html>
Test it Now
Example:
Let's take an example to see how the file path points to a file in the images folder located at the root of
the current web.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="/images/nature-2.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
Test it Now
Example:
This is how a file path points to a file in the images folder located in the current folder.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="images/nature-3.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
Test it Now
Example:
When the images folder located in the folder one level above the current folder.
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Using a Relative File Path</h2>
5. <img src="../images/nature4.jpg" alt="Mountain" style="width:300px">
6. </body>
7. </html>
Test it Now
← PrevNext →
HTML Head
The HTML <head> element is used as a container for metadata (data about data). It is used between
<html> tag and <body> tag.
The head of an HTML document is a part whose content is not displayed in the browser on page
loading. It just contains metadata about the HTML document which specifies data about the HTML
document.
An HTML head can contain lots of metadata information or can have very less or no information, it
depends on our requirement. But head part has a crucial role an HTML document while creating a
website.
Metadata defines the document title, character set, styles, links, scripts, and other meta information.
History of Java
o <title>
o <style>
o <meta>
o <link>
o <script>
o <base>
Note: The title element must be specific about the document and its recommended length is 65 to 70 characters including spaces.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>This Page Title</title>
5. </head>
6. <body>
7. <p>The body's content is displayed in the browser window.</p>
8. <p>The content of the title element is displayed in the browser tab, in favorites and in search engine r
esults.</p>
9. </body>
10. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>This is Page Title</title>
5. <style>
6. body {background-color: pink;}
7. h1 {color: red;}
8. p {color: blue;}
9. </style>
10. </head>
11. <body>
12. <h1>This is a Heading</h1>
13. <p>This is a paragraph.</p>
14. </body>
15. </html>
Test it Now
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>This is title</title>
5. <link rel="stylesheet" href="style.css">
6. </head>
7. <body>
8. <h2>Web-page with external CSS</h2>
9. <p>This is looking a cool page</p>
10. </body>
11. </html>
Test it Now
Metadata is mainly used by browsers, search engines, and other web services to rank your webpage
better.
1. <meta charset="UTF-8">
The charset attribute specifies the character encoding. In this example we have set it to "UTF-8" which
means it can handle to display any language.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="UTF-8">
5. </head>
6. <body>
7. <p>This is written in English language<span style="color: blue"> My friend's name is.......</span></
p>
8. <p>This is Chinese language <span style="color: red">Wǒ de péngyǒu jiào</span></p>
9. </body>
10. </html>
Test it Now
Output:
To define a description of your webpage:
If you give a meta description then it will be useful for the relevant search to perform by search
engines.
The keyword value is also used to provide keywords for a search engine, but it may ignore by browser
due to spammers.
The author value specifies the name of the person who wrote the page content, and it is useful to
automatically extract author information by some content management systems.
Meta refresh is used to provide instructions to the browser to automatically refresh the page after the
given time interval. As in above example it will automatically refresh after 30 sec
If you add an URL with content value, then it will redirect to that page after the time limit will over.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta http-equiv="refresh" content="5; url=https://www.javatpoint.com/html-head">
5. </head>
6. <body>
7. <h2>Meta element Example</h2>
8. <p style="color: green;">Kindly wait for 5 seconds and after 5 seconds it will automatically redirect
to URL specified in meta tag</p>
9. </body>
10. </html>
Test it Now
Following is an example to show how to use all Meta elements within HTML head
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="UTF-8">
5. <meta name="description" content="Free Web tutorials">
6. <meta name="keywords" content="HTML,CSS,XML,JavaScript">
7. <meta name="author" content="Akon">
8. </head>
9. <body>
10. <p>All the meta information are set.</p>
11. </body>
12. </html>
Test it Now
Viewport is the user's visible area of a webpage. It changes from device to device and appears smaller
on mobile phones than computer screens.
Here, the <meta> viewport element specifies how to control the page's dimensions and scaling.
The width=device-width is used to set the width of the page to follow the screen-width of the device
(which will vary depending on the device).
The initial-scale=1.0 is used to set the initial zoom level when the page is first loaded by the
browser.
1. <!DOCTYPE html>
2. <html>
3. <body>
4.
5. <p><b>To understand this example, you should open this page on a phone or a tablet.</b></p>
6.
7. <img src="image.jpg" alt="image" width="460" height="345">
8.
9. <p>
10. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
11. laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
12. ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel
13. eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu
14. feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum
15. zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
16. eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
17. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim place
rat
18. facer possim assum.
19. </p>
20.
21. </body>
22. </html>
Test it Now
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
5. <style>
6. img {
7. max-width: 100%;
8. height: auto;
9. }
10. </style>
11. </head>
12. <body>
13. <p><b>To understand this example, you should open this page on a phone or a tablet.</b></p>
14.
15. <img src="image.jpg" alt="image" width="460" height="345">
16.
17. <p>
18. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut
19. laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation
20. ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel
21. eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu
22. feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum
23. zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis
24. eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum.
25. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim place
rat
26. facer possim assum.
27. </p>
28.
29. </body>
30. </html>
Test it Now
Note: To see the difference clearly, open this page on smartphone or tablet.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Page Title</title>
5. <base href="https://static.javatpoint.com/htmlpages/images/" target="_blank">
6. </head>
7. <body>
8. <img src="html5.png">
9. <p>We have specified a base URL, the browser will look for the image "html5.png"
10. at "https://static.javatpoint.com/htmlpages/images/html5.png"</p>
11. <p><a href=" https://www.javatpoint.com">JavatPoint</a></p>
12. <p>The link above will open in a new window because base target is set to "_blank".</p>
13. </body>
14. </html>
Test it Now
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <script>
5. function fun() {
6. document.getElementById("p").style.color="green";
7. }
8. </script>
9. </head>
10. <body>
11. <h2>Script within Head element</h2>
12. <p id="p">This will change the color</p>
13. <button type="button" onclick="fun()">Click me</button>
14. </body>
15. </html>
Test it Now
If we want to use some external JavaScript file then it can be applied by:
Example:
1. <!DOCTYPE html>
2. <title>Page Title</title>
3. <h1>This is a heading</h1>
4. <p>This is a paragraph.</p>
Test it Now
Note: It is not recommended to omit the <html> and <body> tags. Omitting these tags can crash DOM or XML software and produce
errors in older browsers (IE9).
← PrevNext →
HTML Layouts
HTML layouts provide a way to arrange web pages in well-mannered, well-structured, and in
responsive form or we can say that HTML layout specifies a way in which the web pages can be
arranged. Web-page layout works with arrangement of visual elements of an HTML document.
Web page layout is the most important part to keep in mind while creating a website so that our
website can appear professional with the great look. You can also use CSS and JAVASCRIPT based
frameworks for creating layouts for responsive and dynamic website designing.
Following are different HTML5 elements which are used to define the different parts of a webpage.
NOTE: HTML layouts create an individual space for every part of the web page. So that every element can arrange in a significant
order.
HTML <header>
The <header> element is used to create header section of web pages. The header contains the
introductory content, heading element, logo or icon for the webpage, and authorship information.
Example:
1. <header style="background-color: #303030; height: 80px; width: 100%">
2. <h1 style="font-size: 30px; color: white;text-align: center; padding-top: 15px;">Welcome to My
FirstWebpage</h1>
3. </header>
Test it Now
HTML <nav>
The <nav> elements is a container for the main block of navigation links. It can contain links for the
same page or for other pages.
Example:
1. <nav style="background-color:#bcdeef;">
2. <h1 style="text-align: center;">Navgation Links</h1>
3. <ul>
4. <li><a href="#">link1</a></li>
5. <li><a href="#">link2</a></li>
6. <li><a href="#">link3</a></li>
7. <li><a href="#">link4</a></li>
8. </ul>
9. </nav>
Test it Now
HTML <section>
HTML <section> elements represent a separate section of a web page which contains related element
grouped together. It can contain: text, images, tables, videos, etc.
Example:
1. <section style="background-color:#ff7f50; width: 100%; border: 1px solid black;">
2. <h2>Introduction to HTML</h2>
3. <p>HTML is a markup language which is used for creating attractive web pages with the help of sty
ling, and which looks in a nice format on a web browser..</p>
4. </section>
Test it Now
HTML <article>
The HTML
tag is used to contain a self-contained article such as big story, huge article, etc.
Example:
1. <article style="width: 100%; border:2px solid black; background-color: #fff0f5;">
2. <h2>History of Computer</h2>
3. <p>Write your content here for the history of computer</p>
4. </article>
Test it Now
HTML <aside>
HTML <aside> define aside content related to primary content. The <aside> content must be related
to the primary content. It can function as side bar for the main content of web page.
Example:
1. <aside style="background-color:#e6e6fa">
2. <h2>Sidebar information</h2>
3. <p>This conatins information which will represent like a side bar for a webpage</p>
4. </aside>
Test it Now
HTML <footer>
HTML <footer> element defines the footer for that document or web page. It mostly contains
information about author, copyright, other links, etc.
Example:
1. <footer style="background-color: #f0f8ff; width: 100%; text-align: center;">
2. <h3>Footer Example</h3>
3. <p>© Copyright 2018-2020. </p>
4. </footer>
Test it Now
HTML <details>
HTML <details> element is used to add extra details about the web page and use can hide or show the
details as per requirement.
Example:
1. <details style="background-color: #f5deb3">
2. <summary>This is visible section: click to show other details</summary>
3. <p>This section only shows if user want to see it. </p>
4. </details>
Test it Now
HTML <summary>
HTML <summary> element is used with the <details> element in a web page. It is used as summary,
captions about the content of <details> element.
Example:
1. <details>
2. <summary>HTML is acronym for?</summary>
3. <p style="color: blue; font-size: 20px;">Hypertext Markup Language</p>
4. </details>
Test it Now
← PrevNext →
element is designed to display tabular data. It is not good for a layout. Although first creating a layout
is easy, but if you want to change or redesign your website, then it will be a complicated task.
Following is an example for the creation of a simple web page layout using HTML table.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. li{
6. display: inline-block;
7. padding: 10px;}
8. a{
9. color:#20b2aa;
10. }
11. </style>
12. </head>
13. <body>
14. <!-- Header Section -->
15. <table width="100%" style="border-collapse:collapse;">
16. <tr>
17. <td colspan="2" style="background-color:#1a1a1a; text-align: center;">
18. <h3 style="font-size: 30px; color: #ff6a6a;">javaTpoint Table-layout</h3>
19. </td>
20. </tr>
21. <!-- Nav Section -->
22. <tr>
23. <td colspan="2" style="background-color:#666666;">
24. <ul>
25. <li><a href="#">Home</a></li>
26. <li><a href="#">Menu</a></li>
27. <li><a href="#">About-us</a></li>
28. <li><a href="#">Contact us</a></li>
29. </ul>
30. </td>
31. </tr>
32. <!-- Main Section -->
33. <tr>
34. <td style="background-color:#e6e6fa; width:80%; height: 400px; text-align: center;">
35. <p>Write your content Here</p>
36. </td>
37. <td style="background-color:#a7e6fb; height: 400px;">
38. <p>This is your side bar</p>
39. </td>
40. </tr>
41. <!-- Footer Section -->
42. <tr>
43. <td colspan="2" style="background-color:#2e2e2e; text-align: center;">
44. <p style="color:#f08080">©<strong>Copyright javaTpoint.com</strong></p>
45. </td>
46. </tr>
47. </table>
48. </body>
49. </html>
Test it Now
Note: This example is just for show you how to create layout using table but it's not recommended to use table layout.
CSS Frameworks
CSS provides many frameworks like W3.CSS, Bootstrap, and many more, to create your layout fast.
Using CSS frameworks you can easily create a responsive and attractive web layout. You just need to
add a link for these frameworks, and you can use all properties available in the framework.
CSS Float
You can create an entire web layout using CSS float property.
Advantage: It is very easy to learn and use. You just learn how the float and clear properties work.
Disadvantage: Floating elements are tied to the document flow, which may harm the flexibility.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. div.container {
6. width: 100%;
7. border: 1px solid gray;
8. }
9.
10. header, footer {
11. padding: 1em;
12. color: white;
13. background-color: #000080;
14. clear: left;
15. text-align: center;
16. }
17.
18. nav {
19. float: left;
20. max-width: 160px;
21. margin: 0;
22. padding: 1em;
23. }
24.
25. nav ul {
26. list-style-type: none;
27. padding: 0;
28. }
29.
30. nav ul a {
31. text-decoration: none;
32. }
33.
34. article {
35. margin-left: 170px;
36. border-left: 1px solid gray;
37. padding: 1em;
38. overflow: hidden;
39. }
40. </style>
41. </head>
42. <body>
43.
44. <div class="container">
45.
46. <header>
47. <h1>Tutorials Gallery</h1>
48. </header>
49.
50. <nav>
51. <ul>
52. <li><a href="#">HTML</a></li>
53. <li><a href="#">CSS</a></li>
54. <li><a href="#">JavaScript</a></li>
55. </ul>
56. </nav>
57. <article>
58. <h1>HTML</h1>
59. <p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html. Our HTML tutorial
is
60. developed for beginners and professionals.</p>
61. <p>TML is an acronym which stands for Hyper Text Markup Language. Let's see what is Hyper Text a
nd what is Markup Language?</p>
62. </article>
63. <footer>Copyright © javatpoint.com</footer>
64. </div>
65. </body>
66. </html>
Test it Now
CSS Flexbox
Flexbox is a new layout mode in CSS3.
Advantage: It ensures that the page layout must accommodate different screen sizes and different
display devices.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <style>
5. .flex-container {
6. display: -webkit-flex;
7. display: flex;
8. -webkit-flex-flow: row wrap;
9. flex-flow: row wrap;
10. text-align: center;
11. }
12.
13. .flex-container > * {
14. padding: 15px;
15. -webkit-flex: 1 100%;
16. flex: 1 100%;
17. }
18.
19. .article {
20. text-align: left;
21. }
22.
23. header {background: #000080;color:white;}
24. footer {background: #000080;color:white;}
25. .nav {background:#eee;}
26.
27. .nav ul {
28. list-style-type: none;
29. padding: 0;
30. }
31. .nav ul a {
32. text-decoration: none;
33. }
34.
35. @media all and (min-width: 768px) {
36. .nav {text-align:left;-webkit-flex: 1 auto;flex:1 auto;-webkit-order:1;order:1;}
37. .article {-webkit-flex:5 0px;flex:5 0px;-webkit-order:2;order:2;}
38. footer {-webkit-order:3;order:3;}
39. }
40. </style>
41. </head>
42. <body>
43.
44. <div class="flex-container">
45. <header>
46. <h1>City Gallery</h1>
47. </header>
48.
49. <nav class="nav">
50. <ul>
51. <li><a href="#">HTML</a></li>
52. <li><a href="#">CSS</a></li>
53. <li><a href="#">JavaScript</a></li>
54. </ul>
55. </nav>
56.
57. <article class="article">
58. <h1>HTML</h1>
59. <p>HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of html. Our HTML tutorial
is
60. developed for beginners and professionals.</p>
61. <p>TML is an acronym which stands for Hyper Text Markup Language. Let's see what is Hyper Text a
nd what is Markup Language?</p>
62. <p><strong>Resize this page to see what happens!</strong></p>
63. </article>
64.
65. <footer>Copyright © javatpoint.com</footer>
66. </div>
67.
68. </body>
69. </html>
Test it Now
HTML Responsive
Responsive Web design
Responsive web design is used to make your web page look appropriate, good, and well placedon all
devices (desktop, tablet, smartphone etc.)
Responsive web design uses HTML and CSS to resize, hide, shrink, enlarge, or move the content. It
makes the content look good on any screen.
Responsive Images
Images which can be scaled nicely to fit any browser size are known as responsive images.
Set the CSS width property to 100% to make the image responsive and scale up and down.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Responsive Image</h2>
6. <p>When we set the CSS width property to 100%, it makes the image responsive.
7. Resize the browser window to see the effect.</p>
8. <img src="img_girl.jpg" style="width:100%;">( change image)
9. </body>
10. </html>
Test it Now
Note: A problem with the above method (width: 100%) is that the image can be scaled up to be larger than its original size. So, it is
better to use the max-width property instead.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Responsive Image</h2>
6. <p>"max-width:100%" makes the image responsive and also ensures that the image
7. doesn't get bigger than its original size.</p>
8. <p>Resize the browser window to see the effect.</p>
9. <img src="img_girl.jpg" style="max-width:100%;height:auto;"> (Change the image)
10. </body>
11. </html>
Test it Now
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h2>Change Images Depending on Browser Width</h2>
6. <p>Resize the browser width and the image will change at 600px and 1500px.</p>
7. <picture>
8. <source srcset="img_smallflower.jpg" media="(max-width: 600px)">(Change image)
9. <source srcset="img_flowers.jpg" media="(max-width: 1500px)">(Change image)
10. <source srcset="flowers.jpg">
11. <img src="img_flowers.jpg" alt="Flowers" style="width:auto;">
12. </picture>
13. </body>
14. </html>
Test it Now
Responsive Text-size
We can make the text size responsive by using the "uv" unit. It means viewport-width. By using this,
we can make the text size to follow the browserwindow screen.
Example
1. <!DOCTYPE html>
2. <html>
3. <meta name="viewport" content="width=device-width, initial-scale=1.0">
4. <body>
5. <h1 style="font-size:10vw;">Here size is 10vw.</h1>
6. <p style="font-size:6vw;">Here size is 6vw.</p>
7. <p style="font-size:4vw;">Here size is 4vw.</p>
8. <p>Resize the browser window to see how the text size changes.</p>
9. </body>
10. </html>
Test it Now
Note: viewport specifies the browser window size. 1vw = 1% of viewport width. Means, if the viewport is 100cm wide, 1vw is 1.0cm.
Media Query
We can also use media query to make responsive websites. Read the details of media query from
here: Media Query
Following is a list of some tags which are used in HTML for this task.
o <code>
o <kbd>
o <samp>
o <var>
o <pre>
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>Computer Code</h2>
5. <p>This is a programming code:</p>
6. <code>
7. x = 5;<br>
8. y = 6;<br>
9. z = x + y;
10. </code>
11. </body>
12. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The kbd Element</h2>
5. <kbd>This is how content written within kbd element looks like.</kbd></p>
6. </body>
7. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The samp Element</h2>
5. <samp>This is how the content within samp element looks like. </samp>
6. </body>
7. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h2>The var Element</h2>
5. <p>This is a famous formula: <var>E</var> = <var>mc</var><sup>2</sup>.</p>
6. </body>
7. </html>
Test it Now
Example:
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <h3>Example of pre tag</h3>
5. <pre>
6. This is content written
7. within pre tag, and pre tag will ignore all
8. spaces, break lines, and will display the content
9. as in original format.
10. </pre>
11. </body>
12. </html>
Test it Now
Next TopicHTML Entities
← PrevNext →
HTML Entities
HTML character entities are used as a replacement of reserved characters in HTML. You can also
replace characters that are not present on your keyboard by entities.
These characters are replaced because some characters are reserved in HTML. HTML entities provide a
wide range of characters which can allow you to add icons, geometric shapes, mathematical operators,
etc.
For example: if you use less than (<) or greater than (>) symbols in your text, the browser can mix
them with tags that's why character entities are used in HTML to display reserved characters.
12. Install AdminLTE in a CMS | Absolute vs Relative path HTML | Build a CMS using OOP tutorial MVC
Syntax:
1. &entity_name;
2. OR
3. &#entity_number;
Disadvantage of entity name: Browsers may not support all entity names, but the support for
numbers is good.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title></title>
5. </head>
6. <body>
7. <h3>HTML entity example</h3>
8. <p> "This is the content written within entity"</p>
9. <p> <p> Paragraph tag </p>
10. </body>
11. </html>
Test it Now
Some diacritical marks, like grave ( ̀) and acute ( ́) are called accents.Diacritical marks can be used
both above and below a letter, inside a letter, and between two letters.
̀ a à à
́ a á á
̂ a â â
̃ a ã ã
̀ O Ò Ò
́ O Ó Ó
̂ O Ô Ô
̃ O Õ Õ
HTML Symbols
There are many mathematical, technical and currency symbols which are not present on a normal
keyboard. We have to use HTML entity names to add such symbols to an HTML page.
If there no entity name exists, you can use an entity number, a decimal, or hexadecimal reference.
Example:
<!DOCTYPE html>
<html>
<body>
<h3>The Currency Symbols</h3>
<p>This is Indian Rupee symbol <b>₹<b></p>
<p>This is Euro symbol <b>€</b></p>
<p> This is Dollar symbol <b>#36;</b></p>
</body>
</html>
Test it Now
← PrevNext →
HTML Charset
HTML Charset is also called HTML Character Sets or HTML Encoding. It is used to display an HTML page
properly and correctly because for displaying anything correctly, a web browser must know which
character set (character encoding) to use.
The main problem with ASCII encoding was it contains a limited range of characters. It contains mainly
128 characters.
HTML Tutorial
ISO-8859-1 was the default character set for HTML 4. This character set also supported 256 different
character codes.
Because ANSI and ISO-8859-1 were so limited, HTML 4 also supported UTF-8.The default character
encoding for HTML5 is UTF-8.
1. <meta charset="UTF-8">
Syntax of a URL:
1. scheme://prefix.domain:port/path/filename
Here,
o scheme is used to define the type of Internet service (most common is http or https).
o prefix is used to define a domain prefix (default for http is www).
o domain is used to define the Internet domain name (like javaTpoint.com).
o port is used to define the port number at the host (default for http is 80).
o path is used to define a path at the server (If omitted: the root directory of the site).
o filename is used to define the name of a document or resource.
URL Encoding
URL encoding is used to convert non-ASCII characters into a format that can be used over the Internet
because a URL is sent over the Internet by using the ASCII character-set only. If a URL contains
characters outside the ASCII set, the URL has to be converted.
In URL encoding, the non-ASCII characters are replaced with a "%" followed by hexadecimal digits.
URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign, or %20.
Following is a list of some character sets which are encoded by browser after submitting
the text.
Next TopicHTML global attributes
Global Attributes
HTML global attributes are those attributes which are common for all HTML elements. The global
attributes are supported by both standard and non-standard element.
The global attributes can be used with all elements, although it may not have any effect on some
elements.
accesskey character It is used to generate keyboard shortcuts for the current element.
class classname It is used to provide the class name for the current element. It is
mainly used with the stylesheet.
contextmenu menu_id It defines the id for the <menu> element which is used as a
context menu (a menu appear on right click) for an element.
data-* somevalue It is used to store element-specific private data which can be
accessed by Javascript.
dir rtl It specifies the direction of the content inside the current element.
ltr
auto
dropzone copy It specifies the action is taken on the dragged element when it is
move dropped, ¬¬ such as whether it is copied, moved or linked.
link
lang language_co It specifies the primary language for the content of an element.
de
spellcheck true It specifies whether the content should be checked for spelling
false errors or not.
title text It is used to provide the title, name, or some extra information
about the element.
In HTML5 there are lots of event attributes available which can be activated using a programming
language such as JavaScript.
Following is a table of event attributes, using these attributes you can perform several events.
Attribute Description
onhashchang Executed the script when the anchor part in URL of the webpage is changed.
e
onoffline Executed the script when the network connection is disconnected, and browser
started working offline.
ononline Executed the script when the browser started working online
onpagehide Executed the script when the current webpage is hidden such as if the user has
moved away from the current webpage.
onpopstate Executed the script when the window's active history is changed.
onunload Executed the script when the current webpage is unloaded, or window is closed.
The form events can be used with any element, but these are mainly used with HTML form elements.
Attribute Description
onblur Executed the script when form element loses the focus.
onchange Executed the script when the value of the element is changed.
oninput Executed the script when the user enters input to the element.
oninvalid Executed the script when the element does not satisfy its predefined constraints.
onreset Triggers the event when user reset the form element values.
onsearch Triggers the event when a search field receives some input.
onselect Triggers the event when the user has selected some text.
Attribute Description
onkeydown Triggers the event when the user presses down a key on the keyboard.
onkeypress Trigger the event when the user presses the key which displays some character.
onkeyup Trigger the event when the user releases the currently pressed key.
Attribute Description
onclick Trigger the event when the mouse clicks on the element.
ondblclick Trigger the event when mouse double-click occurs on the element.
onmousedown Trigger the event when the mouse button is pressed on the element.
onmousemove Trigger the event when the mouse pointer moves over the element.
onmouseout Trigger the event when the mouse moves outside the element.
onmouseover Trigger the event when the mouse moves onto the element.
onwheel Trigger the event when the mouse wheel rolls up or down on the element
Attribute Description
oncopy Trigger the event when the user copies the content to the system clipboard.
oncut Trigger the event when the content of an element is cut and copy to the clipboard.
onpaste Trigger the event when the user pastes some content in an element.
Attribute Description
oncanplay Executed the script when the media file is ready to play.
oncanplaythrou Executed the script when the media file is ready to play without buffering or
gh stopping.
ondurationchan Executed the script when the media file duration is changed.
ge
onemptied Executed the script if media occurs some fatal error, and the file becomes
unavailable.
onended Executed the script when the media file occurs its end point.
onerror Executed the script when some error occurred while fetching the media data.
onplay Executed the script when media file ready to play after being paused.
onprogress Executed the script when the browser is in the process of getting the media data.
onseeked Executed the script when seek operation is ended and seeking attribute is set to
false.
onseeking Executed the script when seek operation is active and seeking attribute is set to
true.
onstalled Executed the script when browser unexpectedly stopped fetching the data
media.
ontimeupdate Executed the script when playback position is changed, such as if a user fasts
forward the track.
onvolumechang Executed the script when media volume is changed (muted or unmuted).
e
onwaiting Executed the script if playback pause to wait for loading more data.
Next TopicHTML 5 Tags
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
Note: HTML Tags are always written in lowercase letters. The basic HTML tags are given below:
Test it Now
Some HTML tags are not closed, for example br and hr.
<br> Tag: br stands for break line, it breaks the line of the code.
<hr> Tag: hr stands for Horizontal Rule. This tag is used to put a line across the webpage.
<p>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <strong>, <em>, <abbr>, <acronym>, <address>,
<bdo>, <blockquote>, <cite>, <q>, <code>, <ins>, <del>, <dfn>, <kbd>, <pre>, <samp>, <var>
and <br>
table, tr, td, th, tbody, thead, tfoot, col, colgroup and caption
form, input, textarea, select, option, optgroup, button, label, fieldset and legend
<aside> It defines content aside from main content. Mainly represented as sidebar.
<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 of
document. (Not supported in HTML5)
<bdi> This tag is used to provide isolation for that part of text which may be formatted in
different directions from its surrounding text.
<big> This tag is used to make font size one level larger than its surrounding
content. (Not supported in HTML5)
<cite> It is used to define the title of the work, book, website, etc.
<col> It defines a column within a table which represent common properties of columns
and used with the <colgroup> element.
<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)
<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 in
HTML5)
<frame> It defines a particular area of webpage which can contain another HTML file. (Not
supported in HTML5)
<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 in
HTML5)
<noframes> It provides alternate content to represent in browser which does not support the
<frame> elements. (Not supported in HTML5)
<picture> It defines more than one source element and one image element.
<rp> It defines an alternative content if browser does not supports ruby annotations.
S
<s> It render text which is no longer correct or relevant.
<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 as <picture>,
<video>, and <audio> element.
<strike> It is used to render strike through the text. (Not supported in HTML5)
<table> It is used to present data in tabular form or to create a table within HTML document.
<tbody> It represents the body content of an HTML table and used along with <thead> 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 page
load and may render later using JavaScript.
<textarea> It is used to define multiple line input, such as comment, feedback, and review, etc.
<thead> It defines the header of an HTML table. It is used along with <tbody> and <tfoot>
tags.
<track> It is used to define text tracks for <audio> and <video> elements.