Studocu Unit-1
Studocu Unit-1
Studocu Unit-1
UNIT-I: HTML-5
…………………………………………………………………………………………………………………….
HTML 5: Introduction to Web, Overview of Web Technologies, HTML - Introduction, HTML - Need,Case-
insensitivity, Platform-independency, DOCTYPE Declaration, Types of Elements, HTML Elements-
Attributes, Metadata Element, Sectioning Elements, Paragraph Element, Division and Span Elements,List
Element, Link Element, Character Entities, HTML5 Global Attributes, Creating Table Elements,Table
Elements : Colspan/ Rowspan Attributes, border, cellspacing and cellpadding attributes, CreatingForm
Elements, Input Elements -Attributes,Color and Date Pickers, Select and Datalist Elements,Editing Elements,
Media, Iframe, Why HTML Security, HTML Injection, Clickjacking, HTML5Attributes & Events
Vulnerabilities, Local Storage Vulnerabilities, HTML5 - Cross-browser support, BestPractices For HTML Web
Pages.
……………………………………………………………………………………………………………………
Introduction to Web:
Web consists of billions of clients and server connected through wires and wireless
networks. The web clients make requests to web server. The web server receives the request, finds the
resources and return the response to the client. When a server answers a request, it usually sends
some type of content to the client. The client uses web browser to send request to the server. The
server often sends response to the browser with a set of instructions written in HTML(HyperText
Markup Language). All browsers know how to display HTML page to the client.
Web Application:
HTTP is a protocol that clients and servers use on the web to communicate.It is similar to other
internet protocols such as SMTP(Simple Mail Transfer Protocol) and FTP(File Transfer Protocol)
but there is one fundamental difference.
HTTP is a stateless protocol i.e HTTP supports only one request per connection. This means
that with HTTP the clients connect to the server to send one request and then disconnects. This
mechanism allows more users to connect to a given server over a period of time.
The client sends an HTTP request and the server answers with an HTML page to the client,
using HTTP.
Backend Development: Backend is the server side of a website. It is the part of the website that users
cannot see and interact. It is the portion of software that does not come in direct contact with the users. It
is used to store and arrange data.
Frontend Languages: The front end portion is built by using some languages which are discussed below:
HTML: HTML stands for Hypertext Markup Language. It is used to design the front-end portion of
web pages using a markup language. HTML is the combination of Hypertext and Markup language.
Hypertext defines the link between the web pages. The markup language is used to define the text
documentation within the tag which defines the structure of web pages.
CSS: Cascading Style Sheets fondly referred to as CSS is a simply designed language intended to
simplify the process of making web pages presentable. CSS allows you to apply styles to web pages.
More importantly, CSS enables you to do this independent of the HTML that makes up each web page.
JavaScript: JavaScript is a famous scripting language used to create magic on the sites to make the site
interactive for the user. It is used to enhancing the functionality of a website to running cool games and
web-based software.
AJAX: Ajax is an acronym for Asynchronous Javascript and XML. It is used to communicate with the
server without refreshing the web page and thus increasing the user experience and better performance.
.
Backend Languages: The back end portion is built by using some languages which are discussed below:
PHP: PHP is a server-side scripting language designed specifically for web development. Since PHP
code executed on the server-side, so it is called a server-side scripting language.
Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript
code outside a browser. You need to remember that NodeJS is not a framework, and it’s not a
programming language. Most people are confused and understand it’s a framework or a programming
language. We often use Node.js for building back-end services like APIs like Web App or Mobile App.
It’s used in production by large companies such as Paypal, Uber, Netflix, Wallmart, and so on.
Python: Python is a programming language that lets you work quickly and integrate systems more
efficiently.
Ruby: Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. Ruby is
a pure Object-Oriented language developed by Yukihiro Matsumoto. Everything in Ruby is an object
except the blocks but there are replacements too for it i.e procs and lambda. The objective of Ruby’s
development was to make it act as a sensible buffer between human programmers and the underlying
computing machinery.
Java: Java is one of the most popular and widely used programming languages and platforms. It is
highly scalable. Java components are easily available.
JavaScript: JavaScript can be used as both (front end and back end) programming.
Golang: Golang is a procedural and statically typed programming language having the syntax similar to
C programming language. Sometimes it is termed as Go Programming Language.
C# :C# is a general-purpose, modern and object-oriented programming language pronounced as “C
sharp”.
DBMS: The software which is used to manage database is called Database Management System
(DBMS).
In the web technology world, below are the fundamental building blocks of any web page.
HTML (HyperText Markup Language) is the most fundamental building block of the Web. It defines the meaning
and structure of web content.
CSS(Cascading Style Sheet) is used for styling and giving better presentation to the web pages
To develop a web application using HTML, you can use simple editors such as Notepad or go for IDEs like Visual
Studio Code(recommended), Eclipse etc. which makes coding easier.
And, to execute application, you can use any commonly used browser such as Google Chrome(recommended),
Mozilla Firefox etc.
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.
In a web page, all instructions to the browser are given in the form of HTML tags, also known as HTML elements.
The content of the web page will be rendered as per the HTML tags in which they are enclosed.
The text content "Hello World!" is annotated to the heading, increasing the font-weight when it is
enclosed in the HTML tag <h1>.
Likewise, the look and feel of the web page can be defined and the content can be organized on the web page with
the help of various HTML elements.
HTML document structure tells the browser how to render the text written in each of the HTML elements of the web
page.
Consider that we need to create a web page, the basic HTML document structure will be as below:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title></title>
5. </head>
6. <body>
7. </body>
8. </html>
The following are some key elements in HTML that form the basic structure of a web page.
<!DOCTYPE html> declaration update the browser about the version of HTML being used. By default, it
points to HTML5, the latest 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'.
o 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
Metadata is in-general, data about data.
<meta> Used to specify page description, author of the document, last modified, etc.
Used by browsers (control how to display content or reload the page), search engines
(keywords), or other web services.
Post HTML5, meta tag also allows web designers to take control over the viewport by setting
the meta viewport tag.
<style> Defines style information for the web page
<link> Defines a link to other documents like CSS
<script> Defines script like JavaScript
The body section is denoted within the start tag <body> and ends with the end tag </body>. This section
contains actual web page content like text, images, etc.
<html>...</html> tag
<head>...</head> tag
<body>...</body> tag
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
This is a paragraph.
Features of HTML:
It is easy to learn and easy to use.
It is platform-independent.
Images, videos, and audio can be added to a web page.
Hypertext can be added to the text.
It is a markup language.
Why learn HTML?
It is a simple markup language. Its implementation is easy.
It is used to create a website.
Helps in developing fundamentals about web programming.
Boost professional career.
Advantages:
HTML is used to build websites.
It is supported by all browsers.
It can be integrated with other languages like CSS, JavaScript, etc.
Disadvantages:
HTML can only create static web pages. For dynamic web pages, other languages
have to be used.
A large amount of code has to be written to create a simple web page.
The security feature is not good.
Case-insensitivity:
HTML elements are case-insensitive. The browser understands the HTML tags irrespective of their cases.
Consider the code snippets below, copy the snippets to your workspace and observe the output
Code 1:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Homepage </title>
5. </head>
6. <body>
7. Hello World!
8. </body>
9. </html>
10.
Code 2:
1. <!DOCTYPE html>
2. <htmL>
3. <head>
4. <title>Homepage </title>
5. </head>
6. <body>
7. Hello World!
8. </boDy>
9. </HTML>
10.
11.
You can observe that both codes generate the same output as below:
Platform-independency:
HTML Language is platform-independent. That means the same HTML code can run on different
operating systems as shown below.
Sample.html
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>sample page</title>
5. </head>
6. <body>
7. <p>Hello World!</p>
8. </body>
9. </html>
Output:
On executing the above-mentioned code we can observe the same output in different platforms as shown below:
DOCTYPE Declaration:
There are many versions of HTML out there such as - HTML 2.0, HTML 3.0, HTML
3.2, HTML4.0, HTML 4.01 and latest is HTML5.0. In each version, some elements and attributes are either added
or depreciated. The appearance of your .html page depends on how the browser renders HTML elements. And how
the browser renders HTML elements depends on how the browser understands them.
Thus, to ensure that the browser understands all HTML elements specific to a particular version, as a developer you
need to tell the browser what version of HTML you have followed while developing your web page.
This is done by using <!DOCTYPE> declaration which stands for Document Type. It tells the browser what version
of HTML it should follow for rendering the web page.
Sample.html:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title> Sample page </title>
5. </head>
6. <body>
7. Hello world!
8. </body>
9. </html>
In the above code, <!DOCTYPE html> signifies that, the code is written in HTML5.
Provide a proper DOCTYPE declaration while designing an HTML web page, so that browser can understand the
version and interpret elements of the web page appropriately.
Types of Elements:
Block Element:
A block element begins on a new line occupying the entire width of the parent tag.
Inline Element:
An inline element occupies the necessary space to accommodate the content in the element. Inline elements can
be nested within other inline elements, whereas, block elements cannot be nested within inline elements.
<address>, <article>, <aside>, <blockquote>, <canvas>, <dd>, <div>, <dl>, <dt>, <fieldset>,
<figcaption>, <figure>, <footer>, <form>, <h1>-<h6>, <header>, <hr>, <li>, <main>, <nav>,
<noscript>, <ol>, <output>, <p>, <pre>, <section>, <table>, <tfoot>, <ul> and <video>.
Output:
tag, which defines a section in a web page, and takes full width of page.
We have used style attribute which is used to styling the HTML content, and the background color are
showing that it's a block level element..
**Following are The Inline elements are mostly used with other elements.
<a>, <abbr>, <acronym>, <b>, <bdo>, <big>, <br>, <button>, <cite>, <code>, <dfn>, <em>, <i>,
<img>, <input>, <kbd>, <label>, <map>, <object>, <q>, <samp>, <script>, <select>, <small>,
<span>, <strong>, <sub>, <sup>, <textarea>, <time>, <tt>, <var>.
Example:(a,span)
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <a href="https://www.javatpoint.com/html-tutorial">Click on link</a>
7. <span style="background-color: lightblue">this is inline element</span>
8. <p>This will take width of text only</p>
9. </body>
10. </html>
Test it Now
Output:
Syntax
1. <element attribute_name="value">content</element>
2.
Example
<!DOCTYPE html>
1. <html>
2. <head>
3. </head>
4. <body>
5. <h1> This is Style attribute</h1>
6. <p style="height: 50px; color: blue">It will add style property in element</p>
7. <p style="color: red">It will change the color of content</p>
8. </body>
9. </html>
Output:
Example:
<img src="whitepeacock.jpg" height="400" width="600">
CODE:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
OUTPUT:
HTML COMMENT:
As a developer, you may want to document your code, so that you can easily refer to it in the future.
Metadata Element:
The <meta> tag defines metadata about an HTML document. Metadata is data
(information) about data.
<meta> tags always go inside the <head> element, and are typically used to specify
character set, page description, keywords, author of the document, and viewport
settings.
Metadata is used by browsers (how to display content or reload page), search engines
(keywords), and other web services.
There is a method to let web designers take control over the viewport (the user's visible
area of a web page), through the <meta> tag (See "Setting The Viewport" example below).
Value
Attributes:
Attribute Description
charset character_set Specifies the character encoding for the HTML document
content Text Specifies the value associated with the http-equiv or name attribute
http-equiv content-security-policy Provides an HTTP header for the information/value of the content attribute
content-type
default-style
refresh
More Examples:
Setting the viewport to make your website look good on all devices:
The viewport is the user's visible area of a web page. It varies with the device - it will
be smaller on a mobile phone than on a computer screen.
You should include the following <meta> element in all your web pages:
This gives the browser instructions on how to control the page's dimensions and scaling.
The width=device-width part sets the width of the page to follow the screen-width of the
device (which will vary depending on the device).
The initial-scale=1.0 part sets the initial zoom level when the page is first loaded by the
browser.
Here is an example of a web page without the viewport meta tag, and the same web
page with the viewport meta tag:
Tip: If you are browsing this page with a phone or a tablet, you can click on the two links
below to see the difference.
Without the viewport meta tag With the viewport meta tag
Sectioning Elements:
Section tag is used to distribute the content i.e, it distributes the sections and
subsections.
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<section>
</section>
<section>
</section>
<section>
</section>
</body>
</html>
Output:
The below figure illustrates some of the widely used sectioning elements in HTML5.
<header>
The <header> element is used to include header content like web page logo, login link, website settings link, etc.
Ideally, every web page has one header. However, multiple headers may also be included as per need.
1. <header>
2. <h3>About Us</h3>
3. </header>
<footer>
The <footer> element is used to include footer content like copyright, about us, terms and conditions link, etc. One
footer is included per page.
1. <footer>
2. Copyright @ WayFar, 2020
3. <a href="./AboutUs.html">About Us</a>
4. </footer>
<main>
The <main> element is used for demarking the main content of the web page. Only one main tag per web page is
allowed.
1. <main>
2. <section>
3. ..
4. </section>
5. <section>
6. <article>
7. ..
8. </article>
9. <article>
10. ..
11. </article>
12. </section>
13. </main>
<nav>
The <nav> element is used for navigational content like navigation menu for the website. There is no limit to the
number of times <nav> tag can be used on a web page. As long as there are navigation links, links can be wrapped
inside <nav>.
1. <nav>
2. <a href="Home.html">Home</a>
3. <a href="Login.html">Login</a>
4. </nav>
<section>
The <section> element is used to organize the web page into different sections.
1. <main>
2. <section>
3. <p>Section 1</p>
4. </section>
5. <section>
6. <p>Section2</p>
7. </section>
8. </main>
1. <article>
2. <h1>MEAN stack</h1>
3. <p>MEAN stack training includes discussion on MongoDB, Node,
4. Express and Angular with the corresponding certifications</p>
5. </arcicle>
<aside>:
The <aside> element is used to include content related to the main content of the web page.
1. <article>
2. <h1>MEAN stack</h1>
3. <p>MEAN stack training includes discussion on MongoDB, Node, Express and
Angular with the corresponding certifications</p>
4. <aside>
5. <p>Visit our official website to attempt our certifications</p>
6. </aside>
7. </arcicle>
<address>:
The <address> element helps to semantically organize address details in HTML content.
1. <address>
2. John
3. #231A
4. Palace Lane
5. Bangalore
6. </address>>
Paragraph Element:
The paragraph element is generally used for denoting a paragraph. Any textual content can be mentioned inside
this element.
demo.html
1. <!DOCTYPE html>
2. <html>
3. <body>
4. <p>This is a Paragraph</p>
5. </body>
6. </html>
Output:
If any common rule or style needs to be added to a particular section, the same can be applied to the corresponding
division. The rule or style gets applied to all the contents of the division thereby.
<!DOCTYPE>
<html>
<body>
</div>
</body>
</html>
OUTPUT:
SPAN TAG:
The <span> tag does not have any default meaning or rendering.
Syntax
1. <span>Write your content here......</span>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Span Tag</title>
5. </head>
6. <body>
HTML div element is used to wrap large sections of HTML span element is used to wrap small portion of texts,
elements. image etc.
Output:
NOTE:The <span> tag does not contain any specific attribute in HTML.
HTML Lists are used to specify lists of information. All lists may contain one or more list
elements. There are three different types of HTML lists:
In the ordered HTML lists, all the list items are marked with numbers by
default. It is known as numbered list also. The ordered list starts with <ol> tag and the list items start
with <li> tag.
CODE:
<!DOCTYPE>
<html>
<body>
<ol>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ol>
</body>
</html>
OUTPUT:
1. Aries
2. Bingo
3. Leo
4. Oracle
Code:
<h1>Courses offered:</h1>
<li>HTML5</li>
<li>CSS</li>
<li>JS</li>
<li>Bootstrap</li>
</ol>
Some of the attributes which can be used with this element are:
Name Description
Start Specifies the initial value of the list.
Specifies the pattern to be rendered in reversed order.
reversed
For example:
1. <h1>Courses offered:</h1>
2. <ol type="a" start="d" reversed>
3. <li>HTML5</li>
4. <li>CSS</li>
5. <li>JS</li>
6. <li>Bootstrap</li>
7. </ol>
The above code will generate lists of course offered on the web page as shown below:
In HTML Unordered list, all the list items are marked with bullets. It is also
known as bulleted list also. The Unordered list starts with <ul> tag and list items start with the <li>
tag.
<!DOCTYPE>
<html>
<body>
<ul>
<li>Aries</li>
<li>Bingo</li>
<li>Leo</li>
<li>Oracle</li>
</ul>
</body>
</html>
Output:
Aries
Bingo
Leo
Oracle
HTML Unordered List or Bulleted List displays elements in bulleted format . We can use unordered
list where we do not need to display items in any particular order. The HTML ul tag is used for the
unordered list. There can be 4 types of bulleted list:
o disc
o circle
o square
o none
To represent different ordered lists, there are 4 types of attributes in <ul> tag.
Type Description
Type "disc" This is the default style. In this style, the list items are marked with bullets.
Type "circle" In this style, the list items are marked with circles.
Type "square" In this style, the list items are marked with squares.
Type "none" In this style, the list items are not marked .
Test it Now
Output:
o HTML
o Java
o JavaScript
o SQL
ul type="circle"
1. <ul type="circle">
2. <li>Java</li>
3. <li>JavaScript</li>
4. <li>SQL</li>
5. </ul>
Test it Now
Output68.1Features
o Java
o JavaScript
o SQL
HTML Description list is also a list style which is supported by HTML and XHTML. It
is also known as definition list where entries are listed like a dictionary or encyclopedia.
The definition list is very appropriate when you want to present glossary, list of terms or other name-
value list.
Code:
<!DOCTYPE>
<html>
<body>
<dl>
<dt>Aries</dt>
<dt>Bingo</dt>
<dt>Leo</dt>
<dt>Oracle</dt>
</dl>
</body>
</html>
Output:
Aries
-One of the 12 horoscope sign.
Bingo
-One of my evening snacks
Leo
-It is also an one of the 12 horoscope sign.
Oracle
-It is a multinational technology corporation.
Antoher example:
1. <dl>
2. <dt>HTML</dt>
3. <dd>is a markup language</dd>
4. <dt>Java</dt>
5. <dd>is a programming language and platform</dd>
6. <dt>JavaScript</dt>
7. <dd>is a scripting language</dd>
8. <dt>SQL</dt>
9. <dd>is a query language</dd>
10. </dl>
Output:
HTML
is a markup language
Java
JavaScript
is a scripting language
SQL
is a query language
LINK ELEMENTS:
Links are found in nearly all web pages. Links allow users to click their way from page to
page.
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.
Example
This example shows how to create a link to W3Schools.com:
CODE:
<!DOCTYPE html>
<html>
<body>
<h1>HTML Links</h1>
</body>
</html>
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.
Text hyperlink:
A clickable text is used to take the user to another web page. Largely, we use text-based hyperlinks.
This text usually appears with an underline and in a different color.
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:
Text hyperlink:
The text is mentioned within the start tag <a> and end tag </a> and is displayed on the screen in a clickable manner
Image hyperlink:
We can also have an image-based hyperlink. For this, we need to wrap the image inside an anchor tag.
1. <a href="http://www.google.com">
2. <img src="google.jpg" />
3. </a>
On click of the image, the user gets redirected and the google.com website gets loaded in the browser tab.
Bookmark hyperlink:
When a web page is lengthy, we commonly come across icons or links that say "Go to Top" or "Go to Bottom". Click
on these links does take the user to the top of the page or bottom, as applicable. Sometimes we also observe, on
click of a text in the menu bar, the page auto scrolls to that particular section on that page. This is achieved by using
the Bookmarking concept and the same is implemented by using hyperlinks.
1. <h2 id="top">Topic</h2>
2. <p>Detail……</p>
3. <p>Detail……</p>
4. <p>Detail……</p>
Email hyperlink:
On click of the link, the installed mail client on the computer gets activated for sending the email. An installed email
client should necessarily be installed on the computer for this to work.
CODE:EMAIL
<!DOCTYPE html>
<html>
<body>
<p>To create a link that opens in the user's email program (to let them send a new email), use mailto: inside the
href attribute:</p>
</body>
</html>
OUTPUT:
To create a link that opens in the user's email program (to let them send a new email), use mailto:
inside the href attribute:
Send email
character entities:
HTML character entities are used as a replacement of reserved characters in HTML. You
can also replace characters that are not present on your keyboard by entities.
These characters are replaced because some characters are reserved in HTML. HTML entities provide
a wide range of characters which can allow you to add icons, geometric shapes, mathematical
operators, etc.
For example: if you use less than (<) or greater than (>) symbols in your text, the browser can mix
them with tags that's why character entities are used in HTML to display reserved characters.
Syntax:
1. &entity_name;
2. OR
3. &#entity_number;
HTML processors must support following five special characters listed in the table that follows.
Example
If you want to write <div id = "character"> as a code then you will have to write as follows −
<!DOCTYPE html>
<html>
<head>
<title>HTML Entities</title>
</head>
<body>
<div id = "character">
</body>
</html>
This will produce the following result −
<div id = "character">
Attribute Description
contenteditable Allows the user to edit content. Possible values are true/false.
Dir Specifies text direction. Possible values are Itr/ rtl.
Title Displays the string message as a tooltip.
Specifies whether the spelling of an element's value should be checked or not. Possible values
Spellcheck
are true/false.
Id Gives a unique id to an element.
For example:
<html dir="ltr">
<body>
</body>
</html>
editable........................................EDITABLE
HTML table arranges content into rows and columns and can be used on websites for
the effective display of information in a tabular structure.
We can also create a complex tabular structure where contents can span across multiple columns/multiple
rows.
We can also create a complex tabular structure where contents can span across multiple columns/multiple
rows.
Table Elements :
The table header is for adding header information like column headers and the table body is for table contents.
Element Description
caption Defines table heading
Tr Defines row of the table
Th Defines heading of the column
Td Defines data of column
Thead Defines header part of the table
Tbody Defines the content part of the table
colgroup Helps to logically group two or more consecutive columns
Table Structure:
1. <table>
2. <caption>Table heading</caption>
3. <thead>
4. <tr>
5. <th>Column 1 heading</th>
6. <th>Column 2 Heading</th>
7. </tr>
8. </thead>
9. <tbody>
10. <tr>
11. <td>Column 1 data</td>
12. <td>Column 2 data</td>
13. </tr>
14. </tbody>
15. </table>
The above code snippet displays the below table on the web page:
Example:
<!DOCTYPE html>
<html>
<style>
table, th, td {
</style>
<body>
<table style="width:100%">
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
<p>To understand the example better, we have added borders to the table.</p>
</body>
</html>
OUTPUT:
16 14 10
The colspan attribute accepts a numeric value and merges specified numeric value of columns together whereas,
the rowspan attribute accepts a numeric value and merges specified numeric value of rows together.
For example, if we provide colspan attribute with a value 2, then 2 columns of the table will be merged as shown
below:
And, if we provide rowspan attribute with a value 2, then 2 rows of the table will be merged as shown below:
Code:
<!DOCTYPE html>
<html>
<body>
<table border="2">
<tr>
<th>Training Status</th>
</tr>
<tr>
<td rowspan="2">Oct'20</td>
<td>Jacob, #1002</td>
<td>Completed</td>
</tr>
<tr>
<td>Jeenie, #3001</td>
<td>In progress</td>
</tr>
</table>
</body>
</html>
Output:
When you add a border to a table, you also add borders around each table cell:
To add a border, use the CSS border property on table, th, and td elements:
!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
</style>
</head>
<body>
<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>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
Output:
Jill Smith 50
Eve Jackson 94
John Doe 80
<head>
<style>
table, th, td {
border-collapse: collapse;
</style>
</head>
Example
table, th, td {
border: 1px solid white;
border-collapse: collapse;
}
th, td {
background-color: #96D4D4;
}
…………………
Cell padding is the space between the cell edges and the cell content.
Example
th, td {
padding: 15px;
}
To add padding only above the content, use the padding-top property.
And the others sides with the padding-bottom, padding-left, and padding-right properties:
Example
th, td {
padding-top: 10px;
padding-bottom: 20px;
padding-left: 30px;
padding-right: 40px;
}
To change the space between table cells, use the CSS border-spacing property on
the table element:
Example:
<html>
<head>
<style>
table, th, td {
table {
border-spacing: 60px;
</style>
</head>
There has to be a mechanism through which a website can capture user inputs. This is why HTML forms have
been introduced.
HTML Forms, also known as Web Forms, help in capturing information from the user of a web application.
Users can key-in the details such as name, email, phone numbers, comments, dates, and other needed values
using the HTML form inputs. Users can also select from a predefined set of values.
method: Defaults to HTTP "get" method of submission to the server. To use HTTP "post", use
method="post"
action: The URL to which the form data has to be submitted
target: Specifies if the submitted result will open in the current window, a new tab, or on a new frame
The form input element is used to collect details from the user.
An <input> element can be displayed in many ways, depending on the type attribute.
Type Description
<input type="radio"> Displays a radio button (for selecting one of many choices)
<input type="checkbox"> Displays a checkbox (for selecting zero or more of many choices)
Let us learn some of the basic input types of HTML form and understand their implementation in short.
A single-line text field. The value attribute defines the value of the input field.
Defines an input text box, where the user can enter only numerical input.
Gives an error on form submission if the value entered goes beyond the min and max limits and includes
built-in validation to reject non-numerical values.
Attributes min and max can be used to define a boundary and step attribute value which can be used
for defining the difference between consecutive numbers.
Defines a checkbox.
The checked attribute checks that particular checkbox value.
Label:
The <label> element is used to associate a text label with a form <input> field. The label is used to tell users the
value that should be entered in the associated input field.
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.
EXAMPLE:
<!DOCTYPE html>
<html>
<body>
<form>
Enter the URL of the certified training if any: <input type="url" /> <br/> <br/>
<input type="submit"/>
</form>
</body>
</html>
OUTPUT:
Placeholder
Pattern
Min
Max
Step
Required
Multiple
Form-override
Placeholder:
The placeholder attribute specifies a value that appears in the textbox as below:
Pattern:
The value entered by the user is checked for validity against a specified pattern.
If the user input value does not match with a specified pattern, an error message appears.
The following are some of the attributes which are used only with range and number input types
Multiple:
The multiple attribute value allows the user to enter/select/upload more than one value.
Required:
If the user does not enter any value in the input field which is associated with this attribute, a default error
message appears on the screen.
Form-Override:
The override attributes can be used to override the form-level built-in attribute functionalities using the
submit/image input elements.
In the below example, you can observe that the default form submission method
'GET' has been overridden to the 'POST' method due to the usage of 'formmethod' attribute in the submit
input tag.
Defines a date-time picker, where the user can pick a date as well as time
<!DOCTYPE html>
<html>
<body>
<form>
</form>
</body>
</html>
OUTPUT:
Selectyourfavouritecolor:
<select> element :
<option value="+213">+213</option>
<option value="+91">+91</option>
<option value="+244">+244</option>
<option value="+61">+61</option>
<option value="+973">+973</option>
</select>
<datalist> element:
9. </datalist>
Code:
<!DOCTYPE html>
<html>
<body>
<form>
the user needs to select an option from the dropdown provided -->
<select>
<!-- When the input is collected through datalist, user can choose the vlue from the option list or they can
provide their own input through the input field -->
<datalist id="Technologies">
</datalist>
<input type="submit">
</form>
</body>
</html>
Output:
Editing Elements:
While developing any content-based application, there may be a requirement to get it reviewed.
While reviewing the content of our web page, the reviewer may want to add or delete some content.
Example:
Code:
<!DOCTYPE html>
<html>
<body>
</p>
</body>
</html>
Output:
Media:
Any website must be able to engage well with its visitors, be entertaining, and be able to quickly deliver
information.
Embedding content like audio clips, videos, images, maps, and so on... are a great way of engaging, be entertaining
and be able to quickly deliver information to the website users.
Pictures or moving pictures, maps, etc. typically draw user attention and trigger quite a lot of emotions. Humans find
it easy to connect to such information, rather than having to go through textual information.
This is why HTML provides tags for embedding media content like audio, video, and images and also for
embedding external content like maps.
Image Element:
Embedding images to a web page can be done with the <img>...</img> tag. The <img> tag has attributes 'src' and
'alt' where src defines the location of the image and alt defines the alternative text if it is failed to load the image
inside the web page.
Audio Element:
Embedding audio to a web page can be done with <audio>...</audio> tag. The <audio> tag has an attribute 'src'
which defines the location of the audio file. It also has an attribute 'controls' which specifies whether to display the
player controls.
Content between <audio> and </audio> tag will be shown by browsers who do not support audio element.
Video Element:
Videos can be embedded into web pages using <video>…</video> tag. The <audio> tag has an
attribute 'src' which defines the location of the audio file. It also has an attribute 'controls' which specifies whether to
display the player controls.
Content between <video> and </video> tag will be shown by browsers who do not support the video element.
Iframe:
We might have requirements to include documents, videos, interactive videos, or even other web content into
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
Code:
<html>
<body>
</body>
</html>
Web developers can use the new features in HTML5 for building
hybrid applications that can run on the web and mobile devices. Lots of data flow has to be handled
in these applications, therefore developers should take care of the attacks that are possible as well.
For example, an attacker can steal the data by inserting some wicked code through HTML forms
which will be kept in the database. Security flaws are possible if proper security measures are not
taken when using HTML5 features like communication APIs, storage APIs, geolocation, sandboxed
frames, offline applications, etc.
Therefore there is a need to find the attacks possible in all-new HTML5 features and their preventive
measures to defend against those attacks.
HTML Security
The following is the list of a few vulnerabilities that are possible in HTML:
1. HTML Injection
2. Clickjacking
5. Reverse Tabnabbing.
HTML Injection?
The main intention of this injection attack is to either change the website's appearance or to steal the
user's identity
Click jacking :
Let us now understand another attack called clickjacking and its consequences.
Hackers will have several ways to trick the user and make
them click on something which they are not supposed to. A common form of this attack involves
mirroring a login form on a website. Users will think that they are entering values in the actual HTML
form but they are actually entering them in the form fields that are overlaid on that web page. The
data which the user enters will be sent directly to an attacker's page. In this type of attack, hackers
will usually target sensitive data like passwords, bank account information, credit card information,
etc.,
1. There was an attack on one of the popular browser plugins, where an attacker added a
modified page in an iframe and can trick a user into changing settings of the plugin to get access to
the local system's resources such as a microphone, camera, etc.
2. A popular social networking site was attacked by tricking users to click on a button that will make
them retweet the location of the malicious web page which will be propagated hugely.
Clickjacking is frequently used to hijack accounts for spamming purposes or navigate links to
malicious web pages on online social network websites.
Using document.write() method or using innerHTML property, the resulting HTML code can be written
into DOM.
It is very important to identify a suitable sanitizer library for securing your application .
HTML5 has introduced Web storage or offline storage which deals with storing data in a local cache.
Data can be stored using two types of objects in HTML5. Local storage and Session storage. These
storages hold data in the form of key-value pairs.
Local storage holds the data in the browser cache until the user deletes it or it expires based on the
expiry date given. setItem() method is used to assign data to local storage. The below code creates
three items with names bgcolor, textcolor, fontsize and assigns the values to them.
localStorage.setItem("textcolor",document.getElementById("textcolor").value);
localStorage.setItem("fontsize",document.getElementById("fontsize").value);
getItem() method is used to fetch values from local storage. Below is the
codetoretrievevaluesfromlocalStoragedocument.
getElementById("page").style.backgroundColor = localStorage.getItem("bgcolor");
document.getElementById("page").style.color = localStorage.getItem("textcolor");
document.getElementById("page").style.fontSize = localStorage.getItem("fontsize");
Ideally, all browsers are supposed to implement the W3C specification of HTML5 as it is.
However, in reality, all browser vendors more or less customize the specification.
This leads to different outputs of the same HTML code when viewed on different browsers .
Activity: Copy below-given into your Visual Studio Code IDE workspace and save the
file as cross-browser.html.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>Cross Browser</title>
5. </head>
6. <body>
7. <form>
8. <label for="">Username</label>
9. <input type="text" name="username"> <br/>
10. <label for="">Password</label>
11. <input type="password" name="password"><br/>
12. <input type="submit">
13. </form>
14. </body>
15. </html>
Right-click on the file, copy the path, and paste it into different browsers such as Mozilla Firefox and
Google Chrome and observe the below output.
Hence, while developing your website, you need to consider the capabilities of your
user's browser - implement HTML5 features according to the capabilities of your user's
browser.
Browser Compatibleness:
To identify the capabilities of your browser you can refer www.caniuse.com website.
To identify whether your browser supports a particular HTML5 element or not, you can
refer www.html5test.com website.
1. In the application, ensure that each web page is having proper document structure with
divisions such as <head>, <body>, <header>, <footer>
2. Ensure that correct DOCTYPE is declared, which is required for the browser to understand the
standards of the application used to render it properly.
3. Use a meaningful title for the web pages.
4. Always close the tag even if it is not a container tag.
5. Avoid Inline styles and embedded scripts. Try to include script and style with external files
keeping your HTML code clean and neat.
6. Include the script as an external file and place this code at the end portion of the <body> tag.
7. Add the lang attribute to the root element, and keep the value as short as possible.
8. Even though HTML is case insensitive, using lowercase for code is the best practice.
9. Use the most appropriate HTML tag for sectioning the web page. Try to avoid the generic
<div> tag and use more meaningful tags such as <article>, <section> and appropriate tags in
the web pages.
10. Always use <ul> for designing navigation bars.
11. Avoid the use of the 'type' attribute in the HTML list element and use the corresponding CSS
property list-style-type property instead.
12. On embedding elements to the web page, use the alt attribute with a proper description text.
13. Indent nested elements properly.
14. Use appropriate type attribute for Input element inside forms, also ensure the form control is
wrapped with <label> element.
15. Use a sandbox attribute along with the iframe element whenever it is needed to embed
another webpage into the application.
16. Use rel attribute with a value "noopener noreferrer" along with hyperlink, to avoid reverse
tabnabbing.
17. Consider all the input data as untrusted information and sanitize those inputs before it is used
in some logic in the application.
18. Do proper output encoding to avoid chances of injection of malicious code to the application
through input elements.
Head Elements:
Tag Description Attributes Possible Values
<title> Specifies the title of the web page. None
<link> Specifies the hyperlink to an external source. href, rel rel="stylesheet"
href="mystyle.css"
<style> Specifies the CSS styling inside HTML page. None
<script> Specifies the JavaScript Code for the web page. None
<meta> Specifies the additional meta information for the name,content name='description',
web page. content="details of
web page content"
<a> Specifies hyper-link to either an external web page or href, rel, href
some other division of the same web page. target ="dummy.com"
rel=" noopener
noreferrer"
target="_blank,
_self,_parent
or _top"
Table Elements:
Embedded Elements: