3 Getting - Started - With - HTML
3 Getting - Started - With - HTML
Get
tingSt
art
edWi
thHTML
NOTES
Introduction to HTML
1
NOTES
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title> Hello, World!</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML page.</p>
</body>
</html>
Step 3: Open the file using any Browser and we are done with
our first HTML project.
2
NOTES
JavaScript
<!DOCTYPE html>
<!DocType html>
<!Doctype html>
<!doctype html>
What is a tag ?
3
NOTES
For example:
Opening tag: <tagname>
Closing tag: </tagname>
meta tag:
The <meta> tag in HTML is used to provide metadata about the
HTML document. Metadata is data about the data, and in the context
of HTML, it includes information such as the character set, page
description, keywords, author of the document, and viewport
settings.
JavaScript
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
● <meta charset="UTF-8">:
This meta tag specifies the character encoding for the HTML
document.
4
NOTES
● <meta name="viewport"
content="width=device-width,initial-scale=1.0">:
5
NOTES
<title>: This is the title tag, which sets the title of the web
page. In this example, it's set to "Hello, World!".
The words in the title are really important for getting your
webpage found in search engines (like Google). Search
engines use the title to figure out where to put your page in
the search results.
6
NOTES
● Don't just list words in the title. If you do, your webpage
might not show up as much in search results.
● So, try to make the title accurate and meaningful!
JavaScript
<!DOCTYPE html>
<html>
<head>
<title>My Webpage Title</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<p>This is a sample webpage with a title.</p>
</body>
</html>
Output:
7
NOTES
8
NOTES
If we inspect it( right click and tab the inspect button), we can
easily see that in the title tag.
9
NOTES
Note: We learn more in detail what is the use of inspect and all in
the upcoming lectures.
10
NOTES
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h1> First Heading</h1>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.
Consequuntur, at?</p>
</body>
</html>
Output:
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h1> First Heading
11
NOTES
Output:
In this example, the <h1> tag is not closed properly with a </h1> tag.
When you view this page in a web browser, the rendering will try to
interpret the content, but it causes unexpected results as above.
12
NOTES
1. Open Vs Code
2. Go to extensions: Look for the extensions icon on the
sidebar and click on it.
13
NOTES
Enjoy the magic: once installed , your new extensions are ready
to use. You might need to configure it but that's usually easy too.
14
NOTES
15
NOTES
16
NOTES
6. Stylelint - Link
Coding Police: Stylelint checks your code for errors and
style issues, making sure your code follows the rules.
Highlighting Mistakes: It points out mistakes with flashy
lights, so you can easily see what needs fixing
Code Excellence: By enforcing coding standards, Stylelint
helps your code look clean, professional, and consistent.
HTML Comments
Comments are useful when you want to write something about
the code but you do not want to run that or show in the output.
Comments are basically for humans, you write comments for
your future self or for other developers who might work on the
same codebase.
In HTML we can create a comment as shown below and the
browser will not display that on the screen.
17
NOTES
Example:
JavaScript
<!-- This is a comment -->
<h2>Single line comment</h2
In the above code we can see a single line comment, and this exactly
is the way to create a multi line comment.
JavaScript
<!- - This is a comment
This can be a multi line as well -- >
<h2>Multi line comments</h2>
In the example above we can see we have a multi line comment and
the syntax to create a multi line comment is similar to how we create
a single line comment.
18
NOTES
Best Practices
● Use comments sparingly.
● Do not write the obvious in the comments Ex: Do not write,
“this is a div tag, or “this is a p tag”
● Explain why you did what you did.
● If it is an expression then write the output.
● Use comments to document a piece of code, but do not just
rely on comments for documentation.
What is a tag ?
HTML uses a system of "tags" to define the structure and layout of
web pages. Tags are the building blocks of HTML documents and
consist of angle brackets enclosing specific keywords. These tags
provide instructions to web browsers on how to display the content.
For example:
19
NOTES
In HTML, some are self-closing tags or void tags because they don't
require a separate closing tag. These elements are used for elements
that don't contain any content or don't have a closing counterpart.
What is an element?
HTML elements are the building blocks of an HTML document.
HTML elements consist of a start tag, an end tag (if applicable), and
content in between the tags. The start tag defines the beginning of
an HTML element, and the end tag defines the end of an HTML
element.
20
NOTES
To put Heading in HTML doc, we use <h1>, <h2>, <h3> ...<h6> tags. From h1
to h6, represents different levels of content.
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
21
NOTES
<title>Heading</title>
</head>
<body>
<h1> Heading 1</h1>
<h2> Heading 2</h2>
<h3> Heading 3</h3>
<h4> Heading 4</h4>
<h5> Heading 5</h5>
<h6> Heading 6</h6>
</body>
</html>
Output:
Note: Browsers automatically add some white space(a margin) before and
after a heading.
22
NOTES
Note: Use HTML headings for headings only. Don't use headings to make the text
Big or Bold.
Example:
JavaScript
<p> This is a Paragraph </p>
<p> This is another Paragraph </p>
Output:
JavaScript
<h1> This is heading 1 </h1>
<p> This is some text </p>
<hr>
<h2> This is heading 2 </h2>
<p> This is some other text </p>
<hr>
Output:
23
NOTES
The <hr> tag is an empty tag, which means that it has no end tag.
4. HTML Line Breaks: The HTML <br> element defines a line break.
Use <br> if a line breaks ( a new line) without starting a new
paragraph.
JavaScript
Output:
The <br> tag is an empty tag, which means that it has no end tag.
24
NOTES
Introduction to Emmet
Emmet is a powerful web development tool that enhances
productivity by allowing web developers to write HTML and CSS code
using abbreviations and shortcuts. It originated as a plugin called
Zen Coding, created by Sergey Chikuyonok, and has since evolved
into a widely adopted tool by web developers.
What is Emmet?
Emmet is a shorthand syntax that helps you write HTML and CSS
code more quickly and efficiently. It uses abbreviations that expand
into standard HTML and CSS code, so you can write complex
structures with just a few keystrokes. This can save you a lot of time
and typing, and it can also help you write more consistent and
error-free code.
25
NOTES
26
NOTES
JavaScript
<div></div>
<p></p>
2. Nested Elements:
You can nest elements inside each other by using the >
(greater-than) symbol. For example:
JavaScript
<div>
<ul>
<li></li>
</ul>
</div>
27
NOTES
JavaScript
<div id="lead"></div>
<div class="container"></div>
4. Sibling Elements:
You can create sibling elements by using the + (plus)
symbol. For example:
JavaScript
<h1></h1>
<p></p>
5. Multiplication:
You can use multiplication operators (*) to generate
multiple elements. Specify the number followed by the
element abbreviation. For example:
28
NOTES
JavaScript
<ul>
<li></li>
<li></li>
<li></li>
</ul>
6. Text Contents:
To add text content to an element, enclose the desired text
within curly braces { }. For example:
JavaScript
<h1>Hello</h1>
7. Attributes:
You can include attributes in an element by using
square brackets [ ] and specifying the attribute name and value.
For example:
JavaScript
<a href="https://example.com"></a>
29
NOTES
JavaScript
<tagname attribute_name="attribute_value">
Global Attributes:
30
NOTES
Specific Attributes
They are designed to serve specific purposes and are only applicable
to their corresponding elements. Examples of specific attributes
include:
Style Attributes
The style attribute allows you to apply CSS (Cascading Style Sheets)
directly to HTML elements. CSS is a language that describes how
HTML elements should be displayed on the screen. It provides a wide
range of properties and values that you can use to control the
appearance of elements.
For example, let's consider a heading <h1> tag that you want to style.
You can use the style attribute to change its color, font size, and
alignment.
Here's an example:
31
NOTES
JavaScript
<h1 style="color: blue; font-size: 24px; text-align: center;">This is a
styled heading</h1>
Formatting tags in HTML are used to style text and change its
appearance.
JavaScript
<p>This is a <b>bold</b> word.</p>
32
NOTES
JavaScript
<p>This is an example of <strong>strongly emphasized</strong> text.</p>
Output:
JavaScript
<p>This is an <i>italicized</i> word.</p>
JavaScript
<p>This is an example of <em>emphasized</em> text.</p>
33
NOTES
5. Mark tag(<mark>):
The <mark> tag is a non-semantic tag used to highlight or mark
specific sections of text within the content. It is typically rendered
with a background color to visually distinguish the marked text. This
tag is useful for drawing attention to important or relevant
information, such as search terms or key findings within a document.
JavaScript
<p>This is <mark>highlighted</mark> text.</p>
6. Small tag(<small>):
The <small> tag is a non-semantic tag used to decrease the
font size of the enclosed text, making it appear smaller than the
surrounding text. It is often used to indicate secondary or
fine-print information, such as disclaimers, copyright notices, or
footnotes.
JavaScript
<p>This is some <small>smaller text</small> within a paragraph.</p>
34
NOTES
JavaScript
<p>This is <del>deleted</del> text.</p>
JavaScript
<p>This is <ins>inserted</ins> text.</p>
Output:
35
NOTES
JavaScript
<p>H<sub>2</sub>O</p>
Output:
JavaScript
<p>E = mc<sup>2</sup></p>
36
NOTES
Output:
11. <s> tag: The <s> tag is a non-semantic tag used to render text
with a strikethrough line, indicating that it is no longer valid,
relevant, or accurate. It is typically used for displaying content
that has been deprecated, crossed out, or should be ignored.
JavaScript
<p>This is <s>no longer relevant</s> information.</p>
Output:
JavaScript
<p>This is <big>large text</big> within a paragraph.</p>
37
NOTES
Output:
Let us see the most commonly used tags and whether they are inline
or block level elements
38
NOTES
● form
The above list contains the tags that are most commonly used, there are
many more tags apart from the ones mentioned above.
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
‹meta charset="UTF-8" />
‹meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<span>First Span,</span>
<span>Second Span, </span>
<span> Third Span.</span>
</body>
</html>
Output:
39
NOTES
JavaScript
<! DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div>First div, </div>
<div>Second div, </div>
<div>Third div.</div>
</body>
</html>
40
NOTES
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,
initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<span>First Span, </span>
<div>Second div, </div>
<div>Third div.</div>
</body>
</html>
Output
So they look exactly like the previous example, which shows a block
element will always sit in a new line.
Now are there any ways to make them sit inline? In short, yes we can
change their behavior using the CSS display property which we will
look at later in the course.
TIP: This is also a very important question that gets asked during
the interviews
41
NOTES
List
In HTML, a list is a structured way to present a collection of related items.
Lists are commonly used to organize and display information in a
structured and readable format. HTML provides several tags specifically
designed for creating different types of lists.
● ul
● ol
● dl
1. ul: It stands for an unordered list, which means every list item will
have a bullet point in front of it.
JavaScript
<!DOCTYPE html>
<html lang="en" >
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width,
initial-scale=1.0"
/>
<title>unordered list</title>
</head>
<body>
<ul>
<li>Item 1</li>
<li>Item 2</li>
42
NOTES
<li>Item 3</li>
<li>Item 4</li>
</ul>
</body>
</html>
Output
You see every list item is displayed with a bullet point in front of it. This
indicates it is an unordered list.
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
43
NOTES
<ul>
<li>Sub item</li>
<li>Sub item</li>
<ul>
<li>Sub sub item</li>
<li>Sub sub item</li>
</ul>
</ul>
</ul>
</body>
</html>
Output:
Ex:
JavaScript
<ul type="circle">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
44
NOTES
</ul>
Output:
JavaScript
<ul type="square">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
Output
NOTE: There is also a triangle, but not all the browsers support it.
45
NOTES
Similar to ul tag the li tag also supports type attribute with the following
values
type = "circle"
type = "square"
type = "disc"
Example:
JavaScript
<ul>
<li type="circle">item‹/li>
<li type="square">item</li>
<li type="disc">item</li>
</ul>
Output:
Note:
As these technologies evolved, it was decided that all styling should be
handled by CSS, leading to the deprecation of certain attributes in both
the li and ul tags. We'll cover how to achieve these effects using CSS later in
the course
2. Ol: It stands for ordered list, which means every list item will have
a number in front of it.
46
NOTES
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ol>
</body>
</html>
Output:
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Document</title>
</head>
47
NOTES
<body>
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<ol>
<li>Sub Item 1</li>
<li>Sub Item 2</li>
<ol>
<li>Sub sub Item 1</li>
<li>Sub sub Item 2</li>
</ol>
</ol>
</ol>
</body>
</html>
Output:
We also have a start attribute which we can use to define the start
number
JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Document</title>
48
NOTES
</head>
<body>
<ol start="3">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ol>
</body>
</html>
Output:
There is another handy attribute called type, which lets us change the
numbering style of the items list.
JavaScript
type = "1"
type = "A"
type = "a"
type = "I"
type = "i"
type = “1” is the default one
49
NOTES
JavaScript
<! DOCTYPE html>
<html lang="en">
<head>
50
NOTES
Output:
Note : Now, you must be thinking, is there a way I can change the ul bullet
list from circles to something else? In short, yes, we can change them to
something different with the help of CSS(We will learn this later in the
course). There is a way to change them in HTML using type attributes but it
is not preferred
Anchor tag
An anchor tag in HTML is represented by the <a> element and is
used to create hyperlinks within a web page. It allows you to link to
other web pages, files, sections within the same page, email
addresses, and more. The anchor tag is one of the fundamental
elements for navigation and linking in HTML.
51
NOTES
Syntax:
JavaScript
<a href= "URL">Link Text</>
The most commonly used attributes with the anchor tag are
● href
● target
● rel
1. href(Hypertext reference):
It specifies the destination URL or target of the link
JavaScript
<a href="https://aimerz.ai">Visit Aimerz Website</a>
With this a link will be created on the text Visit Aimerz website and
on clicking on this text the user will be redirected to aimerz.ai in the
same tab.
2. target:
It specifies where the linked document should be displayed.
● _self: This is the default value if we do not specify any
target attribute. This means open the link in the same
window.
Ex:
JavaScript
<a href="https://aimerz.ai" target="_self">Visit Aimerz Website</a>
52
NOTES
● _blank: If we use _blank this means open the link in a new tab.
Ex:
JavaScript
<a href="https://aimerz.ai" target="_blank">Visit Aimerz
Website</a>
Ex:
JavaScript
<iframe
width="300"
height="100"
style="border: 3px dashed #808cf8; padding: 30px 0 0 30px"
srcdoc="<a target='_parent' href='https://wikipedia.com'>Wikipedia</a>"
>
</iframe>
JavaScript
<iframe
width="300"
height="100"
style="border: 3px dashed #808cf8; padding: 30px 0 0 30px"
srcdoc="<a target='_top' href='https://wikipedia.com'>Wikipedia</a>"
>
</iframe>
53
NOTES
This unlike the _parent will move to the outermost section which is
the browser and replace the page.
Example, if we are in an online editor where the left hand side has
the editor and the right hand side has output preview, using _top will
replace the entire page with the destination URL.
Ex:
JavaScript
<p>
Click to learn more about
<a target="display-frame"
href="https://simple.wikipedia.org/wiki/JavaScript">Javscript Wikipedia
</a>.
< /p>
<iframe name="display-frame"
style="width:100%;height:600px;border:2px solid
#446e5; "></iframe>
3. rel
54
NOTES
● rel=”nofollow”:
Indicates to search engines that they should not follow the link
or pass any ranking authority to the linked page.
JavaScript
<a href="https://aimerz.ai" rel="nofollow">Visit Aimerz website</a>
JavaScript
<a href="https://aimerz.ai" rel="_blank">Visit Aimerz website</a>
● rel="stylesheet"
Specifies that the linked document is a style sheet used to
define the visual presentation of the current document.
This is one of the most common and important ones out there
that you will see yourself using whenever you have an external
stylesheet. Mostly you will see this in your head tag.
JavaScript
<link href="style.css" rel="stylesheet"
55
NOTES
● rel="icon":
Specifies that the linked document is an icon or image to be used as
the website's favicon (a small icon displayed in the browser's tab or
bookmark).
JavaScript
<link rel="icon" href="favicon.ico" type="image/x-icon" />
HTML Classes
● The class attribute assigns one or more class names to an HTML
element.
● Classes allow multiple elements to share the same styling or
behavior.
● Multiple classes can be assigned to an element by separating them
with spaces.
● Classes are defined in CSS stylesheets to apply specific styles to the
elements with those class names.
Ex:1
JavaScript
<div class="container">
<h1 class="heading">Aimerz!</h1>
<p class="content">Pure Hardwork, No Shortcuts! </p>
</ div>
Ex-2:
56
NOTES
JavaScript
<div class="container">
<h1 class="heading">Aimerz</h1>
<span class="content">Pure Hardwork</span>
<span class="content">, No Shortcuts!</span>
</div>
The example code above shows how to add class names to the HTML
tags.
HTML ID
● The id attribute is used to give a unique identifier to an HTML
element.
● Each ID must be unique within the HTML document.
● IDs are primarily used for targeting specific elements with CSS or
JavaScript.
● IDs are often used when you want to apply specific styling or perform
targeted actions on a single element.
JavaScript
<div id="container">
<h1 id="heading">Aimerz!</h1>
<p id="content">Pure Hardwork, No Shortcuts!</p>
</div>
57
NOTES
JavaScript
<div id="container">
<h1 id="heading">Aimerz</h1>
<p id="content tagline">Pure Hardwork, No Shortcuts!</p>
</div>
Tips
● Use ID for uniquely targeting the element via Javascript, or
giving the element some unique style, since ID must not
be reused.
● Use classes when you want to give a generic style to
elements since classes can be reused.
HTML Media
Image
58
NOTES
Syntax
JavaScript
<img src="image.jpg" alt="img tag syntax"/>
Ex:
JavaScript
<body>
<h1>Heading </h1>
<p>This is a random photo</p>
<img src="https://picsum.photos/200" alt="image" />
</body>
Output:
Suppose, we have given the wrong path to the src attribute, the
image will not be displayed we call it a broken image.
59
NOTES
JavaScript
<body>
<h1>Heading</h1>
<p>This is a random photo</p>
<img src="broken-image.jpg" alt="image alt text" />
</body>
Output:
Yes!! It will show the alt text that we provided in the <img> tag.
It is important to include alt text for images because it provides
information to users who may be unable to see the image due
to a slow internet connection, or a broken image link.
60
NOTES
JavaScript
<img src="image.jpg" width="200" height="150" alt="dog image"/>
61
NOTES
Example
JavaScript
<source
srcset="https://cdn.pixabay.com/photo/2023/07/30/11/30/spider-8158656_1280.j
pg"
media="(min-width: 700px)"
/>
<source
srcset="https://cdn.pixabay.com/photo/2023/07/04/10/30/dragonfly-8105988_128
0.jpg"
media="(min-width: 450px)"
/>
<img
src="https://cdn.pixabay.com/photo/2023/08/06/07/19/field-8172323_1280.jpg"
alt="photos"
/>
</picture>
Output:
62
NOTES
You can see in the above example, the browser displays different
images at different screen sizes, because it selects the most
compatible one.
Audio
Audio tag <audio/>
The Audio tag includes audio on our web page. <audio/> tag is
introduced in HTML5.
Syntax
JavaScript
Here, the src attribute can be a URL of an audio file, and the
controls attribute enables play, pause, and volume controls.
JavaScript
<body>
<audio
63
NOTES
controls
src="https://interactive-examples.mdn.mozilla.net/media/c
c0-audio/t-rex-roar.mp3">
</audio>
</body>
Output:
4. loop: The audio will loop and play repeatedly when this
attribute is present.
64
NOTES
JavaScript
<audio src="audio.mp3" controls controlsList="nodownload"></audio>
JavaScript
<audio src="audio.mp3" muted></audio>
65
NOTES
Ex:
JavaScript
<audio controls>
<source src="audio.opus" type="audio/ogg; codecs=opus" />
<source src="audio.ogg" type="audio/ogg; codecs=vorbis" />
<source src="audio.mp3" type="audio/mpeg" />
</audio>
The browser will try to play the first file format specified in the
<source> tag, and if it cannot play it, it will try the next one until
it finds a compatible file format.
Video
Syntax
JavaScript
66
NOTES
Here, the src attribute can be a URL of a video file, and the
controls attribute enables play, pause, and volume controls.
JavaScript
<body>
<video
src="https://interactive-examples.mdn.mozilla.net/media/c
c0-videos/flower.webm" controls width="250">
</video>
</body>
Output:
67
NOTES
4. loop: The video will loop and play repeatedly when this
attribute is present. For example;
JavaScript
<video src="video.mp4" width="640" height="360"></video>
JavaScript
<video src="video.mp4" poster="movie-poster.jpg" width="640" height="360"
controls></video>
68
NOTES
Just like the <audio> tag, the <video> tag can use the <source>
tag to provide alternative file formats to ensure that the video
can be played on a wide range of devices and web browsers.
Ex:
JavaScript
<video width="620" controls>
<source src="video.ogv" type="video/ogg" />
<source src="video.avi" type="video/avi" />
<source src="video.mp4" type="video/mp4" />
Sorry, your browser doesn't support embedded videos.
</video>
69
NOTES
70
NOTES
When you click that button, the website takes all the
information you provided in the input fields and sends it to the
website's server, kind of like sending a letter. The server then
processes that information and does whatever the website
needs it to do, like creating your account with the details you
provided.
JavaScript
<h1>Contact Form</h1>
<form action="/submit_form" method="post">
<!-- Form elements go here -->
</form>
71
NOTES
Form attributes
Behind the scenes, HTML forms use attributes to control the
behaviour and how the data is processed. Let's understand
these attributes using our Amazon sign-up example:
- action
The action attribute is like specifying the address where
you want to send your form. It tells the browser where to
submit the form data. The action attribute might look like
this: action="/signup_process". This means the form data
will be sent to the "/signup_process" URL on some website
server.
Ex:
JavaScript
<form action="/signup_process" method="post">
<input type="submit" />
</form>
Output:
- method
The method attribute determines how the form data is
sent to the server.
72
NOTES
Syntax:
JavaScript
<form method="get"></form>
<form method="post"></form>
Note: In the case of the GET method, after submitting the form,
form data is visible in the address bar. But the POST method
prevents form data from appearing in the address bar after the
form has been submitted, via sending data in the request body.
Example:
JavaScript
<form action="/signup_process" method="get">
<input name="email" />
<input name="username" />
<input type="submit" />
</form>
73
NOTES
- target
The action attribute accepts different values, each
influencing how the form response is handled.
74
NOTES
Syntax
JavaScript
<form target="_self"></form>
<form target="_blank"></form>
<form target="_parent"></form>
<form target="_top"></form>
JavaScript
<form action="/signup_process" method="post" target="_blank">
<input name="username" />
<input name="email" />
<input type="submit" />
</form>
- autocomplete
Controls whether the browser should remember and
autofill form input values. Values can be "on" (default) or
"off"
Ex:
JavaScript
<form action="/signup_process" method="post" >
75
NOTES
<label>Name</label>
<input name="username" autocomplete="on" />
<input type="submit" />
</form>
Output:
- enctype
specifies how the form data should be encoded before
sending it to the server. There are three common enctype
values:
● application/x-www-form-urlencoded (Default): It
encodes form data in a URL-like format, suitable for
regular form submissions with text input fields.
● multipart/form-data: Used for forms with file uploads.
It properly handles binary data, like images or
documents.
● text/plain: Rarely used, sends form data as plain text
without special formatting.
Syntax:
JavaScript
<form enctype="application/x-www-form-urlencoded"></form>
<form enctype="multipart/form-data"></form>
<form enctype="text/plain"></form>
76
NOTES
Example:
JavaScript
<form action="/signup_process" method="post" enctype="multipart/form-data">
<input name="filename" />
<input name="file" />
<input type="submit" />
</form>
77
NOTES
- name
Name of the form, it must a unique non-emply string.
Syntax
JavaScript
<form name="signup"></form>
- novalidate
A boolean attribute, which tells the browser to not validate
field values. We will study about validation in next lesson.
Syntax
JavaScript
<form novalidate></form>
- rel
It defines the relationship between current document and
the linked document. Its values could be,
- external: Indicates that the referenced document
exists outside the scope of the current website.
- help: Provides a link to a document designed to offer
assistance or guidance.
- license: Directs to copyright-related information
associated with the document.
- next: Refers to the subsequent document within a
series or selection.
- nofollow: Links to a document without an
endorsement, often used for paid links.
- noreferrer: Instructs the browser to not send an HTTP
referrer header.
78
NOTES
JavaScript
<form rel="noreferrer nofollow" action="">
Username <input type="text" /><br /><br />
Password<input type="password" /><br />
<input type="submit" value="submit" />
</form>
Form elements
Form elements in HTML are used to create interactive sections
where users can input data or make selections. Forms are a
fundamental part of web development, allowing users to
submit information to a server for processing. Here are some
elements that form contains:
79
NOTES
A simple example,
JavaScript
<label for="email">Enter Email: </label>
<input type="email" name="email" id="email" required>
Here <label> tags help users to know the purpose of the form
control element (input), and for attribute specifies the target
control element, which allows users to click on the label to focus
on the associated form control.
80
NOTES
index.html
JavaScript
<body>
<fieldset>
<legend>sign up</legend>
<form action="/signup_process" method="post" name="sign-up>
<label for=" username">Username:</label>
<input type="text" id="username" name="username" required><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"
required><br>
Output:
81
NOTES
3. Button Tag
It offers submitting a form or triggering specific actions, like
resetting the form fields.
Syntax
JavaScript
<button type="">Button Text<button/>
JavaScript
<form>
<label for="module">Module</label><br />
<input type="text" id="module" name="module" required /><br />
82
NOTES
Output:
As you see above, clicking a button with type “reset”, sets all
fields to its original value.
4. Datalist Tag
The <datalist> tag is used to provide an autocomplete feature
for <input> elements (We will study about input tags in detail in
next lesson). Users will see a drop-down list of predefined
options as they input data.
JavaScript
<h1>The datalist element</h1>
<label for="language">Choose your browser from the list:</label>
<input list="languages" name="language" id="language" />
<datalist id="languages">
<option value="java"> </option>
<option value="javascript"> </option>
<option value="python"> </option>
<option value="c++"> </option>
</datalist>
83
NOTES
5. Textarea Tag
The <textarea> element is used to create a multi-line text input
field that allows users to enter and edit text. The <textarea>
84
NOTES
6. Details Tag
JavaScript
<details>
<summary>Topic Name</summary>
Topic Details Here
</details>
Close state
Open State
85
NOTES
Input Tag
The <input> HTML element is one of the most important form elements
which is used to accept data/input from the user.
A wide variety of types of input data and control widgets are available
JavaScript
<label for="email">Enter Email: </label>
<input type="email" name="email" id="email"
required>
86
NOTES
Output:
Above code defines an email input for entering an email address. It also checks for
a valid email address.
Here < label > tags help users to know the purpose of the form control element
(input), and for attribute specifies the target control element, which allows users
to click on the label to focus on the associated form control.
Input Attributes
JavaScript
<h2>Contact Information</h2>
<form>
<label for="name" >Name: </label>
<input type="text" id="name" name="name" /><br /><br />
<label for="email" >Email:</label>
87
NOTES
Above example shows a form which takes name, email and phone
number as input.
88
NOTES
● value:
This attribute specifies the default value of the input control. It
is used to pre-fill the input field with a value that the user can
modify.
● placeholder:
This attribute specifies a short hint or example text that is
displayed in the input field to provide guidance to the user on
what should be entered
● step:
The step attribute is used with the < input> element of type
number or datetime-local to specify the increment value for the
input field. It defines how much the value of the input should
increase or decrease.
when the user interacts with the associated input control, such
as clicking the up/down arrows or using keyboard input. Step
89
NOTES
Example:-
JavaScript
<form>
<label for="quantity">Quantity(only in dozens/ multiple of 12):</label>
<input type="number" id="quantity" name="quantity" step="12" />
<input type="submit" />
</form>
Output:
● autocomplete:
The autocomplete attribute is used in HTML forms to control
whether a browser should automatically complete input fields.
The browser should display options to fill in the field, based on
earlier typed values. This
attribute can be applied to <input> elements of type text or
number, <textarea> elements, <select> elements,
and <form> elements. By default the value is on. We can turn
the auto-complete suggestions on a form by keeping the value
as off (autocomplete="off")
90
NOTES
Ex:
JavaScript
<form autocomplete="on">
<label for="name">Name: </label>
<input type="text" id="name" name="name" /><br /><br />
<label for="email">Email:</label>
<input type="email" id="email" name="email" autocomplete="off" /><br /><br
/>
<input type="submit" />
</form>
Now you can see that it's giving suggestions in the name field but
since we added autocomplete="off" in the
email input, it won't give any suggestions there.
91
NOTES
Boolean attributes
These boolean attributes are an essential part of HTML and are used to
control the behavior and properties of various elements without requiring
additional attribute values. Their presence or absence determines whether
a particular behavior or state is enabled or disabled, providing flexibility
and simplicity in HTMLmarkup. Kindly observe in attributes below how
they do not need any value.
Simplicity: Boolean attributes make the HTML markup more concise and
readable. They eliminate the need for explicit values, reducing clutter in the
code and making it easier for developers to understand and maintain.
● autofocus:
The autofocus attribute is an HTML attribute that can be applied to
specify that the input field should receive focus automatically when
the web page loads. This means that as soon as the page is loaded,
the cursor will be placed inside the input field, allowing the user to
start typing or interacting with it without needing to click on it first.
Ex:
JavaScript
<form>
<label for="username">Username: </label>
<input type="text" id="username" name="username" autofocus />
</form>
92
NOTES
As you can see in the above example, the input element getting
focused once the page is loaded and we can see that the cursor is
blinking which indicates that we can start typing
● multiple:
The multiple attribute is used with the ‹ input › element when
creating file upload fields "‹ input type="file"›" to allow users to select
multiple files for upload in a single input field. This attribute is
particularly useful when you want to enable users to upload multiple
files simultaneously.
Example:-
JavaScript
<label for="fileInput">Select multiple files:</label>
<input type="file" id="fileInput" name="fileInput" multiple />
93
NOTES
JavaScript
<label for="readonlyInput">Read-only ORDER-ID:</label>
<input
type="text"
id="readonlyInput"
name=" readonlyInput"
value="43459213"
readonly
/>
In the above example, the value in the input field cannot be edited by
the user.
● disabled:
94
NOTES
Example:-
JavaScript
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="user_name" value="Prabir" disabled />
<label for="age">Age:</label>
<input type="number" id="age" name="age" />
<input type="submit" value="Submit" />
</form>
● novalidate:
The novalidate attribute is used in HTML to disable the built- in form
validation provided by web browsers.
When this attribute is added to a <form> element, it instructs the
browser not to perform its default client-side validation checks when
the form is submitted.
For Example, if you have an input field for email and you have added
the type email. If you type some random text on that input field and
95
NOTES
JavaScript
<form method="post" novalidate>
<label for="user_email">Email:</label>
<input type="email" id="user_email" name="user_email" />
<input type="submit" value="Submit" />
</form>
JavaScript
<form>
<label for="email">Enter Email: </label>
<input
type="number"
name="salary"
placeholder="Enter your Salary"
value="100000"
required
/>
</form>
96
NOTES
Example:-
JavaScript
<label for="name">Name</label>
<input
type="text"
placeholder="write your name"
id="name"
name="name"
required
/>
97
NOTES
JavaScript
<label for="mailid">Mail Id</label>
<input type="email" id="mailid" name="mailid" />
Example:-
JavaScript
<label for="password">Password</label>
<input type="password" id="pass" name="pass" />
JavaScript
<label for="salary">Salary</label>
<input type="number" id="salary" name="salary" />
5. Checkbox:
● Checkboxes are a type of input field that allows the user to
select one or more options from a list of predefined options.
98
NOTES
Example:-
JavaScript
<label for="male">Male</label>
<input type="checkbox" id="male" name="male" />
<label for="female">Female</label>
<input type="checkbox" id="female" name="female" />
<label for="other">other</label>
<input type="checkbox" id="other" name="other" />
Output:
6. Radio:
● Radio buttons are a type of input field that allows the user to
select one option from a list of predefined options.
● The "name" attribute in the radio button (<input
type="radio">) tag is used to group related radio buttons
together so that only one radio button can be selected at a
time within a given group.
99
NOTES
Example:-
JavaScript
<label for="option1">option1</label>
<input type="radio" id="option1" name="selected" value="option1" />
<label for="option2">option2</label>
<input type="radio" id="option2" name="selected" value="option2" />
<label for="option3">option3</label>
<input type="radio" id="option3" name="selected" value="option3" />
7. Button:
The "button" type is used to create clickable buttons within a form or
on a web page. This works similarly to the <Button> element.
Ex:
JavaScript
<input type="button" value="Click me">
100
NOTES
8. Color:
The "color" type is used to create an input field that allows users to select a
color. When this input field is rendered in a web browser, it typically
displays a color picker dialog that lets users choose a color visually.
Example:-
JavaScript
<label for="colorPicker">Choose a color:</label>
<input type="color" id="colorPicker" name="color" />
9. Date:
The "date" input type is used to create an input field that allows users
to select a date. When you use this input type, it typically displays a
date picker or calendar control. This allows users to easily choose a
date
without having to manually enter it.
101
NOTES
Ex:
JavaScript
<label for="datePicker">Select a date:</label>
<input type="date" id="datePicker" name="selectedDate">
Output:
Additionally, you can use attributes like min and max to specify a range of acceptable
dates and the value attribute to set an initial date value.
Example:-
JavaScript
<input type="date" id="datePicker" name="selectedDate"
min="2023-01-01" max="2024-06-31" value="2023-08-24">
10. Datetime-local:
The "datetime-local" input type in HTML is used to create an input field
that allows users to select both a date and a time, including the year,
month, day, hour, and minute. It's particularly useful when you need to
collect date and time information together, such as scheduling events or
appointments.
102
NOTES
JavaScript
<label for="dateTimePicker">Select a date and time: </label>
<input type="datetime-local" id="dateTimePicker"
name="selectedDateTime">
Output:
When users interact with the datetime-local input, they can click on it to
open a calendar control for selecting the date and a time picker for
choosing the time.
11. file:
The "file" type is used to create a file input field in HTML forms. This type
of input allows users to select and upload files from their local devices to a
web server. It is commonly used for tasks such as uploading images,
documents, or other files to a website
JavaScript
<label for="fileUpload">Select a file:</label>
<input type="file" id="fileUpload" name="uploadedFile" />
103
NOTES
When users interact with the file input, they can click on it to open a file selection
dialog provided by their operating system. They can then browse their local files
and select the files) they want to upload.
12.Hidden
The "hidden" type is used to create a hidden input field in an HTML form.
Unlike visible input fields like text boxes or checkboxes, hidden input fields
are not visible to users when they view the form on a web page.
Instead, they are used to store data like, user ID, Session Id or many other
details which the user may not be aware of or you don't want a user to
manually type it but this data you still want to send to the backend/server
when the form is submitted.
JavaScript
<input type="hidden" name="hiddenField" value="This is a hidden
value" />
104
NOTES
Hidden input fields are a useful tool for working with forms and managing
data on the server-side without requiring user interaction or displaying
the data to users
13.image:
The "image" type is used to create an image-based submit button in HTML
forms. It allows you to use an image as the button instead of traditional text
or a styled button. When the user clicks on the image, it functions as a
form submit button and sends the form data to the server. The src
attribute is used to set the submit button image and alt attribute will act as
the label if it's unable to load that image
JavaScript
<input
type="image"
src="https://t4.ftcdn.net/jpg/00/28/27/95/360_F
_28279558_SqNXoZWsQLfWYVxyKe9hVzZ49dJtKLsc.jpg"
width="100"
height=" 70"
alt="Submit"
/>
Output:
The image-based submit button is a visually appealing way to create custom submit buttons
in your forms, especially when you want to use images or icons for better user experience.
14. month:
The "month" type is used to create an input field that allows users to
select a specific month and year. It provides a dropdown or spinner
interface that lets users choose a month and year without having to
manually enter the information.
105
NOTES
JavaScript
<label for="monthPicker">Select a month and year:</label>
<input type="month" id="monthPicker" name="selectedMonthYear" />
When users interact with the month input, they can click on it to open a dropdown
control that allows them to select a month and year. You can also set the min and
max attributes & values similar to that of we did in the date type
15.Range:
● The "range" type is used to create an input field that allows
users to select a value from a specified range,typically
represented as a slider control. It's often used in scenarios
where you want users to choose a value within a predefined
numeric range, such as setting a volume level, selecting a price
range, or adjusting a numerical setting.
● We can define the minimum and maximum and default initial
values of the range input element. There is also a step attribute
which specifies the increment by which the value can change.
JavaScript
<label for="volumeControl">Volume Control:</label>
<input type="range" id="volumeControl" name="volume" min="®" max="100"
step="1"
106
NOTES
107
www.
aimer
z.ai
THANK YOU
Vi
shwaMohan Vi
shwa.
mohan.
singh Vi
shwaMohan Vi
shwaMohan