Html5 Notes
Html5 Notes
HTML
#Web Terminologies
Example :- When you open YouTube from your phone, it connects through the
Internet to get videos from a YouTube server.
WWW (World Wide Web) :- The World Wide Web (WWW), often called the
Web, is a system of interconnected webpages and information that you can
access using the Internet.
Internet
└── WWW (websites, pages, links, images, videos)
└── www.google.com
└── www.wikipedia.org
Client :- A client is the device or software that requests data from a server.
Example :- When you open Chrome and type amazon.in , your browser is the
client.
Example:- YouTube's servers store all videos. When you click a video, a server
sends the video to you.
HTML 1
Browser:- A browser is a software application that lets you view websites
and use web apps.
Parts of a URL:
Example URL: https://www.example.com/page.html
https:// – Protocol
HTTP :- HTTP is a protocol (set of rules) that tells how data is transferred
between browser (client) and server.
Example:
When you open http://example.com , your browser talks to the server using HTTP.
MIME (Multipurpose Internet Mail Extension) :- MIME types tell the browser
what kind of file is being sent so it knows how to handle it.
Examples:
text/html → HTML file
HTML 2
video/mp4 → MP4 video
#Introduction to HTML
Hyper Text Markup Language (HTML) is a standard markup language to create
the structure of a web page. It annotates the content on a web page using
HTML elements.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
The following are some key elements in HTML that form the basic structure of a
web page.
HTML 3
version.
The <html> tag encapsulates the complete web page content. All other tags
are 'nested' within the <HTML> tag.
Any HTML document or web page consists of two main sections the 'head'
and the 'body'.
The head section starts with the start tag <head> and ends with the end
tag </head>.
Tags Description
<title> Defines the title that should be displayed on the browser tab
HTML is not case-sensitive but it is best practice to write name of all the
tags in lower case.
HTML is Platform-Independent.
HTML 4
Attributes :-HTML elements can contain attributes that can be considered
as an additional feature to set various properties and they are optional.
Comment :-As a developer, you may want to document your code, so that
you can easily refer to it in the future.
<!-- -->
HTML 5
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Meta tag example</title>
<!-- A web app wants to allow content from a current domain and truste dom
and all its subdomains -->
<meta http-equiv="content-security-policy" content="default-src 'self' http:/
<!-- page content display to be adjusted to the device width being used to v
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<p> Sample demo to explain meta tag with attributes </p>
</body>
</html>
Sectioning Elements
HTML 6
#Basics of HTML
HTML 7
<!--UNORDERED LIST (square , circle , disc)-->
<h1>Courses offered:</h1>
<ul style="list-style-type: square;">
<li>HTML5</li>
<li>CSS</li>
<li>JS</li>
<li>Bootstrap</li>
</ul>
<h1>Courses offered:</h1>
<ol type="a" start="d" reversed>
<li>HTML5</li>
<li>CSS</li>
<li>JS</li>
<li>Bootstrap</li>
</ol>
Description List
HTML 8
<!DOCTYPE html>
<html>
<body>
<dl>
<dt>The God of Small Things</dt>
<dd>The story is authored by Arunthati Ry and is set in Kerala and revolv
<dt>Shadow Lines</dt>
<dd>Shadow Lines is an invigorating story by Amitav Ghosh about the bo
<dt>The Lord of The Rings</dt>
<dd>An epic high fantasy book by the English author and scholar J.R.R.T
</dl>
</body>
</html>
Quotation Element
<!DOCTYPE html>
<html>
<body>
Below line has been referred from OWASP website:
<blockquote cite="https://owasp.org/">
The Open Web Application Security Project® (OWASP) is a nonprofit fo
</blockquote>
</body>
</html>
Link Element
HTML 9
A hyperlink is a prime way in which users can navigate from one web
page to another. A hyperlink can point to another web page, or website,
or files, or even specific locations on the same web page.
Hyperlinks can be of any of the below types:
Text hyperlink:
A clickable text is used to take the user to another web page. Largely, we
use text-based hyperlinks.
This color mapping is automatically done by the browser for all text
hyperlinks.
Image hyperlink:
Bookmark hyperlink:
A clickable text/image is used to take the user to another part of the same
web page.
Email hyperlink:
<a href="http://www.google.com">
<img src="google.jpg" />
</a>
<h2 id="top">Topic</h2>
<p>Detail……</p>
<p>Detail……</p>
HTML 10
<p>Detail……</p>
<a href="#top">Go to Top</a>
For example:
The table below lists widely used text-level semantic elements supported in
HTML5.
Element Description
HTML 11
sup Displays text as superscript
<strong>Text in bold</strong>
Character Entities
For example: If you use the less than (<) or greater than (>) sign in your
content, the browser may mix them with HTML tags.
Also, some characters are unavailable on the keyboard.
For example: ©
Character entities are used to include such character content on a web page
<!DOCTYPE html>
<html>
<body>
<p>
<body> is start tag of body element.
</p>
<p>
HTML 12
</body> is end tag of body element.
</p>
</body>
</html>
Global Attributes
Attributes that can be used with all HTML elements are called "Global
attributes".
The table below lists a few global attributes supported in HTML5.
Attribute Description
contenteditable Allows the user to edit content. Possible values are true/false.
For example:
<div>
<p contenteditable="true">This is editable</p>
<p dir="rtl">The direction of the text is from right to left</p>
<p title="mydemo">Hover your mouse here to see the title</p>
<p id="id1">ID should be unoque for each element</p>
</div>
#Table Element
HTML 13
<table>
<caption>MERN stack developer program</caption>
<colgroup>
<col>
<col style="background-color:lightblue;">
<col span="2" style="background-color: lightgreen;">
<col style="background-color: lightpink;">
</colgroup>
<tr>
<th>Technology</th>
<td >MongoDB</td>
<td >Node</td>
<td >Express</td>
<td>React</td>
</tr>
<tr>
<th >Description</th>
<td>The database</td>
<td>Node is the base for server side scripting</td>
<td>JS framework for web server development</td>
<td>JS library to design the front end</td>
</tr>
</table>
<!DOCTYPE html>
<html>
<body>
<table border="2">
<caption>Training Status of the Team</caption>
<tr>
<th colspan="2">Employee Details</th>
<th>Training Status</th>
</tr>
<tr>
<td rowspan="2">Oct'20</td>
<td>Jacob, #1002</td>
<td>Completed</td>
HTML 14
</tr>
<tr>
<td>Jeenie, #3001</td>
<td>In progress</td>
</tr>
</table>
</body>
</html>
#Form Element
HTML 15
The form input element is used to collect details from the user.
The table below lists the various types of input elements.
HTML 16
search Creates a search bar
Additionally, the "for" attribute of the label can point to the "id" of input control.
This ensures the cursor focuses on the respective input control on the click of
the label.
It also enhances the usability, by allowing the user to toggle the control by
clicking on text written within <label>…</label> tag.
<label>
Username:
<input type="text" name="username">
</label>
HTML 17
<option value="+61">+61</option>
<option value="+973">+973</option>
</select>
The following are some of the attributes which can be used with HTML input
elements.
HTML 18
Placeholder
Pattern
Min
Max
Step
Required
Multiple
Form-override
HTML 19
HTML 20
HTML 21
#EMBEDDED MEDIA
<figure>
<img src="tropicalSea.jpg"
alt="An image of tropical sea"
width="400"
height="341">
<audio>
<source src="myaudio.ogg" type="audio/ogg">
<source src="myaudio.mp3" type="audio/mp3">
</audio>
Some of the attributes which are supported by video element are as follows:
HTML 22
auto- entire audio file is
downloaded
The <iframe> element is used to meet the above requirement. Using the iframe
element, contents from external sources can be integrated anywhere on our
web page
<!DOCTYPE html>
<html>
<body>
<p>This demo loads the target of hyperlink into the same web page using
<a href="https://owasp.org/" target="myFrame">
Click here to load webpage content into iframe.
</a></br>
<iframe name="myFrame" width="600" height="400"></iframe>
</body>
</html>
Value Description
HTML 23
allow-forms Allows users to submit the form
#HTML SECURITY
As HTML applications are web-based applications, developers should take
proper measures to safeguard the stored data and communications. An
attacker can inject some malicious code via Bluetooth/wifi/text messages for
mobile-based apps or via advertisements/emails for web-based apps. This
malicious code can capture sensitive information and can expose it to the
attacker or it can run some undesired operations internally like sending false
messages or purchasing a product with zero amount etc.
The following is the list of a few vulnerabilities that are possible in HTML:
1. HTML Injection
2. Clickjacking
HTML 24
3. HTML5 attributes and events vulnerabilities
5. Reverse Tabnabbing
#HTML INJECTION
📦 Example:
HTML 25
A blog website allows users to comment. But it doesn't check the comment for
HTML.
Attacker comments:
<b>Hacked!</b> <script>alert('Gotcha!');</script>
Now, whenever anyone views that blog post, the script runs! 😱
🔁 Example:
A website shows your name from the URL like this:
https://example.com/welcome?name=Teju
And it says:
Welcome, Teju!
https://example.com/welcome?name=<script>alert('Oops')</script>
Welcome, <script>alert('Oops')</script>
🔹 Example:
User inputs:
<script>alert('Hacked!');</script>
<script>alert('Hacked!');</script>
✅ Output in browser:
It just displays the text, not runs it:
<script>alert('Hacked!');</script>
Sanitization = Remove or clean bad parts of input (e.g., strip HTML tags).
function sanitizeInput(input) {
return input.replace(/<[^>]*>?/gm, ''); // removes any HTML tags
}
🔹 Usage:
HTML 27
let userInput = "<script>alert('x')</script>";
let safeInput = sanitizeInput(userInput); // Output: alert('x')
🔹 Example (React):
In React, if a user enters:
<script>alert('x')</script>
#CLICKJACKING
🕵️♂️ What is Clickjacking?
Clickjacking is a trick where a user is fooled into clicking on something
invisible — like a hidden button — that does something dangerous without
them knowing.
Think of it as a "click trap".
🪤 Real-World Analogy:
HTML 28
Imagine you see a "Play Video" button on a website — but underneath it is a
hidden "Buy Now" or "Allow Camera" button.
When you click "Play", you're actually clicking the hidden button below. You
just got clickjacked.
💻 Example of Clickjacking
Let’s say there’s a real website:
https://bank.com/transfer?amount=1000&to=hacker
Now an attacker creates their own site with this invisible iframe:
<iframe src="https://bank.com/transfer?amount=1000&to=hacker"
style="opacity: 0; position: absolute; top: 0; left: 0; width: 100%; height: 1
</iframe>
Then they place a fake "Click here to win a prize!" button exactly where the real
transfer button is underneath.
You click — 💸 money gets transferred!
X-Frame-Options: DENY
OR
X-Frame-Options: SAMEORIGIN
HTML 29
✅ 2. Use Content-Security-Policy Header
This is a newer and better way:
In the above code snippet, the malicious script can be injected in formaction
attribute. To prevent this, users should not be allowed to submit forms with
form and formaction attributes or transform them into non-working attributes.
HTML 30
<input type="text" autofocus onfocus="alert('hacked')"/>
This will automatically get focus and then executes the script injected. To
prevent this, markup elements should not
<video src="/apis/authContent/content-store/Infosys/Infosys_Ltd/Public/lex_a
this code will run the script injected if the given source file is not available. So,
we should not use event handlers in audio and video tags as these are prone to
attacks.
🛡️ How to Prevent
1. HTML Sanitization
2. DOMPurify
HTML 31
DOMPurify is used for sanitizing HTML code. It is written in JavaScript and
works in all modern browsers. This library strip out dangerous HTML and
prevents XSS attacks by sanitizing the HTML code.
localStorage.setItem("bgcolor", document.getElementById("bgcolor").value);
localStorage.setItem("textcolor", document.getElementById("textcolor").value
localStorage.setItem("fontsize", document.getElementById("fontsize").value);
document.getElementById("page").style.backgroundColor = localStorage.getI
document.getElementById("page").style.color = localStorage.getItem("textcol
document.getElementById("page").style.fontSize = localStorage.getItem("font
HTML 32
Mitigation Techniques:
1. Never store sensitive information on client-side
2. Use cookies with the 'httponly' flag to protect the data stored at the client-
side
In the above code snippet username and password are keys, Smith and secret
are their corresponding values.
Below is the syntax of setting a cookie in the HTTP response header:
Set-Cookie: <name>=<value>[;<Max-Age>=<age>][;expires=<date>][;domai
#Reverse Tabnabbing
🔁 What is Reverse Tabnabbing?
Reverse Tabnabbing is a trick where a link you click can take control of your
original tab (the one you clicked from) and redirect it to a fake site — like a
fake login page.
It happens when you open links in a new tab ( target="_blank" ), but don’t protect
the original tab.
HTML 33
The new tab (badsite.com) can access the original page using window.opener and
run:
window.opener.location = 'https://fake-login.com';
Now your original tab gets redirected to a phishing page — and you might
think it's still the real site!
🧪 Simple Example:
Let’s say you’re on a bank website, and it has this innocent-looking link:
window.opener.location = 'https://fake-bank-login.com';
rel="noreferrer" does that and hides the referrer info (less common need)
HTML 34
2. Declare correct DOCTYPE: Use <!DOCTYPE html> to ensure standards
rendering.
4. Close all tags: Even for non-container elements like <br> , <img> , etc.
5. Avoid inline styles/scripts: Use external CSS/JS files to keep HTML clean.
9. Use semantic tags like <article> , <section> instead of <div> when possible.
10. Use <ul> for navigation bars instead of lists with type attributes.
14. Use correct input type and wrap inputs with <label> in forms.
15. Use sandbox with <iframe> for security when embedding content.
#Summary
Table Elements:
Possible
Tag Description Attributes
Values
HTML 35
<table> Specifies the table element. None None
Embedded Elements:
Specifies a self-
<figure> contained content along None None
with a caption.
HTML 36
Specifies the hyperlink to rel="stylesheet"
<link> href, rel
an external source. href="mystyle.css"
href
="dummy.com"
Specifies hyper-link to either
rel=" noopener
an external web page or
<a> href, rel, target noreferrer"
some other division of the
target="_blank,
same web page.
_self,_parent or
_top"
HTML 37
Specifies the Inline division of
<span> None
an HTML element.
type, start,
<ol> Specifies the ordered list. 1,I,I,a,A
reversed
Specifies paragraph
<p> None
element.
HTML 38
Specifies inserted text by
<ins> None None
underline.
Forms Element:
type=" text",
placeholder="Enter
Specifies the input type, placeholder,
<input> Username"
field. value, formaction
value=""
formmethod-"POST"
Specifies an input
<button> None None
button element.
Specifies the
value ="abc"
<option> options in the value, selected
selected= "true"
<select> drop down.
Displays output of
<output> None None
user input
HTML 39