Module1 HTML Doc
Module1 HTML Doc
Topics
• What is HTML
• HTML Element
• HTML Attributes
• HTML Headings
• HTML Paragraphs
• HTML Styles
• HTML Text Formatting
• HTML Quotations, Comments
• HTML Colors
• HTML-Styles-CSS
• HTML Tables, Forms, Frames
Markup language
• A markup language is a set of rules that defines how the layout and
presentation of text and images should appear in a digital document.
• It allows structuring documents, adding formatting, and specifying how
different elements should be displayed (or “rendered”) on webpages.
• An example of a markup language—and the one most people know—is
HTML. And it looks like this:
• XML
• SGML
• XHTML
</body>
</html>
Html Page Structure
Note: The content inside the <body> section will be displayed in a browser. The
content inside the <title> element will be shown in the browser's title bar or in the
page's tab.
Example Explained…
• The <!DOCTYPE html> declaration defines that this document is
an HTML5 document
• The <html> element is the root element of an HTML page
• The <head> element contains meta information about the
HTML page
• The <title> element specifies a title for the HTML page (which is
shown in the browser's title bar or in the page's tab)
• The <body> element defines the document's body, and is a
container for all the visible contents, such as headings,
paragraphs, images, hyperlinks, tables, lists, etc.
• The <h1> element defines a large heading
• The <p> element defines a paragraph
Tree Structure
HTML syntax
• HTML syntax is the order in which elements
and attributes are arranged to create well-
formed documents.
• It's the grammar and spelling of the language,
and syntax rules ensure that the language can
be read and interpreted by a computer.
• If syntax rules aren't followed, errors can
occur and web pages can break.
HTML syntax:
1. Tags: HTML uses tags to define the meaning and structure of content. Tags
are written in angle brackets (< and >). There are two types of tags:
• Opening Tag: This marks the beginning of an element. It includes the element
name enclosed in angle brackets (e.g., <p> for paragraph).
• Closing Tag: This marks the end of an element. It's similar to the opening tag
but includes a forward slash before the element name (e.g., </p>).
Example:
HTML
<h1>This is a heading</h1> <p>This is a paragraph.</p>
Use code with caution.
3. Basic Structure: A basic HTML document has a specific
structure:
Example:
HTML
<img src="image.jpg" alt="My Image">
Use code with caution.
5. Case Sensitivity: HTML tags are not case-sensitive. So, <P> and
<p> are treated the same. However, for consistency, it's
recommended to use lowercase tags.
6. Comments
• syntax:
• The HTML element is everything from the start tag to the end tag:
• <h1>My First Heading</h1>
• <p>My first paragraph.</p>
• The href attribute of <a> specifies the URL of the page the link goes to
• The src attribute of <img> specifies the path to the image to be
displayed
• The width and height attributes of <img> provide size information for
images
• The alt attribute of <img> provides an alternate text for an image
• The style attribute is used to add styles to an element, such as color,
font, size, and more
• The lang attribute of the <html> tag declares the language of the
Web page
• The title attribute defines some extra information about an element
1. The href Attribute:
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link
goes to:
Example:<a href="https://www.cutmap.ac.in">Visit CUTMAP</a>
3.The width and height Attributes: The <img> tag should also contain
the width and height attributes, which specifies the width and height of the image (in
pixels):
Example: <img src="img_girl.jpg" width="500" height="600">
4. The alt Attribute: The required alt attribute for the <img> tag specifies an alternate
text for an image, if the image for some reason cannot be displayed. This can be due
to slow connection, or an error in the src attribute, or if the user uses a screen reader.
Example:<img src="img_girl.jpg" alt="Girl with a jacket">
5. The style Attribute:
The style attribute is used to add styles to an element, such as color, font, size, and
more.
Example <p style="color:red;">This is a red paragraph.</p>
<!DOCTYPE html>
<html lang="en">
<body>
...
</body>
</html>
7. The title Attribute:
The title attribute defines some extra information about an element.
The value of the title attribute will be displayed as a tooltip when you mouse over the
element:
Example:<p title="I'm a tooltip">This is a paragraph.</p>
Headings
• HTML headings are titles or subtitles that you want to display on a
webpage.
• HTML headings are defined with the <h1> to <h6> tags.
• <h1> defines the most important heading. <h6> defines the least
important heading.
• Example:
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Each HTML heading has a default size. However, you can specify the size for
any heading with the style attribute, using the CSS font-
size property:
Example: <h1 style="font-size:60px;">Heading 1</h1>
Headings Global Attributes
• Tag Description
<p> Defines a paragraph
<hr> Defines a thematic change in the content
<br> Inserts a single line break
<pre> Defines pre-formatted text
1.<P>
The HTML <p> element defines a paragraph.
A paragraph always starts on a new line, and browsers automatically add some white space (a margin)
before and after a paragraph.
Example:<p>This is a paragraph.</p>
2. <hr>
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a horizontal
rule.
The <hr> element is used to separate content (or define a change) in an HTML page:<hr>
3.<br>
The HTML <br> element defines a line break.
Use <br> if you want a line break (a new line) without starting a new paragraph:
Example: <p>This is<br>a paragraph<br>with line breaks.</p>
4. <pre>
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves
both spaces and line breaks
Example: <pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
</pre>
HTML Styles
• The HTML style attribute is used to add styles to an
element, such as color, font, size, and more.
• The HTML style attribute has the following syntax:
<tagname style="property: value;">
Properties:
• Use the style attribute for styling HTML elements
• Use background-color for background color
• Use color for text colors
• Use font-family for text fonts
• Use font-size for text sizes
• Use text-align for text alignment
Style attributes
1. Background Color: The CSS background-color property defines
the background color for an HTML element.
Ex:<body style="background-color:powderblue;">
<p>This is a paragraph.</p></body
Ex2:<p style="background-color:tomato;">This is a paragraph.</p>
2. Text Color: The CSS color property defines the text color for an
HTML element:
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
3. Fonts: The CSS font-family property defines the font to be used
for an HTML element:
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
<p align="justify" style="font-family:impact;
background-color:powderblue";>
4. Text Size: The CSS font-size property defines the text size for
an HTML element:
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
Tag Description
<abbr> Defines an abbreviation or acronym
<address> Defines contact information for the author/owner of a document
<blockquote> Defines a section that is quoted from another source
<cite> Defines the title of a work
<q> Defines a short inline quotation
1. <blockquote> element defines a section that is quoted from
another source.<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
--------------</blockquote>
2. <q> tag defines a short quotation.
Ex:<p>WWF's goal is to: <q>Build a future where people live in
harmony with nature.</q></p>
3.<abbr> for Abbreviations:
<p>The <abbr title="World Health Organization">WHO</abbr> was
founded in 1948.</p>
4. <address> for Contact Information
<address>--------------</address>
5. <cite> tag defines the title of a creative work
• <p><cite>The Scream</cite> by Edvard Munch. Painted in 1893.</p>
HTML Comments
• HTML comments are not displayed in the browser,
but they can help document your HTML source code.
Example2:
<!-- Do not display this image at the moment
<img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
HTML Colors
• HTML colors are specified with predefined color names, or
with RGB, HEX, HSL, RGBA, or HSLA values.
• Color Names : In HTML, a color can be specified by using a
color name:
1)Background Color:
<h1 style="background-color:DodgerBlue;">Hello World</h1>
2)Text Color:
<h1 style="color:Tomato;">Hello World</h1>
3)Border Color:
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
• Color Values: colors can also be specified using RGB values, HEX
values, HSL values, RGBA values, and HSLA values.
Example:
<p>In addition to the predefined color names, colors can be specified using RGB,
HEX, HSL, or even transparent colors using RGBA or HSLA color values.</p>
HSL Color Values
In HTML, a color can be specified using hue, saturation, and lightness (HSL) in the form:
• Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
• Saturation is a percentage value. 0% means a shade of gray, and 100% is the full color.
• Lightness is also a percentage value. 0% is black, and 100% is white.
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
3) External CSS: An external style sheet is used to define the style for many HTML pages.
• Example
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
another external css file "styles.css":
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}
Html Tables
• HTML tables allow web developers to arrange data into rows and
columns.
<!DOCTYPE html>
<html>
<body>
<h2>Basic HTML Table</h2>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>
Tables
1.Add border: To add a border to a table, use the CSS border property:
Ex: table, th, td {
border: 1px solid black;
}
2. Collapsed Borders: To let the borders collapse into one border, add the CSS
border-collapse property:
Ex: table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
3. Add Cell Padding: Cell padding specifies the space between the cell content and its
borders. To set the padding, use the CSS padding property:
Ex:th, td {
padding: 15px;
}
4. Left-align Headings: By default, table headings are bold and centered.
To left-align the table headings, use the CSS text-align property:
Ex: th {
text-align: left;
}
5. Add Border Spacing: Border spacing specifies the space between the cells.
To set the border spacing for a table, use the CSS border-spacing property:
Ex: table {
border-spacing: 5px;
}
Note: If the table has collapsed borders, border-spacing has no effect.
6. colspan: To make a cell span more than one column, use the colspan attribute:
Ex:<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
7.rowspan: To make a cell span more than one row, use the rowspan attribute:
Ex:<tr>
<th rowspan="2">Telephone:</th>
<td>55577854</td>
</body></html>
Links
HTML Links
• Links allow users to click their way from page to page.
• HTML Links – Hyperlinks, You can click on a link and jump to another
document.
• When you move the mouse over a link, the mouse arrow will turn into a
little hand.
• The HTML <a> tag defines a hyperlink. It has the following syntax:
• The most important attribute of the <a> element is the href attribute,
which indicates the link's destination.
• The link text is the part that will be visible to the reader.
• Clicking on the link text, will send the reader to the specified URL
address.
• Ex:
<a href="https://www.w3schools.com/">Visit W3Schools.com!</a>
• Use the <a> element to define a link
• Use the href attribute to define the link
address
• Use the target attribute to define where to
open the linked document
• Use the <img> element (inside <a>) to use an
image as a link
• Use the mailto: scheme inside
the href attribute to create a link that opens
the user's email program
1. HTML Links - The target Attribute
• By default, the linked page will be displayed in the current
browser window. To change this, you must specify another
target for the link.
• The target attribute specifies “where to open the linked
document”.
• The target attribute can have one of the following values:
_self - Default. Opens the document in the same
window/tab as it was clicked
_blank - Opens the document in a new window or tab
_parent - Opens the document in the parent frame
_top - Opens the document in the full body of the window
Ex:
<a href="https://www.w3schools.com/" target="_blank">Visit
W3Schools!</a>
Absolute URLs vs. Relative URLs
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
2. HTML Links - Use an Image as a Link
To use an image as a link, just put the <img> tag inside
the <a> tag:
Example
• <a href="default.asp">
<img src="smiley.gif" alt="HTML
tutorial" style="width:42px;height:42px;">
</a>
3. Link to an Email Address
• Use mailto: inside the href attribute to create a link that
opens the user's email program (to let them send a new
email):
Example
• <a href="mailto:someone@example.com">mail me</a>
4. Button as a Link
• To use an HTML button as a link, you have to add some JavaScript code.
• JavaScript allows you to specify what happens at certain events, such
as a click of a button:
Example:
<button
onclick="document.location='https://www.google.com/'">clickit</button
>
5. Link Titles
• The title attribute specifies extra information about an element. The
information is most often shown as a tooltip text when the mouse
moves over the element.
• Example
<a href="mailto:someone@example.com"><img src="C:\Users\
laxman\Desktop\download.jpg"></a>
HTML Images
• Images can improve the design and the appearance of a web
page.
• Example:<img src="pic_trulli.jpg" alt="Italian Trulli">
HTML Images Syntax:
• The HTML <img> tag is used to embed an image in a web page.
• Images are not technically inserted into a web page; images
are linked to web pages. The <img> tag creates a holding space
for the referenced image.
• The <img> tag is empty, it contains attributes only, and does
not have a closing tag.
• The <img> tag has two required attributes:
a)src - Specifies the path to the image
b)alt - Specifies an alternate text for the image
Image Size - Width and Height
• You can use the style attribute to specify the
width and height of an image.
• Example:<img src="img_girl.jpg" alt="Girl in a
jacket" style="width:500px;height:600px;">
Or
<img src="img_girl.jpg" alt="Girl in a
jacket" width="500" height="600">
Animated Images
• HTML allows animated GIFs:
• Example:<img src="programming.gif" alt="Compu
ter Man" style="width:48px;height:48px;">
Image Floating
• Use the CSS float property to let the image float to the right or
to the left of a text:
• <p><img src="smiley.gif" alt="Smiley
face" style="float:right;width:42px;height:42px;">
The image will float to the right of the text.</p>
.apng
GIF Graphics Interchange Format .gif
type: Sets the bullet style for the list, with values
such as circle, disc, square, or triangle
HTML Forms
HTML Forms
• An HTML form is used to collect user input. The user
input can then be sent to a server for processing.
• The <form> Element is used to create an HTML form for
user input:
<form>
.
form elements
.
</form>
• HTML forms are required if you want to collect some data from of the
site visitor.
</form>
HTML Form Tags
Tag Description
<form> It defines an HTML form to enter inputs by the used side.
<input> It defines an input control.
<textarea> It defines a multi-line input control.
<label> It defines a label for an input element.
<fieldset> It groups the related element in a form.
<legend> It defines a caption for a <fieldset> element.
<select> It defines a drop-down list.
<optgroup> It defines a group of related options in a drop-down list.
<option> It defines an option in a drop-down list.
<button> It defines a clickable button.
HTML form attributes
These are define the behavior and properties of a form
element.
• They include attributes like action for specifying where
form data is sent,
• a method for the HTTP method used,
• and autocomplete for browser input suggestions,
among others.
a. 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: <form action="action.html" method="post">
b. 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: <form action="action.html" method="get">
When submitting the data, it will display the entered data in the form
of:
file:///D:/HTML/action.html?name=RAJU&pass=123
3. HTML target attribute:
The target attribute defines where to open the response after
submitting the form. The following are the keywords used with the
target attribute.
_blank:
If we use _blank as an attribute it will load the response in a new page.
Example:
Example:
Example:
Note: it can be used with <form> element and <input> element both.
5. HTML enctype attribute
It defines the encoding type of form-content while submitting the form to
the server. The possible values of enctype can be:
Example:
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:
<form action = "action.html" method = "get">
Enter name:<br><input type="name" name="uname"><br>
Enter age:<br><input type="number" name="age"><br>
Enter email:<br><input type="email"><br>
<input type="submit" value="Submit">
</form>
b. HTML value attribute
The HTML value attribute defines the initial value or default value of
an input field.
Example:
<form>
<label>Enter your Name</label><br>
<input type="text" name="uname" value="Enter Name"><br><br>
<label>Enter your Email-address</label><br>
<input type="text" name="uname" value="Enter email"><br><br>
<label>Enter your password</label><br>
<input type="password" name="pass" value=""><br><br>
<input type="submit" value="login">
</form>
c. HTML required attribute HTML5
HTML required is a Boolean attribute which specifies that user must fill
that filed before submitting the form.
Example:
<form>
<label>Enter your Email-address</label><br>
<input type="text" name="uname" required><br><br>
<label>Enter your password</label><br>
<input type="password" name="pass"><br><br>
<input type="submit" value="login">
</form>
d. HTML autofocus attribute HTML5
The autofocus is a Boolean attribute which enables a field
automatically focused when a webpage loads.
Example:
<form>
<label>Enter your Email-address</label><br>
<input type="text" name="uname" autofocus><br><br>
<label>Enter your password</label><br>
<input type="password" name="pass"><br><br>
<input type="submit" value="login">
</form>
e. HTML placeholder attribute HTML5
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:
<form>
<label>Enter your name</label><br>
<input type="text" name="uname" placeholder="Your name"><br><br>
<label>Enter your Email address</label><br>
<input type="email" name="email" placeholder="example@gmail.com"><br><br>
<label>Enter your password</label><br>
<input type="password" name="pass" placeholder="your password"><br><br>
<input type="submit" value="login">
</form>
f. HTML disabled attribute
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:
Example:
<label>Account holder name</label><br>
<input type="text" name="uname" size="40" required><br><br>
<label>Account number</label><br>
<input type="text" name="an" size="30" required><br><br>
<label>CVV</label><br>
<input type="text" name="cvv" size="1" required><br><br>
Form tags
Tag Description
<form> It defines an HTML form to enter inputs by the used side.
<input> It defines an input control.
<textarea> It defines a multi-line input control.
<label> It defines a label for an input element.
<fieldset> It groups the related element in a form.
<legend> It defines a caption for a <fieldset> element.
<select> It defines a drop-down list.
<optgroup> It defines a group of related options in a drop-down list.
<option> It defines an option in a drop-down list.
<button> It defines a clickable button.
HTML Form Elements
The <form> element can contain one or more of the following form
elements:
• <label>
• <input>
• <select>
• <textarea>
• <button>
• <fieldset>
• <legend>
• <datalist>
• <output>
• <option>
• <optgroup>
1)The <input> Element
• Example:
<!DOCTYPE>
<html>
<body>
<form>
<label for="fname">Enter your name :<?label>
<input type="text" id="fname" name="username">
</form>
</body>
</html>
If the type attribute is omitted, the input field gets the default type: "text".
2. The <label> Element
Example
• <label for="cars">Choose a car:</label>
<select id="cars" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
• The <option> elements defines an option that can be selected.
• By default, the first item in the drop-down list is selected.
• To define a pre-selected option, add the selected attribute to the option:
Example
• <option value="fiat" selected>Fiat</option>
Visible Values:
• Use the size attribute to specify the number of visible values:
Example:
• The rows attribute specifies the visible number of lines in a text area.
• The cols attribute specifies the visible width of a text area.
• You can also define the size of the text area by using CSS:
Example:
Example
Example:
<form action="/action_page.php">
<fieldset>
<legend>Signin</legend>
<label for="fname">Username:</label>
<input type="text" id="fname"><br>
<label for="pass">Password:</label>
<input type="password" id="pass"><br>
<input type="submit">
</fieldset>
</form>
7. The <datalist> Element
• The <datalist> element specifies a list of pre-defined options for
an <input> element.
• Users will see a drop-down list of the pre-defined options as they input data.
• The list attribute of the <input> element, must refer to the id attribute of
the <datalist> element.
Example:
• <form action="/action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
8. The <output> Element
• The <output> element represents the result of a calculation
(like one performed by a script).
Example
• Perform a calculation and show the result in
an <output> element:
<form action="/action_page.php"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
• <form> Defines an HTML form for user input
• <input> Defines an input control
• <textarea> Defines a multiline input control (text area)
• <label> Defines a label for an <input> element
• <fieldset> Groups related elements in a form
• <legend> Defines a caption for a <fieldset> element
• <select> Defines a drop-down list
• <optgroup> Defines a group of related options in a drop-
down list
• <option> Defines an option in a drop-down list
• <button> Defines a clickable button
• <datalist> Specifies a list of pre-defined options for input
controls
• <output> Defines the result of a calculation
HTML Input Types
• <input type="button"> • <input type="password">
• <input type="checkbox"> • <input type="radio">
• <input type="color"> • <input type="range">
• <input type="date"> • <input type="reset">
• <input type="datetime- • <input type="search">
local"> • <input type="submit">
• <input type="email"> • <input type="tel">
• <input type="file"> • <input type="text">
• <input type="hidden"> • <input type="time">
• <input type="image"> • <input type="url">
• <input type="month"> • <input type="week">
• <input type="number">
1. Input Type Text
<input type="text">
defines a single-line text input field:
Example
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
2. Input Type Password
<input type="password">
Example
<form>
<label for="username">Username:</label><br>
<input type="text" id="username" name="username"><br>
<label for="pwd">Password:</label><br>
<input type="password" id="pwd" name="pwd">
</form>
3. Input Type Submit
<input type="submit">
• defines a button for submitting form data to a form-handler.
• The form-handler is typically a server page with a script for processing input
data.
• The form-handler is specified in the form's action attribute:
Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
4. Input Type Reset
<input type="reset">
• defines a reset button that will reset all form values to their default values:
• Example
<form action="/action_page.php">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
<input type="reset">
</form>
5. Input Type Radio
<input type="radio“ >
Example
<form>
<input type="radio" id="male" name="gender" value="male">
<label for="male">Male</label><br>
<input type="radio" id="female" name="gender" value="female">
<label for="female">Female</label><br>
<input type="radio" id="other" name="gender" value="other">
<label for="other">Other</label>
</form>
6. Input Type Checkbox
<input type="checkbox">
• defines a checkbox.
• Checkboxes let a user select ZERO or MORE options of a limited number of
choices.
Example
<form>
<input type="checkbox" id="vehicle1" name="vehicle1" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="vehicle2" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="vehicle3" value="Boat">
<label for="vehicle3"> I have a boat</label>
</form>
7. Input Type Button
<input type="button">
defines a button:
Example
<input type="color">
Example
<form>
<label for="favcolor">select color:</label>
<input type="color" id="favcolor" name="favcolor">
</form>
9. Input Type Date
<input type="date">
Example
<form>
<label for="birthday">Birthday:</label>
<input type="date" id="birthday" name="birthday">
</form>
You can also use the min and max attributes to add restrictions to dates:
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br>
<label for="datemin">Enter a date after 2000-01-01:</label>
<input type="date" id="datemin" name="datemin" min="2000-01-02">
</form>
10. Input Type Datetime-local
• The <input type="datetime-local"> specifies a date and time input field, with no
time zone.
• Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="birthdaytime">Birthday (date and time):</label>
<input type="datetime-local" id="birthdaytime" name="birthdaytime">
</form>
11. Input Type Email
• The <input type="email"> is used for input fields that should contain an e-mail address.
• Depending on browser support, the e-mail address can be automatically validated when
submitted.
• Some smartphones recognize the email type, and add ".com" to the keyboard to match
email input.
Example
<form>
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email">
</form>
12. Input Type File
• The <input type="file"> defines a file-select field and a "Browse" button for file uploads.
Example
<form>
<label for="myfile">Select a file:</label>
<input type="file" id="myfile" name="myfile">
</form>
13. Input Type Month
• The <input type="month"> allows the user to select a month and year.
• Depending on browser support, a date picker can show up in the input
field.
Example
<form>
<label for="bdaymonth">Birthday (month and year):</label>
<input type="month" id="bdaymonth" name="bdaymonth">
</form>
14. Input Type Number
Example
<form>
<label for="quantity">Quantity (between 1 and 5):</label>
<input type="number" id="quantity" name="quantity" min="1" max="5">
</form>
15. Input Type Range
• The <input type="range"> defines a control for entering a number whose exact
value is not important (like a slider control). Default range is 0 to 100. However,
you can set restrictions on what numbers are accepted with the min, max,
and step attributes:
Example
<form>
<label for="vol">Volume (between 0 and 50):</label>
<input type="range" id="vol" name="vol" min="0" max="50">
</form>
16. Input Type Tel
• The <input type="tel"> is used for input fields that should contain a
telephone number.
Example
<form>
<label for="phone">Enter your phone number:</label>
<input type="tel" id="phone" name="phone" pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
17. Input Type Search
• The <input type="search"> is used for search fields (a search field behaves
like a regular text field).
Example
<form>
<label for="gsearch">Search Google:</label>
<input type="search" id="gsearch" name="gsearch">
</form>
18. Input Type Time
• The <input type="time"> allows the user to select a time (no time zone).
• Depending on browser support, a time picker can show up in the input
field.
Example
<form>
<label for="appt">Select a time:</label>
<input type="time" id="appt" name="appt">
</form>
19. Input Type Url
• The <input type="url"> is used for input fields that should contain a URL address.
• Depending on browser support, the url field can be automatically validated when submitted.
• Some smartphones recognize the url type, and adds ".com" to the keyboard to match url
input.
Example
<form>
<label for="homepage">Add your homepage:</label>
<input type="url" id="homepage" name="homepage">
</form>
20. Input Type Week
• The <input type="week"> allows the user to select a week and year.
• Depending on browser support, a date picker can show up in the input field.
Example
<form>
<label for="week">Select a week:</label>
<input type="week" id="week" name="week">
</form>
HTML Input Attributes
1. The value Attribute
• The input value attribute specifies an initial value for an input field:
Example
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe">
</form>
2. The readonly Attribute
• The input readonly attribute specifies that an input field is read-only.
• A read-only input field cannot be modified (however, a user can tab to it,
highlight it, and copy the text from it).
• The value of a read-only input field will be sent when submitting the form!
Example
• A read-only input field:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John" readonly><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe">
</form>
3. The disabled Attribute
• The input disabled attribute specifies that an input field should be disabled.
• A disabled input field is unusable and un-clickable.
• The value of a disabled input field will not be sent when submitting the form!
Example
• A disabled input field:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John" disabled><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe">
</form>
4. The size Attribute
• The input size attribute specifies the visible width, in characters, of an input field.
• The default value for size is 20.
• Note: The size attribute works with the following input types: text, search, tel, url, email, and password.
Example
• Set a width for an input field:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" size="50"><br>
<label for="pin">PIN:</label><br>
<input type="text" id="pin" name="pin" size="4">
</form>
5. The maxlength Attribute
• The input maxlength attribute specifies the maximum number of characters
allowed in an input field.
• Note: When a maxlength is set, the input field will not accept more than the
specified number of characters. However, this attribute does not provide any
feedback. So, if you want to alert the user, you must write JavaScript code.
Example
• Set a maximum length for an input field:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" size="50"><br>
<label for="pin">PIN:</label><br>
<input type="text" id="pin" name="pin" maxlength="4" size="4">
</form>
6. The min and max Attributes
• The input min and max attributes specify the minimum and maximum values for an input field.
• The min and max attributes work with the following input types: number, range, date, datetime-
local, month, time and week.
• Tip: Use the max and min attributes together to create a range of legal values.
Example
• Set a max date, a min date, and a range of legal values:
<form>
<label for="datemax">Enter a date before 1980-01-01:</label>
<input type="date" id="datemax" name="datemax" max="1979-12-31"><br><br>
Example
<form>
<label for="files">Select files:</label>
<input type="file" id="files" name="files" multiple>
</form>
8. The pattern Attribute
• The input pattern attribute specifies a regular expression that the input field's value is
checked against, when the form is submitted.
• The pattern attribute works with the following input types: text, date, search, url, tel,
email, and password.
• Tip: Use the global title attribute to describe the pattern to help the user.
• Tip: Learn more about regular expressions in our JavaScript tutorial.
Example
• An input field that can contain only three letters (no numbers or special characters):
<form>
<label for="country_code">Country code:</label>
<input type="text" id="country_code" name="country_code"
pattern="[A-Za-z]{3}" title="Three letter country code">
</form>
9. The placeholder Attribute
• The input placeholder attribute specifies short a hint that describes the expected value of an input field (a
sample value or a short description of the expected format).
• The short hint is displayed in the input field before the user enters a value.
• The placeholder attribute works with the following input types: text, search, url, tel, email, and password.
Example
• An input field with a placeholder text:
<form>
<label for="phone">Enter a phone number:</label>
<input type="tel" id="phone" name="phone"
placeholder="123-45-678"
pattern="[0-9]{3}-[0-9]{2}-[0-9]{3}">
</form>
10. The required Attribute
• The input required attribute specifies that an input field must be filled
out before submitting the form.
• The required attribute works with the following input types: text, search,
url, tel, email, password, date pickers, number, checkbox, radio, and file.
Example
• A required input field:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</form>
11. The step Attribute
• The input step attribute specifies the legal number intervals for an input field.
Example
• An input field with a specified legal number intervals:
<form>
<label for="points">Points:</label>
<input type="number" id="points" name="points" step="3">
</form>
12. The autofocus Attribute
• The input autofocus attribute specifies that an input field should automatically get
focus when the page loads.
Example
• Let the "First name" input field automatically get focus when the page loads:
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" autofocus><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname">
</form>
13. The height and width Attributes
• The input height and width attributes specify the height and width of
an <input type="image"> element.
Example
• Define an image as the submit button, with height and width attributes:
<form>
<label for="fname">First name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname"><br><br>
<input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
14. The list Attribute
• The input list attribute refers to a <datalist> element that contains pre-
defined options for an <input> element.
Example
• An <input> element with pre-defined values in a <datalist>:
<form>
<input list="browsers">
<datalist id="browsers">
<option value="Internet Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
15. The autocomplete Attribute
• The input autocomplete attribute specifies whether a form or an input field should have autocomplete on or
off.
• Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser
should display options to fill in the field, based on earlier typed values.
• The autocomplete attribute works with <form> and the following <input> types: text, search, url, tel, email,
password, datepickers, range, and color.
Example
• An HTML form with autocomplete on, and off for one input field:
Developers depend on frames in HTML to build webpages that display various sections.
• Each of the sections of the browser window is known as a frame and is displayed within
a <frameset> or an inline frame (<iframe>) element.
• Each section highlights separate documents or content.
• Frames in HTML are organized by structuring them in rows and columns within the
<frameset> element.
• The <frameset> element establishes the web page’s structure.
• The <frame >and <iframe> elements create the individual frames.
• The <frame> element is used to create a single frame within a frameset. The attributes
cols and rows are used to define the proportion in percentage or an absolute size value
like pixels.
• The <iframe> element can be used to embed external content within a webpage. It
requires the ‘src’ attribute to specify the URL of the external content. The width and
height attributes define the dimensions of the iframe.
• Each frame has its source URL, which allows for displaying content independently.
• A <frameset> element is mainly used to create multi-frame layouts within a single page.
Advantages of Using Frames
• Frames in HTML have several advantages, such as achieving layout flexibility, creating
navigation menus and sidebars, and more. Let’s take a look at these advantages in
detail.
• Achieving Layout Flexibility: Developers can utilize frames to create intricate layouts
by dividing a webpage into various sections. This level of flexibility empowers the
design of websites that feature responsive navigation menus, sidebars, and
autonomous content panes. By utilizing framesets, it becomes simpler to uphold a
consistent layout throughout multiple pages.
• Creating Navigation Menus and Sidebars: Frame tag in HTML is often used to develop
fixed navigation menus or sidebars that remain visible while the remaining content on
the page undergoes alterations. Such a method guarantees effortless navigation and
provides a user-friendly means of accessing significant information or functions across
the entirety of the website.
• Displaying Content from Multiple Sources: iframes provide a seamless method of
incorporating external content, such as videos, maps, or social media feeds directly
into a webpage. This allows developers to effortlessly integrate dynamic content from
various sources without compromising the website’s overall design or performance.
• Enhancing User Experience: Frames in HTML can greatly improve the user experience
by enabling interactive content to load separately within a designated part of the
webpage. For example, iframes can be used to incorporate a chat widget or a real-time
data display, ensuring that these HTML elements update smoothly without having to
refresh the entire page.
Syntax of Frames
In HTML, there is no end tag for the <frame> tag. When we use frames in a
webpage, we use <frameset> tag instead of a <body> tag. Using <frameset> is
how we instruct the webpage to divide it into frames The <frame> tag defines
which HTML document should open as frame.
• The attribute cols take the value in pixels, and they help at specifying the
number and size of columns in a frameset.
<cols ="10%,80%,10%">
• Similarly, as we saw above, the attribute rows take the value in pixels, and
they help at specifying the number and size of rows in a frameset.
<rows ="10%,80%,10%">
However, it should be duly noted that the <frame> tag has deprecated in
HTML5 and it is no longer used.
Types of Frame Tag
Following are the different types of frame tags:
cols=”30%,*,30%”
2. Rows: The row attribute gives the horizontal frames. It
specifies the rows in a frameset. If we have to create three
horizontal frames we use:
• Eg: Rows=”10%,80%,10%’.
• We can also set the height of each row as we had done in
the case of columns previously
3. Border: It specifies the width of the border of each frame in pixels.
1. src: We provide the file name to this attribute that is supposed to be loaded into the frame.
The value of this attribute can be any URL.
2. name: This attribute provides a name to the frame. It defines which frame a document
should be loaded into. If you have multiple links in one frame that loads into another frame,
we use this attribute. Then the second frame needs a name to identify itself as the target of
the link.
E.g., name=”abc.htm.”
3. frameborder: This attribute is specified to show if the borders are to be shown or not. The
value takes up is 1 or 0 (Yes or No).
4. marginwidth: The attribute is helpful at specifying the width of the space between the left
and right of the frame’s border and also the content of the frame. The value is given in pixel.
E.g., marginwidth=”10”.
5. marginheight: The attribute is helpful at specifying the height of the space between
the top and the bottom of the frame’s border and also the content of the frame. The
value is given in pixel.
E.g., marginheight=”10”.
6. noresize: This attribute basically prevents the user from making any changes to the
already present frames. In the absence of this attribute, any frame can be resized.
E.g., noresize=”noresize.”
7. scrolling: This attribute takes control of the appearance of the scroll bars, which are
present on the frame. The value either a ‘yes, ‘no’, or ‘auto’.
8. longdesc: This attribute lets you provide a link to another page containing a long
description of the content of the frame.
E.g., longdesc=”framedesc.htm.”
Disadvantages of Frames
• When you use frameset you split the visual real estate of a
browser window into multiple frames. Each frame has it’s own
contents and the content in one don’t spill into the next.
<!DOCTYPE html>
<html>
<body>
<h1>Frame 1</h1>
<p>Contents of Frame 1</p>
</body>
</html>
The first document we’ll save as frame_1.html. The other three documents
will have similar contents and follow the same naming sequence.
Creating Vertical Columns
• To create a set of four vertical columns, we need to
use the frameset element with the cols attribute.
<!DOCTYPE html>
<html>
<frameset rows="*,*,*,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</html>
By making that one change, the frames now load as four rows stacked up
on top of eachother.
Mixing Columns and Rows
Columns and rows of frames can both appear on the same webpage by nesting one
frameset inside of another. To do this, we first create a frameset and then nest a
child frameset within the parent element. Here’s an example of how we could nest
two rows within a set of three columns.
<frameset cols="*,*,*">
<frameset rows="*,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
</frameset>
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
The nested frameset takes the place of the first frame within the parent
element. The nested element can be placed in any position. For example, if
we wanted the nested element to appear in the center position we would
just rearrange the elements like this.
<frameset cols="*,*,*">
<frame src="frame_1.html">
<frameset rows="*,*">
<frame src="frame_2.html">
<frame src="frame_3.html">
</frameset>
<frame src="frame_4.html">
</frameset>
<frameset cols="*,*">
<frame src="frame_1.html">
<frameset rows="*,*">
<frame src="frame_2.html">
<frameset cols="*,*">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</frameset>
</frameset>
These changes aren’t made with CSS. Instead, they are made
by adding attributes and values to the frame elements.
1. Sizing Frames
Frames can be sized either in pixels or percentages, or they can be set to
automatically adjust in size based on the available space. To specify the
size of a frame, insert the desired value in the cols or rows attribute.
The marginheight attribute applied to the first frame will add 15px of
margin above and below the content loaded in the first frame. The
frameborder value of 0 removes the borders from around the three
bottom frames.
Targeting Frames with Links
One of the most common uses of frames is to build sticky
navigation into a frame that is always visible regardless of the
position of the contents of the other frames. When properly
implemented, navigation links will cause new resources to
load in one frame while the other frames remain static.
• The webpage content and iframe contents can interact with each
other using JavaScript.
• The src attribute specifies the URL of the document you want to
embed.
• Iframes can include videos, maps, or entire web pages from other
sources.
Iframe Syntax
An HTML iframe is defined with the <iframe>
tag:
<iframe src="URL"></iframe>
Here, "src" attribute specifies the web address
(URL) of the inline frame page.
iframe attributes
Attributes Description
Specifies a set of extra restrictions on the content that can be loaded in
allow
an <iframe>.
allowpaymentr
Enables payment requests for content inside the <iframe>.
equest
Specifies the name of the <iframe> for targeting its content or for
name
referencing it in JavaScript.
sandbox Specifies an extra set of restrictions for the content in the <iframe>.
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.google.com/" height="300"
width="400"></iframe>
</body>
</html>
2. Remove the border of iframe
By default, an iframe contains a border around it. You can remove the
border by using <style> attribute and CSS border property.
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>
3. Iframe Target for a link
You can set a target frame for a link by using iframe. Your specified target
attribute of the link must refer to the name attribute of the iframe.
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
<!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>
<!DOCTYPE html>
<html>
<body>
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d30545.64987207887!
2d81.49729280000001!3d16.8656896!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x3a37b4b3ffffffff
%3A0x2ad71378ab4d0898!2sSri%20Vasavi%20Engineering%20College%20and%20pharmacy!5e0!3m2!1sen!2sin!
4v1722673066814!5m2!1sen!2sin" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy"
referrerpolicy="no-referrer-when-downgrade"></iframe>
<div class="myDiv">
<h2>This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>
</body>
</html>
nav
• The <nav> tag defines a set of navigation links.
mp3,wav,ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar
technologies are used to play the multimedia items.
<audio controls>
<source src="koyal.mp3" type="audio/mpeg">
Your browser does not support the html audio tag.
</audio>
Attributes of HTML Audio Tag
Attribute Description
controls It defines the audio controls which is displayed with
play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it
is ready.
loop It specifies that the audio file will start over again, every
time when it is completed.
muted It is used to mute the audio output.
preload It specifies the author view to upload audio file when
the page loads.
src It specifies the source URL of the audio file.
HTML Video Tag
HTML 5 supports <video> tag also. The HTML video tag is
used for streaming video files such as a movie clip, song
clip on the web page.
• mp4
• webM
• ogg
Example1:
<video controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the html video tag.
</video>
Example2: