UI Module Complete Notes
UI Module Complete Notes
1. HTML
2. CSS
3. JavaScript
4. Bootstrap
2 Projects
--------------------------------------------------------------------------------------------
---
Types of Applications
1. Standalone Applications/Desktop applications
2. Web applications
3. Distributed applications
4. Mobile Applications
5. IOT Applications
6. AI Applications
Web Application
An application whose resources are accessed from browser are
called web applications.
Example: gmail.com, facebook.com,…
Distributed Applications
An application whose resources are access on other device using
other applications can be called distributed application.
Example: Amazon, flipcart…
Mobile Applications
An application which runs inside module and does not uses any
other resources is called mobile applications
Example: calculator, clock, contacts, games
IOT applications
IOT stands for Internet Of Things.
IOT Applications are controlling devices using internet
AI, applications
AI stands Artificial Intelligence.
Example: Driver less Car
--------------------------------------------------------------------------------------------
--
Networking
What is networking?
Networking is logical or physical connection between two or more
devices.
Advantage of networking
1. Sharing Data/information
2. Sharing resources
Types of networks
1. LAN Local Area Network
2. MAN Metropolitan Network
3. WAN Wide Area Network
What is internet?
Internet is a wide area network (OR) networks of networks
1. Connection Oriented
2. Connection Less
History of Web
codewithsatishgupta
What is Web?
Web is a part of internet or restricted access on internet is called
web.
Web also called WWW (World Wide Web) or W3 is a system of
interconnected public web pages accessible through the Internet
Web is invented by a person called Tim Berners Lee
Web standards are maintained by a non profitable organization
called W3C (World Wide Web Consortium). Standards defines set
of rules and regulations for developing web applications or web
sites.
Current version of web is Web3.
Server
Server is a program/software which serves resources to one or
more than client. Server works based on two things
1. Request (input)
2. Response (Output)
Types of servers
1. Local Server
2. Cloud Server
Local Server
A server install in system is called local server
If application is installed in local server, it accessed by one
person.
Cloud Server
Installing web application/web site on cloud server, which allows
web application go live. It is accessed by the entire people
worldwide.
codewithsatishgupta
[email protected]
Q1: Explain directory structure of web application?
Web application/web site directory structured is divided into two
folder
1. Public
2. Src
Public folder contains static files or static resource (images, audio,
video, doc)
Src folder contains dynamic resources (css, javascript, java,…)
Physical path
A local directory or location where all application resources are
stored or saved.
Example: d:\flipcart
Virtual path
Always a website or web application is accessed using virtual
path.
This virtual path is called URL Uniform resource locator.
Q: What is ip-address?
Every computer or system in network is identified with unique
number called ip-address.
Q: What is portno?
Every project within server is identified with unique number called
portno.
What is webpage?
Web page is hyper text document which provides UI (User
Interface) for accessing resources.
.jsp
.php
.asp
.aspx
HTML
What is browser?
Browser is a software used to communicate with web application.
Browser is thin-client software.
Brower is able to open any content (html, images, audio, video,..)
History of HTML
Telegram:
codewithsatishgupta
History of HTML
Browser Architecture
Browser is a program/software which provides end user to
communicate with website or web application or server
1. Browser UI
2. Persistence (Bookmarks, Cookies, …)
3. Networking
4. Browser Engine
5. Render Engine
6. Java script engine
HTML tags/elements
codewithsatishgupta
HTML is a markup language
HTML is used for presentation of data and providing UI for
client/end User. It provides the user interface for accessing web
resources.
HTML is used for creating web pages.
HTML provides tokens and these are called tags. Each tag
represents one element.
Normal elements
An element which presents data without using any attributes.
This element required begins token/tag/element and end
token/tag/element.
Normal elements return values
Example: <b>…</b>
Example: <img>
RC Data elements
RC Data elements are called Rich Text Data elements.
These elements are used to represent plain text, numbers and
other content.
RC data elements/tag does not allow nested tags/elements.
Example:
©
Amount is ₹ 45,000/-
Foreign Elements
These elements are not comes default with HTML.
These elements are available in library.
Library must be imported in order to use.
Example: Canvas
Web Page
Syntax:
<html>
</html>
Syntax:
<html lang=”en-in”>
<html lang=”en-us”>
<html lang=”en-fr”>
<html lang=”en-uk”>
Syntax:
<html>
<head>
</head>
<body>
</body>
</html>
The content defined inside head is stored inside memory.
Whenever browser required it read from memory, without reading
from server. This avoids round trip.
This content defined inside body it does not store inside memory,
whenever browser required it read from server.
head
<title>…</title>
This tag is defined inside head.
This tag is used to define page title, which is displayed on title
bar.
This title also used in SEO Optimization.
Example:
<!DOCTYPE html>
<html lang="en-in">
<head>
<title>Flipcart</title>
</head>
</html>
<link>
This tag is used to link external resources
1. css files
2. favicon
There can be multiple <link> tags within head.
What is favicon?
Icon is a image, which is displayed before title on title bar.
This image must have extension “ico”
This size of this image must be small (15x15px)
Syntax:
<link rel=’relation-type’ href=”resource name/path”>
codewithsatishgupta
The following tags are used inside <head> tag
1. <title>
2. <link>
3. <meta>
4. <script>
5. <style>
meta
Responsive
Creating page responsive, the web page content fit according to
devices and screen.
For making page as responsive there are various approaches and
one of the approaches is using meta tag.
Note: this meta tag can be used more than one time
http://127.0.0.1:5500/public/index.html
SEO friendly
<meta charset=”UTF-8”>
</body>
</html>
codewithsatishgupta
[email protected]
<meta name=”keywords” content=”keywords”>
Example:
<meta name=”keywords” content=”java,oracle,HTML”>
Example:
<meta name=”description” content=”Best Training for HTML,
CSS, JS, JAVA, PYTHON in Hyderabad”>
<style>…</style>
This tag is used for defining CSS styles
<style>
</style>
<script>…</script>
It is used to insert or embed java script code
<script>
Java script coding
</script>
body
The content of web page is defined inside body tag.
The content is displayed within browser as a part of web page.
Syntax:
<body>
</body>
Example:
<header>
<footer>
<section>
<summary>
<nav>
<figure>
<time>
Etc…
1. <div>
2. <span>
<div>
<span>
This tag is used or embedded within line of text or continues text
or elements.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout Demo</title>
<style>
div{
border: 2px black solid;
margin: 10px;
padding: 5px;
}
span
{
color:blue;
}
</style>
</head>
<body>
<div>
Full Stack Python
<div>
Module-1 Python
<div>
Core Python
<div>
Python <span>Language</span> Fundamentals
</div>
</div>
<div>
Adv Python
<div>
OOP, Database, Exceptions<br>
Files, GUI, Date Time
</div>
</div>
</div>
<div>
Module-2 FrontEnd
<div>
HTML
<div>
Creating Web Pages
</div>
<div>
CSS
<div>
Styling Web Pages
</div>
</div>
</div>
</div>
</div>
</body>
</html>
codewithsatishgupta
Attributes of body tag
The following attributes are supported by body tag or element
1. Bgcolor
2. text
3. Background
4. Align
5. Leftmargin
6. Rightmargin
7. Topmargin
8. Bottonmargin
9. Alink
10. Vlink
bgcolor:
This attribute define the background color of body or webpage
These colors in HTML are represented in different formats
1. Color name
a. Solid color names
b. Shading color names
2. Color value
Solid color:
1. Red
2. Blue
3. Green
4. Pink
5. Yellow
6. Black
7. White
Shade colors:
1. Lightgreen
2. Lightblue
Color Value:
R Red 0-255
G Green 0-255
B Blue 0-255
Color value is represented in two formats
1. Single digit format
2. Double digit format
This color value is prefix with #
This color value technically are called hexacode(hexadecimal
value format)
Example:
<body bgcolor=”red”>
<body bgcolor=”yellow”>
<body bgcolor=”lightblue”>
<body bgcolor=”#00f”>
<body bgcolor=”#a0b”>
<body bgcolor=”#a10000”>
<body bgcolor=”#aa00bb”>
text
This attribute is used to define font color or text color
Example:
<body text=”red”>
<body text=”#00ff00”>
background
This attribute is used to define background image
Syntax:
<body background=”images/imagename”>
Syntax:
<style>
body
{
Background-size: width,height,cover,contain
Background-position: top, bottom, left, right,center
Background-repeat: no-repeat,repeat,repeat-x,repeat-y
Background-attachment : scroll,fixed
}
align
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout Demo</title>
<style>
div{
border: 2px black solid;
margin: 10px;
padding: 5px;
}
body
{
height: 100vh;
background-repeat: no-repeat;
background-position: center center;
background-size: 500px 500px;
background-attachment:fixed;
}
</style>
</head>
<body background="images/banner.avif" text="yellow">
<div>
Full Stack Python
<div>
Module-1 Python
<div>
Core Python
<div>
Python <span>Language</span> Fundamentals
</div>
</div>
<div>
Adv Python
<div>
OOP, Database, Exceptions<br>
Files, GUI, Date Time
</div>
</div>
</div>
<div>
Module-2 FrontEnd
<div>
HTML
<div>
Creating Web Pages
</div>
<div>
CSS
<div>
Styling Web Pages
</div>
</div>
</div>
</div>
</div>
<div>
Full Stack Python
<div>
Module-1 Python
<div>
Core Python
<div>
Python <span>Language</span> Fundamentals
</div>
</div>
<div>
Adv Python
<div>
OOP, Database, Exceptions<br>
Files, GUI, Date Time
</div>
</div>
</div>
<div>
Module-2 FrontEnd
<div>
HTML
<div>
Creating Web Pages
</div>
<div>
CSS
<div>
Styling Web Pages
</div>
</div>
</div>
</div>
</div>
</body>
</html>
[email protected]
codewithsatishgupta telegram
align
Left align text within body from left to right. In left alignment
flow of text is from left to right.
Right align text within body from right to left. In right alignment
flow of text is from right to left
Center align text within body in the middle or center. In center
alignment the flow of text is from center to left and right.
Justify align text within body according to width.
<!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 align="justify">
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quas
similique illum sunt sed praesentium a sint quidem non accusamus in
hic iste, necessitatibus voluptas qui voluptatem vitae expedita nam at.
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Numquam
molestiae harum animi nesciunt similique quisquam sapiente! Deleniti
vitae eligendi corporis ducimus earum ea praesentium eos officiis.
Laudantium laborum in adipisci.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nobis dolorum
iste iure neque cumque optio mollitia ab deserunt odit accusamus
quos, incidunt tempora eaque, labore itaque accusantium molestias,
blanditiis nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ratione ipsam
qui porro vero, ad possimus sunt. Magni itaque ab voluptate omnis
mollitia, veniam error fugit placeat odio aliquam nam <ipsa
class="lo"></ipsa>
</body>
</html>
Margins
Syntax:
<body
leftmargin=<value>,rightmargin=<value>,topmargin=<value>,
bottommargin=<value> >
Content
</body>
This margins sets the space between page border and content.
Example:
<body leftmargin=”50” topmargin=”50”>
Content
</body>
<!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 vlink="green" alink="red">
<a href="https://www.nareshit.com">NareshIt</a><br>
<a href="http://www.google.com">Google</a>
<a href="http://www.facebook.com">Facebook</a>
</body>
</html>
1. Bgcolor
2. Text
3. Background
4. Align
5. Leftmargin
6. Rightmargin
7. Topmargin
8. Bottommargin
9. Alink
10. Vlink
https://themes.getbootstrap.com/
<header>..</header>
Syntax:
<header>
tags
</header>
CSS styles
Syntax:
{
font-size: size;
font-family:font-name;
color:color;
font-weight:bold;
font-style:italic;
}
border-radius
Syntax:
{
Border-radius: sets radius for all the borders (left-top, left-
bottom, right-top, right-bottom)
Border- top-left radius:
Border-top-right- radius:
Border-bottom-left-radius:
Border-bottom-right-radius:
}
CSS display styles
Bootstrap icons
Bootstrap is CSS library.
In order to work with bootstrap icons use the following steps
1. Install nodejs
a. To use package manger called npm (node package
manager), it is used for managing packages(libraries)
Note: npm stands for node package manger
Open vscode
Open terminal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Header Demo</title>
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<style>
header{
font-size: 30px;
margin: 20px;
padding-left:20px;
padding-top:20px;
padding-bottom: 20px;
display: flex;
flex-direction: row;
justify-content:space-evenly;
}
.banner{
font-size: 50px;
font-family:"arial";
font-weight: bold;
}
</style>
</head>
<body>
<header>
<div>
<span class="banner">Shopper.</span>
</div>
<div >
<nav>
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Page</span>
<span>Blog</span>
<span>Docs</span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart"></span>
</div>
</header>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Header Demo</title>
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<style>
header{
font-size: 25px;
margin:10px;
padding-top:10px;
display: flex;
flex-direction: row;
justify-content:space-between;
}
.banner{
font-size: 35px;
font-family:"arial";
font-weight: bold;
}
.navbar span {
padding-right: 20px;
}
.icons span {
padding-right: 20px;
}
</style>
</head>
<body>
<header>
<div>
<span class="banner">Shopper.</span>
</div>
<div class="navbar" >
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Page</span>
<span>Blog</span>
<span>Docs</span>
</div>
<div class="icons">
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart"></span>
</div>
</header>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>SELL</title>
<style>
header{
display:flex;
justify-content: space-between;
margin-top: 40px;
border: 2px solid black;
padding: 20px;
background-color: bisque;
}
span{
padding-right: 10px;
}
.logo
{
font-size: 30px;
font-family: Arial, Helvetica, sans-serif;
}
.nav_bar
{
font-size: 20px;
}
</style>
</head>
<body>
<header>
<div class="logo">
<span>SELL.</span>
</div>
<div>
<nav class="nav_bar">
<span>HOME</span><span class="bi bi-chevron-down"></span>
<span>SHOP</span><span class="bi bi-chevron-down"></span>
<span>TEMPLATE</span><span class="bi bi-chevron-
down"></span>
<span>DROPDOWN</span><span class="bi bi-chevron-
down"></span>
<span>CONTACT</span>
<span>DOCS</span><span class="bi bi-chevron-down"></span>
</nav>
</div>
<div>
<span class="bi bi-search"></span>
<span class="bi bi-person-circle"></span>
<span class="bi bi-cart"></span>
</div>
</header>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LandKit</title>
<style>
header{
display:flex;
justify-content: space-evenly;
margin-top: 40px;
}
.logo
{
font-size: 30px;
font-weight: bold;
color:blue;
}
nav
{
font-size:25px;
}
.btn
{
font-size: 25px;
border:2px solid blue;
color:white;
background-color: blue;
}
span
{
padding-right: 20px;
}
</style>
</head>
<body>
<header>
<div class="logo">
<span>LandKit.</span>
</div>
<div>
<nav>
<span>Landings</span>
<span>Pages</span>
<span>Account</span>
<span>Documentation</span>
</nav>
</div>
<div>
<span class="btn">Buy Now</span>
</div>
</header>
</body>
</html>
CSS Colors
CSS provides various approaches for representation of colors
1. Color name
2. Shade Name
3. Hexa Code/HexaDecimal Value
4. rgb() function
5. rgba() function
6. hsl() function
7. hsla() function
8. linear-gradient
9. radial-gradient
1. Color Name
Each color in css represented as keyword.
1. Red
2. Blue
3. Green
4. Yellow
5. Cyan
6. Pink
2. Shade Name
Shade name is represented as keyword
1. Darkgreen
2. Darkred
3. Lightgreen
4. Lightred
3. HexaCode
4. rgb() function
Example:
{
Backround_color:rgb(100,50,120);
}
5. rgba(red,green,blue,alpha)
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Demo</title>
<style>
body
{
background-size: cover;
background-repeat: no-repeat;
}
div
{
height: 100vh;
background-color: rgba(0,0,0,0.7);
font-size:30px;
color:white;
text-align: center;
}
</style>
</head>
<body background="images/banner.avif">
<div>
This Text is inside Division
</div>
</body>
</html>
6. hsl() function
Example:
{
Background-color:hsl(120deg,70%,50%);
}
7. hsla() function
Example:
Example:
{
Background-color:hsla(120deg,70%,50%,0.5);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Demo</title>
<style>
body
{
background-size: cover;
background-repeat: no-repeat;
}
div
{
height: 100vh;
background-color: hsla(0,50%,30%,0.5);
}
</style>
</head>
<body background="images/banner.avif">
<div>
</div>
</body>
</html>
8. linear-gradient
9. radial-gradient
Syntax
{
Background-image:linear_gradient() or radial_gradient()
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Color Demo</title>
<style>
body
{
background-image: radial-gradient(red,yellow,green)
}
</style>
</head>
<body>
</body>
</html>
section
Syntax:
<body>
<header>
</header>
<section>
</section>
<footer>
</footer>
</body>
main
Syntax:
<body>
<header>
</header>
<section>
<main>
</main>
</section>
<footer>
</footer>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css"
<title>NetFlix</title>
<style>
body
{
background-size: cover;
background-repeat: no-repeat;
height: 100vh;
}
.cover
{
background-color:rgba(0,0,0,0.7) ;
height: 100vh;
margin: -20px;
}
header
{
color:white;
font-family: Arial;
padding:60px;
display:flex;
justify-content:space-around;
}
.brand-name
{
color:red;
font-size: 40px;
font-weight: bold;
}
.language
{
border:1px solid white;
padding:5px;
}
.btn-signin
{
border:1px solid red;
font-size: 20px;
margin-left: 20px;
background-color: red;
border-radius: 5px;
width:100px;
height:30px ;
display:inline-block;
text-align: center;
padding-top: 5px;
}
section
{
color:white;
font-family: Arial;
text-align: center;
margin-top: 120px;
}
.text1
{
font-size: 45px;
font-weight: bold;
margin-bottom: 10px;
}
.text2
{
font-size: 20px;
}
.text3
{
font-size: 20px;
margin-bottom: 50px;
}
main {
margin-top: 25px;
font-family: Arial;
font-size:20px;
}
.email
{
border:1px solid gray;
background-color: rgba(0,0,0,0.7);
padding:10px;
width:350px;
display:inline-block;
color:gray;
}
.start-btn
{
border:1px solid red;
background-color: red;
color:white;
padding:10px;
width:200px;
border-radius: 5px;
}
</style>
</head>
<body background="images/netflix-banner.jpeg">
<div class="cover">
<header>
<div class="brand-name">
<span>NETFLIX</span>
</div>
<div>
<span class="language">
<span class="bi bi-translate"></span>
<span>English</span>
<span class="bi bi-chevron-down"></span>
</span>
<span class="btn-signin">
Signin
</span>
</div>
</header>
<section>
<div class="text1">Unlimited movies, TV shows and more</div>
<div class="text2">Watch anywhere. Cancel anytime.</div>
<main>
<div class="text3"> Ready to watch? Enter your email to create or
restart your membership.
</div>
<div>
<span class="email">Email Address</span>
<span class="start-btn">
<span>Get Started</span><span class="bi bi-chevron-
right"></span>
</span>
</div>
</main>
</section>
</div>
</body>
</html>
<article> element
Syntax:
<article>
</article>
footer element
Syntax:
<footer>
</footer>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Header Demo</title>
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<style>
header{
font-size: 25px;
margin:10px;
padding-top:10px;
display: flex;
flex-direction: row;
justify-content:space-between;
}
.banner{
font-size: 35px;
font-family:"arial";
font-weight: bold;
}
.navbar span {
padding-right: 20px;
}
.icons span {
padding-right: 20px;
}
article
{
background-color: black;
color:white;
font-size: 25px;
padding:15px;
text-align: center;
}
article span{
color:darkgoldenrod;
}
.deals
{
color:white;
}
footer
{
margin-top: 200px;
background-color: black;
color:white;
text-align: center;
font-family: Arial;
padding-top:50px;
height: 200px;
}
.footer-want
{
font-size: 25px;
}
.footer-email
{
border:1px solid black;
background-color: rgb(65, 64, 64);
width:350px;
display:inline-block;
padding:20px;
text-align: left;
font-size: 15px;
color:gray;
}
.footer-sub-btn
{
border:1px solid black;
background-color: rgb(65, 64, 64);
color:white;
width:100px;
display:inline-block;
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
}
.footer1
{
margin-top: 30px;
}
</style>
</head>
<body>
<header>
<div>
<span class="banner">Shopper.</span>
</div>
<div class="navbar" >
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Page</span>
<span>Blog</span>
<span>Docs</span>
</div>
<div class="icons">
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-charge-fill" ></span>
<span class="deals">Happy Holiday Deals on Everything </span>
<span class="bi bi-lightning-charge-fill"></span>
</article>
<footer>
<div class="footer-want">Want style Ideas and Treats?</div>
<div class="footer1">
<span class="footer-email">Enter Email*</span>
<span class="footer-sub-btn">Subscribe</span>
</div>
<div>
<div>
<span>Shopper</span>
<span class="bi bi-facebook"></span>
<span class="bi bi-youtube"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-medium"></span>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div>
</div>
</div>
</footer>
</body>
</html>
CSS grid
1. grid-template-rows
2. grid-template-columns
Syntax
{
Display:grid;
Grid-templates-rows:
grid-template-columns:
}
This rows and columns are divided in fixed size or responsive size.
Fixed size is represented in pixels
Responsive size is represented in fractional
Example
{
display:grid:
grid-template-columns: 3fr 3fr 3fr 3fr
}
Example:
{
display:grid;
grid-template-columns:4fr 4fr 4fr;
}
Example:
{
Display:grid;
Grid-template-columns:2.5fr 2.5fr 2.5fr 2.5fr 2.5fr;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Header Demo</title>
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<style>
header{
font-size: 25px;
margin:10px;
padding-top:10px;
display: flex;
flex-direction: row;
justify-content:space-between;
}
.banner{
font-size: 35px;
font-family:"arial";
font-weight: bold;
}
.navbar span {
padding-right: 20px;
}
.icons span {
padding-right: 20px;
}
article
{
background-color: black;
color:white;
font-size: 25px;
padding:15px;
text-align: center;
}
article span{
color:darkgoldenrod;
}
.deals
{
color:white;
}
footer
{
margin-top: 200px;
background-color: black;
color:white;
font-family: Arial;
padding-top:50px;
height: 300px;
}
.footer-want
{
font-size: 25px;
text-align: center;
}
.footer-email
{
border:1px solid black;
background-color: rgb(65, 64, 64);
width:350px;
display:inline-block;
padding:20px;
text-align: left;
font-size: 15px;
color:gray;
}
.footer-sub-btn
{
border:1px solid black;
background-color: rgb(65, 64, 64);
color:white;
width:100px;
display:inline-block;
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
}
.footer1
{
margin-top: 20px;
text-align: center;
}
.service-title
{
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.services
{
display: grid;
grid-template-columns:2.5fr 2.5fr 2.5fr 2.5fr 2.5fr;
margin: 50px;
}
.services span {
display:block;
color:gray;
font-family: Arial;
}
.smedia {
display:flex;
justify-content:space-evenly;
}
</style>
</head>
<body>
<header>
<div>
<span class="banner">Shopper.</span>
</div>
<div class="navbar" >
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Page</span>
<span>Blog</span>
<span>Docs</span>
</div>
<div class="icons">
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-charge-fill" ></span>
<span class="deals">Happy Holiday Deals on Everything </span>
<span class="bi bi-lightning-charge-fill"></span>
</article>
<footer>
<div class="footer-want">Want style Ideas and Treats?</div>
<div class="footer1">
<span class="footer-email">Enter Email*</span>
<span class="footer-sub-btn">Subscribe</span>
</div>
<div class="services">
<div>
<span class="service-title">Shopper</span>
<div class="smedia">
<span class="bi bi-facebook"></span>
<span class="bi bi-youtube"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-medium"></span>
</div>
</div>
<div>
<span class="service-title">SUPPORT</span>
<span>Contact Us</span>
<span>FAQs</span>
<span>Size Guide</span>
<span>Shipping & Returns</span>
</div>
<div>
<span class="service-title">SHOP</span>
<span> Men's Shopping</span>
<span>Women's Shopping</span>
<span>Kids' Shopping</span>
<span>Discounts</span>
</div>
<div>
<span class="service-title">COMPANY</span>
</div>
<div>
<span class="service-title">CONTACT</span>
<address>
<span> 1-202-555-0105 </span>
<span>1-202-555-0106</span>
<span>[email protected]</span>
</address>
</div>
</div>
</footer>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
footer
{
height:200px;
background-color: black;
color: white;
font-family: Arial;
margin-top: 100px;
}
.back
{
background-color: gray;
text-align: center;
font-size: 20px;
}
.services
{
display:grid;
grid-template-columns: 3fr 3fr 3fr 3fr;
}
.title
{
font-size: 15px;
font-weight: bold;
}
.services span {
display:block;
padding-top:10px ;
}
</style>
</head>
<body>
<footer>
<div class="back">
<span >Back to Top</span>
</div>
<div class="services">
<div>
<span class="title">Get to Know Us</span>
<span>About Us</span>
<span>Careers</span>
<span>Press Releases</span>
<span>Amazon Science</span>
</div>
<div>
<span class="title">Connect with Us</span>
<span>Facebook</span>
<span>Twitter</span>
<span>Instagram</span>
</div>
<div>
<span class="title">Make Money with Us</span>
<span>Sell on Amazon</span>
<span>Sell under Amazon Accelerator</span>
<span>Protect and Build Your Brand</span>
<span>Amazon Global Selling</span>
<span>Become an Affiliate</span>
</div>
<div>
</div>
</footer>
</body>
</html>
1. header
2. footer
3. main
4. nav
5. address
6. article
7. section
css image properties
container
{
background-image: url(path);
background-size:cover,size;
background-repeat:repeat or no-repeat;
background-postion:center center;
background-attatchment: fixed;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Header Demo</title>
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-
icons.min.css">
<style>
header{
font-size: 25px;
margin:10px;
padding-top:10px;
display: flex;
flex-direction: row;
justify-content:space-between;
}
.banner{
font-size: 35px;
font-family:"arial";
font-weight: bold;
}
.navbar span {
padding-right: 20px;
}
.icons span {
padding-right: 20px;
}
article
{
background-color: black;
color:white;
font-size: 25px;
padding:15px;
text-align: center;
margin-bottom: 5px;
}
article span{
color:darkgoldenrod;
}
.deals
{
color:white;
}
footer
{
margin-top: 10px;
background-color: black;
color:white;
font-family: Arial;
padding-top:50px;
height: 300px;
}
.footer-want
{
font-size: 25px;
text-align: center;
}
.footer-email
{
border:1px solid black;
background-color: rgb(65, 64, 64);
width:350px;
display:inline-block;
padding:20px;
text-align: left;
font-size: 15px;
color:gray;
}
.footer-sub-btn
{
border:1px solid black;
background-color: rgb(65, 64, 64);
color:white;
width:100px;
display:inline-block;
padding: 20px;
font-family: Arial, Helvetica, sans-serif;
}
.footer1
{
margin-top: 20px;
text-align: center;
}
.service-title
{
font-size: 20px;
font-weight: bold;
margin-bottom: 10px;
}
.services
{
display: grid;
grid-template-columns:2.5fr 2.5fr 2.5fr 2.5fr 2.5fr;
margin: 50px;
}
.services span {
display:block;
color:gray;
font-family: Arial;
}
.smedia {
display:flex;
justify-content:space-evenly;
}
.main
{
display:grid;
grid-template-columns: 4fr 4fr 4fr;
font-size: 30px;
color:white;
}
.women
{
background-image: url(images/women-banner.avif);
background-size: cover;
height: 500px;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.ban{
font-size: 50px;
font-family: Arial;
font-weight: bold;
}
.men
{
background-image: url(images/men-banner.avif);
background-size: cover;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.kids
{
background-image: url(images/kids-banner.avif);
background-size: cover;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.btn{
border: 1px solid white;
background-color: white;
color:black;
padding:15px;
font-size: 15px;
}
</style>
</head>
<body>
<header>
<div>
<span class="banner">Shopper.</span>
</div>
<div class="navbar" >
<span>Home</span>
<span>Catalog</span>
<span>Shop</span>
<span>Page</span>
<span>Blog</span>
<span>Docs</span>
</div>
<div class="icons">
<span class="bi bi-search"></span>
<span class="bi bi-person"></span>
<span class="bi bi-heart"></span>
<span class="bi bi-cart"></span>
</div>
</header>
<article>
<span class="bi bi-lightning-charge-fill" ></span>
<span class="deals">Happy Holiday Deals on Everything
</span>
<span class="bi bi-lightning-charge-fill"></span>
</article>
<section>
<div class="main">
<div class="women">
<span class="ban">Women</span>
<span class="btn">Shop Women</span>
</div>
<div class="men">
<span class="ban">Men</span>
<span class="btn">Mens Shoping</span>
</div>
<div class="kids">
<span class="ban"> Kids</span>
<span class="btn">Kids Shoping</span>
</div>
</div>
</section>
<footer>
<div class="footer-want">Want style Ideas and Treats?
</div>
<div class="footer1">
<span class="footer-email">Enter Email*</span>
<span class="footer-sub-btn">Subscribe</span>
</div>
<div class="services">
<div>
<span class="service-title">Shopper</span>
<div class="smedia">
<span class="bi bi-facebook"></span>
<span class="bi bi-youtube"></span>
<span class="bi bi-twitter"></span>
<span class="bi bi-instagram"></span>
<span class="bi bi-medium"></span>
</div>
</div>
<div>
<span class="service-title">SUPPORT</span>
<span>Contact Us</span>
<span>FAQs</span>
<span>Size Guide</span>
<span>Shipping & Returns</span>
</div>
<div>
<span class="service-title">SHOP</span>
<span> Men's Shopping</span>
<span>Women's Shopping</span>
<span>Kids' Shopping</span>
<span>Discounts</span>
</div>
<div>
<span class="service-title">COMPANY</span>
</div>
<div>
<span class="service-title">CONTACT</span>
<address>
<span> 1-202-555-0105 </span>
<span>1-202-555-0106</span>
<span>[email protected]</span>
</address>
</div>
</div>
</footer>
</body>
</html>
=======================================
=========
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.main
{
display:grid;
grid-template-columns: 4fr 4fr 4fr;
font-size: 30px;
color:white;
}
.women
{
background-image: url(images/women-banner.avif);
background-size: cover;
height: 500px;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.ban{
font-size: 50px;
font-family: Arial;
font-weight: bold;
}
.men
{
background-image: url(images/men-banner.avif);
background-size: cover;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.kids
{
background-image: url(images/kids-banner.avif);
background-size: cover;
display:flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
.btn{
border: 1px solid white;
background-color: white;
color:black;
padding:15px;
font-size: 15px;
}
</style>
</head>
<body>
<div class="main">
<div class="women">
<span class="ban">Women</span>
<span class="btn">Shop Women</span>
</div>
<div class="men">
<span class="ban">Men</span>
<span class="btn">Mens Shoping</span>
</div>
<div class="kids">
<span class="ban"> Kids</span>
<span class="btn">Kids Shoping</span>
</div>
</div>
</body>
</html>
Css style
<div>
<span></span>
<span> </span>
</div>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.div1 span{
font-size: 40px;
color:red;
}
.div2 span{
font-size: 40px;
color:blue;
}
</style>
</head>
<body>
<div class="div1">
<span>Item1</span>
<span>item2</span>
</div>
<div class="div2">
<span>Item3</span>
<span>item4</span>
</div>
</body>
</html>
div+span { styling }
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
nav+span {
font-size: 30px;
}
</style>
</head>
<body>
<nav>
<span>Span1</span>
<span>Span2</span>
</nav>
<span>Span3</span>
</body>
</html>
CSS Center Screen for content
{
height: according to requirement;
display:flex;
justify-content:center;
align-items: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
font-size: 50px;
}
body
{
height:100vh;
display:flex;
justify-content: center;
align-items: center;
}
.text1
{
font-size: 15px;
font-weight: bold;
}
</style>
</head>
<body>
<div>
<div class="text1">New Collection</div>
<div>Best Picks 2019</div>
</div>
</body>
</html>
Syntax:
{
text-shadow: horizontal vertical blur color;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
font-size: 50px;
font-weight: bold;
text-align: center;
text-shadow: 10px 0px 5px red;
}
</style>
</head>
<body>
<div>Women</div>
</body>
</html>
Syntax:
<details>
<summary>Title</summary>
content
<details>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
summary{
margin-bottom: 10px;
font-size: 30px;
font-weight: bold;
color:red;
}
div
{
font-size: 30px;
}
</style>
</head>
<body>
<details>
<summary> What is NetFlix?</summary>
<div>Netflix is a streaming service that offers a wide variety of award-
winning TV shows, movies, anime, documentaries and more – on
thousands of internet-connected devices.</div>
<div>You can watch as much as you want, whenever you want, without
a single ad – all for one low monthly price. There's always something new
to discover, and new TV shows and movies are added every week!</div>
</details>
<details open>
<summary> What is NetFlix?</summary>
<div>Netflix is a streaming service that offers a wide variety of award-
winning TV shows, movies, anime, documentaries and more – on
thousands of internet-connected devices.</div>
</details>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
font-size: 25px;
font-weight: bold;
color:red;
}
fieldset
{
margin-bottom: 50px;
background-image: url(images/banner.avif);
background-repeat: no-repeat;
background-size: cover;
}
legend
{
font-size: 25px;
font-weight: bold;
color:blue;
text-align:center;
border: 2px solid black;
background-color: aqua;
border-radius: 5px;
}
</style>
</head>
<body>
<fieldset>
<legend>Personal Information</legend>
<div>FirstName</div>
<div>LastName</div>
<div>DateofBirth</div>
</fieldset>
<fieldset>
<legend>Education Qualification</legend>
<div>Education</div>
<div>University</div>
<div>Year</div>
</fieldset>
</body>
</html>
Headings
<!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>
<h1>Courses Offered</h1>
<h2>Full Stack Java</h2>
<h3>CoreJava</h3>
<h3>AdvJava</h3>
<h3>Database</h3>
<h3>UI</h3>
<h3>Tools</h3>
<h2>Full Stack .Net </h2>
C#.Net
ASP.Net
Database
Tools
<h2>Full Stack Python</h2>
Python
Python for Datascience
UI
Database
Tools
<h2>Full Stack DS & AI</h2>
DS
AI
</body>
</html>
The headings must be defined in sequential order.
It is not recommended to skip heading.
Inside the webpage or document <h1> element must be defined
one time.
Heading can be modified using css.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heading Demo</title>
<style>
body
{
margin-left: 40px;
}
h1 {
color:red;
font-size: 50px;
font-family: Arial, Helvetica, sans-serif;
}
.python
{
color:blue;
}
h2
{
color:green;
}
.UI
{
color:brown;
}
</style>
</head>
<body>
<header>
<h1>Full Stack Python</h1>
</header>
<article></article>
<section>
<div class="python">
<h2>Python</h2>
<h3>Core Python</h3>
<h3>Adv.Python</h3>
</div>
<div class="UI">
<h2>UI</h2>
<h3>HTML</h3>
<h3>CSS</h3>
</div>
</div>
</section>
<footer>
</footer>
</body>
</html>
Paragraph
Paragraph represents more than one line content.
Example: Description, information about heading,...
<p>…</p>
</style>
</head>
<body>
<h2>Course Overview</h2>
<p class="p1">Naresh IT offers comprehensive <span><b>Python
Online training</b></span>, available both online and in the classroom.
Python is widely recognized for its simplicity and versatility, making it a
highly sought-after high-level programming language. Our course is
designed to equip participants with a thorough understanding of Python
programming concepts, syntax, and applications. From fundamental
principles to advanced topics, learners will gain the skills needed to
develop software solutions, automate tasks, analyze data, and much more.
Join Naresh IT's Python training today for a rewarding learning
experience.</p>
<p class="p2">Learn <span>Python</span> Online training skills with
real experts, either in live classes with videos or without videos, whichever
suits you best.</p>
</body>
</html>
{
text-alignment:left/right/center/justify;
Color: text color
Background-color: background color;
Margin: all the margins;
Padding: space within border;
Border: paragraph border;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paragraph Demo</title>
<style>
.p1{
font-size: 25px;
color:red;
text-align: justify;
border: 2px solid black;
padding: 20px;
margin: 10px;
background-color: aqua;
background-image: url(images/banner.avif);
background-repeat: no-repeat;
background-size: cover;
}
.p2 {
font-size: 20px;
text-align: justify;
width:150px;
}
span
{
color:blue;
}
div
{
display:grid;
grid-template-columns: 6fr 6fr;
}
</style>
</head>
<body>
<h2>Course Overview</h2>
<p class="p1">Naresh IT offers comprehensive <span><b>Python
Online training</b></span>, available both online and in the classroom.
Python is widely recognized for its simplicity and versatility, making it a
highly sought-after high-level programming language. Our course is
designed to equip participants with a thorough understanding of Python
programming concepts, syntax, and applications. From fundamental
principles to advanced topics, learners will gain the skills needed to
develop software solutions, automate tasks, analyze data, and much more.
Join Naresh IT's Python training today for a rewarding learning
experience.</p>
<div>
<p class="p2">Learn <span>Python</span> Online training skills with
real experts, either in live classes with videos or without videos, whichever
suits you best.</p>
<p class="p2">Learn <span>Python</span> Online training skills with
real experts, either in live classes with videos or without videos, whichever
suits you best.</p>
</div>
</body>
</html>
.p1{
font-size: 25px;
color:red;
text-align: justify;
border: 2px solid black;
padding: 20px;
margin: 10px;
line-height: 100px;
background-repeat: no-repeat;
background-size: cover;
}
How to define line spaces, character spacing and word spacing
within paragraph?
Syntax:
p{
line-height:40px;
word-spacing:20px;
letter-spacing:20px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paragraph</title>
<style>
p{
font-size: 30px;
line-height: 50px;
letter-spacing: 5px;
word-spacing: 10px;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum adipisci
nulla impedit nemo totam doloribus tempore autem velit sapiente inventore
repudiandae saepe quibusdam soluta consectetur, explicabo placeat
cupiditate ipsam? Aut.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil minima
voluptate obcaecati at porro quaerat architecto dolor! Perspiciatis,
aspernatur. Iure voluptatum tempora assumenda hic et officia vero
laboriosam ipsam beatae!
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptate
quisquam mollitia praesentium ex nostrum deserunt similique vel
reprehenderit alias dolore dolor voluptatem, at tenetur ipsa deleniti
accusantium dignissimos aut perferendis.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsum non
voluptatem consequatur ea. Quia rerum illo rem minima, et dolore
reiciendis facere, labore vel itaque ea neque hic? Quisquam, magni.
</p>
</body>
</html>
Syntax:
<blockquote>
text
</blockquote>
Q: What is difference between blockquote and paragraph?
If material quoted from texts or speeches is longer than 4 lines of
text, the material should be set off in a block, ie, in reduced type
and without the quotation marks. Paragraph indents are generally
not used unless the quoted material is known to begin a
paragraph.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paragraph</title>
<style>
blockquote
{
font-style: italic;
font-size: 30px;
text-align: justify;
</style>
</head>
<body>
<h2 align="center">Times of India</h2>
<blockquote cite="http://www.nareshit.com">
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Exercitationem minima omnis dolor maiores, delectus nisi officia!
Voluptatibus expedita culpa maiores sequi fugit cupiditate perferendis!
Praesentium blanditiis corrupti qui quod fuga.
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quibusdam
ex optio rem odio modi accusantium reprehenderit similique sint aliquid?
Magni veniam ex nam et soluta excepturi in, consectetur suscipit
recusandae.
</blockquote>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel, reiciendis
eveniet accusamus alias architecto magnam quod iste voluptatum
aspernatur, libero voluptas? Dicta, qui impedit? Voluptatibus error alias
laudantium veritatis perspiciatis.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe ipsum
dolorem cumque excepturi perspiciatis quos quaerat dignissimos eum
repellat quibusdam, rem reprehenderit id, nesciunt tenetur beatae, officia
harum repudiandae tempore.
</p>
</body>
</html>
Syntax:
p::first-line{
margin-left
}
Syntax:
p{
text-indent: 100px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paragraph</title>
<style>
p{
font-size: 30px;
text-indent: 100px;
text-align: justify;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel, reiciendis
eveniet accusamus alias architecto magnam quod iste voluptatum
aspernatur, libero voluptas? Dicta, qui impedit? Voluptatibus error alias
laudantium veritatis perspiciatis.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe ipsum
dolorem cumque excepturi perspiciatis quos quaerat dignissimos eum
repellat quibusdam, rem reprehenderit id, nesciunt tenetur beatae, officia
harum repudiandae tempore.
</p>
</body>
</html>
Syntax:
p::first-letter
{
Font-size
Font-weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Paragraph</title>
<style>
p{
font-size: 30px;
text-align: justify;
}
p::first-letter{
font-size: 70px;
font-weight: bold;
float:left;
padding-right: 20px;
}
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel, reiciendis
eveniet accusamus alias architecto magnam quod iste voluptatum
aspernatur, libero voluptas? Dicta, qui impedit? Voluptatibus error alias
laudantium veritatis perspiciatis.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe ipsum
dolorem cumque excepturi perspiciatis quos quaerat dignissimos eum
repellat quibusdam, rem reprehenderit id, nesciunt tenetur beatae, officia
harum repudiandae tempore.
</p>
</body>
</html>
Character entities
</style>
</head>
<body>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel, reiciendis
eveniet accusamus alias architecto magnam quod iste voluptatum
aspernatur, libero voluptas? Dicta, qui impedit? Voluptatibus error alias
laudantium veritatis perspiciatis.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Saepe ipsum
dolorem cumque excepturi perspiciatis quos quaerat dignissimos eum
repellat quibusdam, rem reprehenderit id, nesciunt tenetur beatae, officia
harum repudiandae tempore.
</p>
NareshIT ©
C Langauge ®
</body>
</html>
Q: How to create scrollable paragraph (scroll up and scroll down)?
Q: How to create scrollable paragraph (scroll up and scroll
down)?
Scrollable paragraph or content is create using CSS style attribute
called “overflow”
Syntax:
p{
width:
height:
border:
overflow: auto/scroll/hidden;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scrollable Test</title>
<style>
p{
width:250px;
height:200px;
border: 2px solid black;
overflow: auto;
}
</style>
</head>
<body>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Et error
earum officia sapiente omnis, repellendus sequi doloribus perspiciatis
commodi repudiandae officiis impedit nihil dolorem facilis velit rerum
excepturi perferendis provident?
</p>
</body>
</html>
</dl>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Definition List</title>
<style>
dl{
width:50%;
}
dt{
background-color: black;
color:white;
font-family: Arial, Helvetica, sans-serif;
font-size: 25px;
font-weight: bold;
margin-bottom: 10px;
}
dd {
font-size: 20px;
}
</style>
</head>
<body>
<dl>
<dt>HTML</dt>
<dd>HTML is markup language used for developing pages</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets for styling web pages </dd>
<dt>Javascript</dt>
<dd>It is Scripting Language</dd>
</dl>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Definition List</title>
<style>
dl {
display:grid;
grid-template-columns: 6fr 6fr;
}
dt {
background-color: black;
color:white;
font-size: 20px;
margin-bottom: 10px;
}
dd
{
background-color: thistle;
color:black;
font-size: 20px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<fieldset>
<legend>Personal Information</legend>
<dl>
<dt>FirstName</dt>
<dd>None</dd>
<dt>LastName</dt>
<dd>None</dd>
<dt>Address</dt>
<dd>None</dd>
</dl>
</fieldset>
<fieldset>
<legend>Education Qualification</legend>
<dl>
<dt>UName</dt>
<dd>None</dd>
<dt>UName</dt>
<dd>None</dd>
<dt>UName</dt>
<dd>None</dd>
</dl>
</fieldset>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Definition List</title>
<style>
dt
{
background-color: black;
color:white;
width:25%;
font-size: 25px;
font-weight: bold;
position: sticky;
top: 0px;
}
</style>
</head>
<body>
<header>
<h3>Shopper.</h3>
</header>
<section>
<nav>
<dl>
<dt>Electronics</dt>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dd>Mobiles</dd>
<dd>TV</dd>
<dd>Watches</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
<dt>Mens</dt>
<dd>Cloths</dd>
<dd>Shoes</dd>
</dl>
</nav>
</section>
</body>
</html>
Ordered list
Ordered list contains list of elements or items which automatically
ordered using numbers.
Ordered list definition is given using <ol> element/tag
Ordered list items are defined using <li> element/tag
Syntax:
<ol>
<li>item-1</li>
<li>item-2</li>
<li>item-3</li>
</ol>
Syntax:
<ol type=”1,I,i,a,A”>
….
</ol>
</ol>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Definition List</title>
<style>
</style>
</head>
<body>
<h2>UI Modules</h2>
<ol type="A" start="3">
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>Bootstrap</li>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
<li>Bootstrap</li>
</ol>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
</style>
</head>
<body>
<h2>UI Modules</h2>
<ol>
<li>HTML</li>
<ol type="A">
<li>Introduction to HTML</li>
<ol type="i">
<li> type of softwares</li>
<li> types of web application</li>
</ol>
<li>History of HTML</li>
</ol>
<li>CSS</li>
<li>JavaScript</li>
<li>Bootstrap</li>
</ol>
</body>
</html>
Q: How to remove numbering of ordered list?
In order remove numbering of order list, we use css style called
“liststyle”. The value of liststyle is None.
Syntax:
Ol
{
list-style:None;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
ol
{
list-style: None;
}
li {
margin-bottom: 20px;
}
</style>
</head>
<body>
<nav>
<ol>
<li>Home</li>
<li>About</li>
<li>Products</li>
<li>Contacts</li>
</ol>
</nav>
</body>
</html>
Syntax:
Ol
{
Display:grid;
Grid-template-columns : 6fr 6fr;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
ol {
display:grid;
grid-template-columns: 6fr 6fr;
}
</style>
</head>
<body>
<h3>What is HTML?</h3>
<ol type="A">
<li>HTML is a Language</li>
<li>HTML is a script</li>
<li>HTML is Database</li>
<li>HTML Markup Language</li>
</ol>
<h3>What is CSS</h3>
<ol type="A">
<li>CSS......</li>
<li>CSS ....</li>
<li>CSS ....</li>
<li>CSS ....</li>
</ol>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
ol {
display:grid;
grid-template-columns: 6fr 6fr;
}
</style>
</head>
<body>
<h3>What is HTML?</h3>
<ol type="A">
<div>
<li>HTML is a Language</li>
<li>HTML is a script</li>
</div>
<div>
<li>HTML is Database</li>
<li>HTML Markup Language</li>
</div>
</ol>
<h3>What is CSS</h3>
<ol type="A">
<li>CSS......</li>
<li>CSS ....</li>
<li>CSS ....</li>
<li>CSS ....</li>
</ol>
</body>
</html>
Unordered list
Syntax:
<ul>
<li>item-1</li>
<li>item-2 </li>
<li>item-3</li>
</ul>
Unordered list style can be changed using css or type attribute of
ul element.
Syntax-1 without using CSS:
<ul type=”circle/disc/square”>
<li></li>
<li></li>
</ul>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
li
{
font-size: 30px;
list-style: square;
}
</style>
</head>
<body>
<h3>Introduction to HTML</h3>
<ul >
<li>What is HTML?</li>
<li>History of HTML</li>
<li>HTML Applications</li>
</ul>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
li
{
font-size: 30px;
}
</style>
</head>
<body>
<h3>Introduction to HTML</h3>
<ul >
<li>What is HTML?</li>
<ul>
<li>HTML is markup language</li>
<ul>
<li> Used for webpage creation</li>
<ul>
<li> wepage is collection of tags</li>
</ul>
</ul>
</ul>
<li>History of HTML</li>
<li>HTML Applications</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List</title>
<style>
li
{
font-size: 30px;
}
</style>
</head>
<body>
<h3>Introduction to HTML</h3>
<ol >
<li>What is HTML?</li>
<ul>
<li>HTML is markup language</li>
<ol>
<li> Used for webpage creation</li>
<ul>
<li> wepage is collection of tags</li>
</ul>
</ol>
</ul>
<li>History of HTML</li>
<li>HTML Applications</li>
</ul>
</body>
</html>
<pre>…</pre>
Syntax:
<pre>
content
</pre>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pre element test</title>
</head>
<body>
<pre>
Given an array of integers nums and an integer target, return indices
of the two numbers such that they add up to target.
You may assume that each input would have exactly one solution, and
you may not use the same element twice.
You can return the answer in any order.
<b>Example 1:</b>
Bootstrap icons
We can assign bootstrap icons to each item of list
Syntax:
<ul>
<li class=”bi bi-icons”> item1 </li>
<li class=”bi bi-icons”>item2 </li>
…
</ul>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Custom Unordered List</title>
<style>
ul {
list-style: none;
}
li
{
font-size: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<ul>
<li class="bi bi-lightbulb">Bank OfferGet ₹50 Instant Discount on first
Flipkart UPI transaction on order of ₹200 and aboveT&C</li>
<li class="bi bi-lightbulb">Bank Offer5% Cashback on Flipkart Axis
Bank CardT&C</li>
<li class="bi bi-lightbulb">Bank OfferFlat ₹1000 off on HDFC Bank
Credit Card EMI Txns, Tenure: 6 and 9 months, Min Txn Value:
₹15,000T&C</li>
<li class="bi bi-lightbulb">Special PriceGet extra 29% off (price
inclusive of cashback/coupon)T&C</li>
</ul>
</body>
</html>
CSS style
Custom icon is assigned to list items using CSS.
Syntax:
ul
{
list-style:url(location of icon)
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Custom Unordered List</title>
<style>
ul {
list-style: url(images/bullet1.jpg)
}
li
{
font-size: 30px;
font-weight: bold;
}
</style>
</head>
<body>
<ul>
<li>Bank OfferGet ₹50 Instant Discount on first Flipkart UPI
transaction on order of ₹200 and aboveT&C</li>
<li>Bank Offer5% Cashback on Flipkart Axis Bank CardT&C</li>
<li>Bank OfferFlat ₹1000 off on HDFC Bank Credit Card EMI Txns,
Tenure: 6 and 9 months, Min Txn Value: ₹15,000T&C</li>
<li>Special PriceGet extra 29% off (price inclusive of
cashback/coupon)T&C</li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Custom Unordered List</title>
<style>
ul {
list-style: none;
display:flex;
justify-content: space-around;
}
li {
font-size: 25px;
font-weight: bold;
border: 2px solid black;
width:10%;
margin-bottom: 20px;
text-align: center;
background-color: darkgrey;
}
</style>
</head>
<body>
<ul>
<li>Home</li>
<li>About</li>
<li>Courses</li>
<li>Contact</li>
</ul>
</body>
</html>
Display:flex
Display:inline
Display:grid
Display:inline-block
Display:block
display:flex
display:inline
display:inline property is assigned to individual items/elements.
Formatting text
size is defined,
1 extra small
2 small
3 normal
4 medium
5 large
6 x-large
7 xx-large
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Custom Unordered List</title>
<style>
</style>
</head>
<body>
<font size="6" face="Arial" color="red">Hyper Text Markup
Language</font>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style>
</style>
</head>
<body>
<b>Bold</b> is similer to <strong>Strong</strong><br>
<i>Italic</i> is similer to <em>Emphsis</em> <br>
<u>Underline</u> is similer to <ins>Insert</ins><br>
<strike>Strike</strike> is similer to <del>Delete</del><br>
Log<sub>(10)</sub><br>
(a+b)<sup>2</sup>=a<sup>2</sup>+b<sup>2</sup>+2ab
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.css">
<title></title>
<style>
main{
display: grid;
grid-template-columns: 3fr 9fr;
}
.rating
{
color:white;
background-color: green;
border: 1px solid green;
padding: 5px;
border-radius: 5px;
}
ul{
list-style: none;
color:green;
font-size: 20px;
}
li{
margin-bottom: 10px;
}
li span {
color:black;
margin-left: 15px;
}
</style>
</head>
<body>
<main>
<div>
</div>
<div>
<div>
<font face="Arial" size="5">Motorola G85 5G (Cobalt Blue, 256 GB)
(12 GB RAM)</font>
</div>
<br>
<div>
<span class="rating">4.0 <span class="bi bi-star-
fill"></span></span><font size="5"
color="gray"> 6,688 Ratings & 355
Reviews</font>
</div>
<br>
<div>
<font size="4" color="green">Extra ₹ 3000 off</font>
</div>
<br>
<div>
<font size="6"><b>₹19,999</b></font> <font
size="4" color="gray">₹<strike>22,999</strike></font> <font
size="5" color="green">13% off</font> <span class="bi bi-
info-circle"></span>
</div>
<br>
<div>
<font size="4"><b>Available offers</b></font>
</div>
<div>
<ul>
<li class="bi bi-tag-fill"><span>Special PriceGet extra ₹3000 off
(price inclusive of cashback/coupon)</span></li>
<li class="bi bi-tag-fill"><span>FreebieFlat ₹1000 off on Cleartrip
hotels booking along with 300 supercoins on booking</span></li>
<li class="bi bi-tag-fill"><span>Partner OfferMake a purchase
and enjoy a surprise cashback/ coupon that you can redeem
later</span></li>
</ul>
</div>
</div>
</main>
</body>
</html>
JPEG
High definition images
Less pixel depth compared to PNG
Compressed image
Less Memory
It can be used for displaying with webpage
GIF
Support 256 colors
Less pixel depth
Less Memory
It is good for displaying within webpage
GIF can be animated
TIFF
TIFF is a raster graphics file format which was created to store
scanned photos, although it can be any kind of image.
Working with images
JPEG
High definition images
Less pixel depth compared to PNG
Compressed image
Less Memory
It can be used for displaying with webpage
GIF
Support 256 colors
Less pixel depth
Less Memory
It is good for displaying within webpage
GIF can be animated
TIFF
TIFF is a raster graphics file format which was created to store
scanned photos, although it can be any kind of image.
BMP
Bit map image
This used for uploading images within database or image
data within database
ICO
Icon images are represented with extension .ico
Example : Cursors, fevicon
SVG
Scalable Vector Graphics
Dynamic images, which created using programming
SVG is created using XML (Extensible Markup Language)
<img> tag/element
Basic Attributes
1. src : it refer to source or image name or image file name,
always source is given using virtual path.
2. Alt : alternative. This attribute is used to display text if image
is not displayed.
a. Browser/Client disable images
b. Browser does not support image format
3. Width & Height : define width and height of the image
4. title : title of the image is nothing but tool tip. This is
displayed when cursor moved on the image
5. border : image border can be defined using this attribute
6. align : alignment of image (left/center/right)
7. vspace & hspace: Vertical spaces and Horizontal spaces
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Test</title>
</head>
<body>
<img src="images/kids-banner.avif" alt="Kids Banner" width="300"
height="300" align="left" title="Kids">
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusantium
eaque hic aliquid dolore ipsam? Quisquam, eligendi iusto minus omnis
dolores dicta laborum est accusantium nostrum? Architecto sequi beatae
neque soluta.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Excepturi
quibusdam, aliquid exercitationem vero voluptatum fuga vel neque placeat
commodi ex ipsam omnis blanditiis deleniti harum ipsum nobis cum,
delectus similique!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Laudantium,
reprehenderit. Odio molestias, magni delectus voluptatibus non nesciunt
vero qui dolorum adipisci illum, dolorem a consectetur, consequuntur
quisquam? Corporis, nobis eaque!
</p>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.css">
<title></title>
<style>
main{
display: grid;
grid-template-columns: 3fr 9fr;
}
.rating
{
color:white;
background-color: green;
border: 1px solid green;
padding: 5px;
border-radius: 5px;
}
ul{
list-style: none;
color:green;
font-size: 20px;
}
li{
margin-bottom: 10px;
}
li span {
color:black;
margin-left: 15px;
}
</style>
</head>
<body>
<main>
<div>
<img src="images/moto.jpg" height="400" width="400px">
</div>
<div>
<div>
<font face="Arial" size="5">Motorola G85 5G (Cobalt Blue, 256 GB)
(12 GB RAM)</font>
</div>
<br>
<div>
<span class="rating">4.0 <span class="bi bi-star-
fill"></span></span><font size="5"
color="gray"> 6,688 Ratings & 355
Reviews</font>
</div>
<br>
<div>
<font size="4" color="green">Extra ₹ 3000 off</font>
</div>
<br>
<div>
<font size="6"><b>₹19,999</b></font> <font
size="4" color="gray">₹<strike>22,999</strike></font> <font
size="5" color="green">13% off</font> <span class="bi bi-
info-circle"></span>
</div>
<br>
<div>
<font size="4"><b>Available offers</b></font>
</div>
<div>
<ul>
<li class="bi bi-tag-fill"><span>Special PriceGet extra ₹3000 off
(price inclusive of cashback/coupon)</span></li>
<li class="bi bi-tag-fill"><span>FreebieFlat ₹1000 off on Cleartrip
hotels booking along with 300 supercoins on booking</span></li>
<li class="bi bi-tag-fill"><span>Partner OfferMake a purchase
and enjoy a surprise cashback/ coupon that you can redeem
later</span></li>
</ul>
</div>
</div>
</main>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.css">
<title>INOX</title>
<style>
main{
display:grid;
grid-template-columns: 2.4fr 2.4fr 2.4fr 2.4fr 2.4fr;
}
.card {
margin-left: 10px;
margin-top: 30px;
border: 1px solid black;
width:205px
}
.card-header
{
height:300px;
}
.img-cls
{
height:100%;
}
.title-1
{
font-size: 12px;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
margin-top: 5px;
}
.title-2{
color:gray
}
.title-3{
color:gray;
}
.bi-square-fill
{
font-size: 5px;
}
.book-btn{
border: 1px solid blue;
background-color: blue;
color:white;
padding:10px;
border-radius: 5px;
text-align: center;
font-family: Arial;
width:100px;
display:inline-block;
margin-right: 20px;
}
.card-footer
{
margin-top: 5px;
}
</style>
</head>
<body>
<main>
<div class="card">
<div class="card-header">
<img src="images/a1.jpg" class="img-cls">
</div>
<div class="card-body">
<div class="title-1">STREE 2 SARKATE KA AATANK</div>
<div class="title-2">U/A <span class="bi-square-fill"></span>
Horror</div>
<div class="title-3">Hindi</div>
</div>
<div class="card-footer">
<div>
<span class="book-btn">BookTickets</span>
<span class="bi bi-info-circle"></span>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/a2.webp" class="img-cls">
</div>
<div class="card-body">
<div class="title-1">STREE 2 SARKATE KA AATANK</div>
<div class="title-2">U/A <span class="bi-square-fill"></span>
Horror</div>
<div class="title-3">Hindi</div>
</div>
<div class="card-footer">
<div>
<span class="book-btn">BookTickets</span>
<span class="bi bi-info-circle"></span>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/a3.jpg" class="img-cls">
</div>
<div class="card-body">
<div class="title-1">STREE 2 SARKATE KA AATANK</div>
<div class="title-2">U/A <span class="bi-square-fill"></span>
Horror</div>
<div class="title-3">Hindi</div>
</div>
<div class="card-footer">
<div>
<span class="book-btn">BookTickets</span>
<span class="bi bi-info-circle"></span>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/a4.avif" class="img-cls">
</div>
<div class="card-body">
<div class="title-1">STREE 2 SARKATE KA AATANK</div>
<div class="title-2">U/A <span class="bi-square-fill"></span>
Horror</div>
<div class="title-3">Hindi</div>
</div>
<div class="card-footer">
<div>
<span class="book-btn">BookTickets</span>
<span class="bi bi-info-circle"></span>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<img src="images/a5.avif" class="img-cls">
</div>
<div class="card-body">
<div class="title-1">STREE 2 SARKATE KA AATANK</div>
<div class="title-2">U/A <span class="bi-square-fill"></span>
Horror</div>
<div class="title-3">Hindi</div>
</div>
<div class="card-footer">
<div>
<span class="book-btn">BookTickets</span>
<span class="bi bi-info-circle"></span>
</div>
</div>
</div>
</main>
</body>
</html>
Hyperlinks
This hyper link is created using <a> tag or element “a” anchor
tag.
Syntax:
<a href=”location/path”>text</a>
Example:
<h2 id="amazon">Amazon</h2>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Consectetur
soluta molestiae fuga dolorem asperiores accusamus esse, error minus
officia quam sequi non libero aliquam odio laborum porro. Quisquam, nam
repellat?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum
magnam molestiae, at dolorem voluptates nobis hic fugit dolor obcaecati
necessitatibus doloremque expedita sit voluptatem excepturi optio animi
quibusdam facilis modi!
</p>
<footer>
<a href="#amazon" >Back to Top</a>
</footer>
Syntax
a{
text-decoration:none;
}
Using HTML
<body alink=”color” vlink=”color”>
Using CSS
Syntax: a:visited Color
Syntax: a:active Color
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Document Link</title>
<style>
a{
text-decoration: none;
color:green;
}
a:visited {
color:aqua;
}
a:active {
color:yellow;
}
</style>
</head>
<body>
<h2 id="amazon">Amazon</h2>
<p id="p1">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Consectetur
soluta molestiae fuga dolorem asperiores accusamus esse, error minus
officia quam sequi non libero aliquam odio laborum porro. Quisquam, nam
repellat?
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Earum
magnam molestiae, at dolorem voluptates nobis hic fugit dolor obcaecati
necessitatibus doloremque expedita sit voluptatem excepturi optio animi
quibusdam facilis modi!
</p>
<footer>
<a href="#amazon" >Back to Top</a>
<a href="#p1" >Back to Top</a>
</footer>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intra Document Link</title>
<style>
ul {
list-style: none;
}
li {
margin-top: 50px;
border: 1px solid black;
font-size: 30px;
font-weight: bold;
background-color: black;
color: white;
padding:10px;
}
section
{
display: grid;
grid-template-columns: 2fr 8fr;
column-gap: 50px;
}
p
{
font-size: 24px;
}
img
{
width:300px;
height: 300px;
}
a{
text-decoration: none;
color:white;
}
a:active{
color: white;
}
a:visited{
color:white;
}
.brand-title
{
background-color: black;
color:white;
padding: 20px;
}
div p a{
color:blue;
}
div p a:active
{
color:brown;
}
div p a:visited {
color:aqua;
}
</style>
</head>
<body>
<header>
<div class="brand-title">
<h1>Shopper.</h1>
</div>
</header>
<section>
<nav>
<ul>
<li> <a href="#home">Home</a></li>
<li><a href="#mens">Mens</a></li>
<li><a href="#women">Women's</a></li>
<li><a href="#kids">Kid's</a></li>
</ul>
</nav>
<div>
<h2 id="home">Home</h2>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta
veniam mollitia velit vero libero amet corporis aut accusamus dicta
doloribus sapiente quos totam iste, dolorum eius placeat animi pariatur
accusantium!
Lorem ipsum dolor sit amet, consectetur <a href="#kids">Kids
Offer</a>adipisicing elit. Ipsam laboriosam modi architecto. Quidem iure
voluptates vero tempora maiores, aut consequuntur voluptatum rem sunt,
deleniti reiciendis esse ipsum corrupti expedita dolorum.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla eos
quis nesciunt quibusdam, ratione, quam enim eveniet magnam maxime
unde laboriosam laudantium nobis tempora adipisci fugiat id exercitationem
commodi eum!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sit fugiat
ex nemo totam quis vitae, molestiae autem incidunt eos nesciunt at repellat
quaerat voluptatum mollitia dicta tenetur iste laudantium illo.
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Similique
fuga quibusdam cumque quos blanditiis itaque omnis dolor ea, perspiciatis
officiis neque, assumenda molestiae harum, quae distinctio eligendi
reprehenderit iure velit!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni
beatae facilis consequatur doloribus sint iste assumenda labore debitis
voluptas cupiditate accusamus illum enim, accusantium at sed aperiam
dolore officiis deserunt.
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ratione
eius asperiores eaque expedita repellendus architecto neque voluptatem
praesentium animi et cumque cum recusandae, corporis dolorem in iste
omnis molestiae doloremque?
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Similique
fuga quibusdam cumque quos blanditiis itaque omnis dolor ea, perspiciatis
officiis neque, assumenda molestiae harum, quae distinctio eligendi
reprehenderit iure velit!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Magni
beatae facilis consequatur doloribus sint iste assumenda labore debitis
voluptas cupiditate accusamus illum enim, accusantium at sed aperiam
dolore officiis deserunt.
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Ratione
eius asperiores eaque expedita repellendus architecto neque voluptatem
praesentium animi et cumque cum recusandae, corporis dolorem in iste
omnis molestiae doloremque?
</p>
<h2 id="mens">Mens</h2>
<img src="images/men-banner.avif">
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Facere
iusto, unde nostrum minima dicta adipisci, facilis impedit, assumenda
exercitationem quas illo ullam voluptates delectus et quaerat veniam sequi
nihil deserunt.
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Libero
dolorem eum ut obcaecati, id soluta quod dolorum voluptates aut deserunt,
ipsam, rem numquam sequi repudiandae quidem assumenda reiciendis
sunt nisi!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Velit alias
magnam ad eveniet. Reprehenderit tempora iusto similique quis. Deserunt
illum tempora nam reprehenderit quia fuga iste amet praesentium, quidem
aliquam.
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Laborum
temporibus dolorem natus dolore tempore, nesciunt fugiat illum
reprehenderit voluptates non? Quasi consequuntur voluptates doloribus ad
reiciendis omnis exercitationem quidem dicta.
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Ex non
voluptatibus error iste voluptate enim similique fugiat quod sint reiciendis
assumenda eum, voluptatum nemo itaque, rerum, architecto quas. Fuga,
rem!
</p>
<h2 id="women">Women's</h2>
<img src="images/women-banner.avif">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Culpa iste
enim repellat consequuntur, dolorum cupiditate natus minus itaque harum,
inventore officiis amet voluptate corrupti, a quia tempore? Corporis,
veritatis inventore.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti
molestiae quidem explicabo alias, dolore debitis omnis sunt iure? Inventore
labore earum ea repellat vitae ex consequuntur ab odit quisquam
repellendus?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Facere
dolorum est dolore sequi dicta quam eius odio. Ad, exercitationem. Quos
sed doloribus quidem qui perferendis necessitatibus natus neque, placeat
dolores!
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Laboriosam
accusamus, earum doloribus rem impedit, mollitia fugiat ipsam eligendi
repellat aliquam et velit corporis doloremque ut saepe aliquid distinctio est
quas!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sequi
consequuntur ut sint unde? Iure magnam eveniet error, culpa odit laborum
officiis perspiciatis, placeat doloribus doloremque tempora cupiditate
inventore accusamus fuga.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Eligendi
totam expedita adipisci ea rerum cum fuga corporis iure, consequuntur
voluptatem possimus, magnam quasi consectetur quo exercitationem
excepturi tempora provident ut?
</p>
<h2 id="kids">Kids</h2>
<img src="images/kids-banner.avif">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ex ipsa
eligendi nesciunt. Mollitia itaque nostrum atque, saepe sunt beatae
praesentium quibusdam sit magni aliquid explicabo quidem illum
voluptatibus laudantium recusandae?
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Tenetur
recusandae sunt ad voluptatibus. Nihil, omnis. Fuga a illum odio, atque
odit, laboriosam cumque quas corporis quisquam molestias magnam
facere voluptas!Lore
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Accusamus
nam neque facere adipisci architecto voluptatibus omnis. Odio velit esse
qui nisi! Itaque quia fugit eaque vel minus sapiente error quae!
Lorem, ipsum dolor sit amet consectetur adipisicing elit.
Repellendus quis vitae aperiam eos similique eligendi, ratione, officia non
dolorem omnis, repudiandae inventore. Reiciendis distinctio quidem rerum
placeat dolorem, provident explicabo.
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Provident
neque iure odit. Tempore error necessitatibus, ipsum explicabo, enim, illo
dolor aspernatur nostrum repellat itaque eius nulla? Dolor sed deserunt
maxime?
</p>
</div>
</section>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
main {
display:grid;
grid-template-columns: 4fr 4fr 4fr;
column-gap: 20px;
}
div
{
border: 1px solid black;
padding: 10px;
font-family: Arial, Helvetica, sans-serif;
font-size: 25px;
width:300px
}
nav {
margin: 50px;
font-size: 25px;
}
a{
margin-right: 20px;
text-decoration: none;
}
div:target
{
border: 1px solid black;
padding: 10px;
font-family: Arial, Helvetica, sans-serif;
font-size: 25px;
width:300px;
background-color: black;
color:white;
}
</style>
</head>
<body>
<nav>
<a href="#html">HTML</a>
<a href="#css">CSS</a>
<a href="#js">JavaScript</a>
</nav>
<main>
<div id="html" >
<h2>HTML</h2>
<ul>
<li>Lesson1</li>
<li>Lesson2</li>
<li>Lesson3</li>
<li>Lesson4</li>
<li>Lession5</li>
</ul>
</div>
<div id="css" >
<h2>CSS</h2>
<ul>
<li>Lesson1</li>
<li>Lesson2</li>
<li>Lesson3</li>
<li>Lesson4</li>
<li>Lession5</li>
</ul>
</div>
<div id="js" >
<h2>JavaScript</h2>
<ul>
<li>Lesson1</li>
<li>Lesson2</li>
<li>Lesson3</li>
<li>Lesson4</li>
<li>Lession5</li>
</ul>
</div>
</main>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
nav {
margin-bottom: 50px;
margin-top: 50px;
margin-left: 200px;
font-size: 25px;
}
a
{
margin-right: 50px;
}
img
{
width:300px;
height: 300px;
}
img:target {
border: 4px solid black;
border-radius: 5px;
width:200px ;
height:200px;
}
</style>
</head>
<body>
<nav>
<a href="#mens"> Mens</a>
<a href="#womens"> Womens</a>
<a href="#kids"> Kids</a>
</nav>
<main>
<img src="images/men-banner.avif" id="mens">
<img src="images/women-banner.avif" id="womens">
<img src="images/kids-banner.avif" id="kids">
</main>
</body>
</html>
Interlink Document
Interlink document allows to link a document or file exists outside
current document.
File
Interlink document allows to link to file. These files can images,
documents, pdf or any type of file supported by browser.
To open these files, browser required some plugins.
Syntax:
<a href=”file location”>
Example:
<!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>
<a href="images/a1.jpg">Image</a> <br>
<a href="images/kids-banner.avif">kids</a><br>
<a href="docs/python.pdf">Python</a><br>
<a href="docs/26-8-2024.docx">WordDoc</a>
</body>
</html>
<a> is having an attribute called download, this allows every file
to download
<!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>
<a href="images/a1.jpg" download>Image</a> <br>
<a href="images/kids-banner.avif">kids</a><br>
<a href="docs/python.pdf" download>Python</a><br>
<a href="docs/26-8-2024.docx">WordDoc</a>
</body>
</html>
Inter document link allows to link one webpage with another
webpage.
Syntax:
<a href=”.html”>text</a>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
a{
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
text-decoration: none;
border: 1px solid black;
background-color: black;
color:white;
margin-right: 50px;
}
</style>
</head>
<body>
<header>
<a href="about.html">About</a>
<a href="courses.html">Courses</a>
<a href="contact.html">Contact</a>
</header>
<section>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore
libero nisi ipsam enim vel explicabo, recusandae accusamus. Tempora
libero suscipit eaque blanditiis ut possimus neque, eius repellendus, sint
praesentium minus?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Possimus
debitis nam in hic nesciunt laudantium laboriosam minus architecto
recusandae repellendus incidunt neque tempora error, aspernatur, facilis
sequi asperiores sunt libero.
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
Consequatur, recusandae ut iure sit, quam illo nam velit facere eaque,
iusto a natus! Ea sapiente illo enim corporis nemo ipsum neque.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Id quasi
laboriosam officia hic quod, dolores eos quia dicta molestiae praesentium
autem libero consequatur animi excepturi obcaecati voluptatibus ex ipsam
debitis?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis
dolor rem modi odit eveniet reprehenderit temporibus laudantium eum
fugiat dolorem quod deleniti quibusdam, vitae facilis delectus error. Quia,
corporis itaque.
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nostrum
dignissimos debitis, praesentium officiis corporis pariatur et delectus,
asperiores facilis aliquam suscipit quisquam dolorem ipsa quam
consectetur mollitia iure. Dolorum, iure?
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Rerum
facere, nemo modi animi ratione nihil, vel quasi perspiciatis id consectetur
nobis dolore iusto, dolores eaque. Vel at autem sequi reprehenderit.
</p>
</section>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
</head>
<body>
<h2> Interview Preparation Sites</h2>
<main>
<a href="https://www.hackerrank.com/">HackerRank</a>
<a href="https://leetcode.com/">Leetcode</a>
<a href="https://www.hackerearth.com/">HackerEarth</a>
<a href="https://www.geeksforgeeks.org/">GeeksForGeeks</a>
</main>
</body>
</html>
Application
This hyperlink can be,
1. Email link
2. Telephone link
3. Skype Link
Email Link
Mail link required mailing application installed in your system.
Example: Microsoft Outlook
Syntax:
<a href=”mailto:email-address>text</a>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
</head>
<body>
Mail Us: <a
href="mailto:[email protected]">[email protected]</a>
</body>
</html>
Telephone link
This link required application where it can open telephone number
make call (Dial pad)
Syntax:
<a href=”tel:+number”>text</a>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
</head>
<body>
Contact <a href="tel:+915566799887">+915566799887</a>
</body>
</html>
Syntax:
<a href=”path” target=”_blank”>text</a>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
</head>
<body>
<a href="images/moto.jpg" target="_blank">Moto</a>
</body>
</html>
Syntax:
<a href=”javascript:function”>Text</a>
Example:
<a
href=”javascript:window.open(“path”,title,width,height)”>text</a
>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
</head>
<body>
<a
href="javascript:window.open('images/moto.jpg','image',width=300,height=
300)">Moto</a>
</body>
</html>
Syntax:
<iframe name=”name of frame”>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Demo</title>
<style>
a{
font-size: 20px;
font-family: Arial;
}
section
{
display:grid;
grid-template-columns: 2fr 10fr;
}
iframe
{
width:100%;
height: 100vh;
border: none;
}
</style>
</head>
<body>
<section>
<div>
<a href="images/moto.jpg" target="frame1">Moto</a><br>
<a href="docs/python.pdf" target="frame1">PDF</a><br>
<a href="about.html" target="frame1">About</a>
</div>
<div>
<iframe name="frame1"></iframe>
</div>
</section>
</body>
</html>
IN HTML 4.0 frameset
Syntax:
<frameset>
<frame src=”path”></frame>
<frame src=”path”></frame>
</frameset>
Attributes of frameset
Rows : defines number of rows
Cols : defines number of cols
Attributes of frame
src: path/context which has to be displayed within frame
Example:
<!DOCTYPE html>
<html>
<head>
<title>frameset</title>
</head>
<frameset cols="50%,50%">
<frame src="index.html"></frame>
<frame src="courses.html"></frame>
</frameset>
</html>
HTML Tables
Tables represent data.
Table is grid, which consist of number of rows and columns.
This table is represented using <table> tag/element.
Attributes
1. frame,rules,groups
Syntax:
<table frame=“box|lhs|rhs|above|below|none”>
rules : the rules are given as rows or cols
The value of rules can be
Syntax:
<table rules=”rows|cols|all |groups|none”>
Syntax:
<table>
<colgroup span=”n columns”>
</table>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IPL</title>
</head>
<body>
<table width="100%" frame="box" rules="groups">
<caption>Test Ranking</caption>
<colgroup span="2"></colgroup>
<thead>
<tr>
<th>Pos</th>
<th>Team</th>
<th>Players</th>
<th>Rating</th>
<th>Career Best Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>01</td>
<td><img src="images/ind.JPG" >IND</td>
<td>Rohit Sharma</td>
<td>1000</td>
<td>923 v India at Edgbaston 2022</td>
</tr>
<tr>
<td>02</td>
<td><img src="images/eng.JPG" >ENG</td>
<td>Joe Root</td>
<td>872</td>
<td>923 v India at Edgbaston 2022</td>
</tr>
<tr>
<td>03</td>
<td><img src="images/nz.JPG" >NZ</td>
<td> Kane Williamson</td>
<td>859</td>
<td>919 v Pakistan at Christchurch 2021</td>
</tr>
<tr>
<td>04</td>
<td><img src="images/pak.JPG" >PAK</td>
<td> Babar Azam</td>
<td>768</td>
<td>882 v New Zealand at Karachi 2022</td>
</tr>
</tbody>
<tfoot>
<tr><th>ICC Test Ranking</th></tr>
</tfoot>
</table>
</body>
</html>
Attributes of table
Syntax:
<table width=”80%” border=”1” cellspacing=”20”
cellpadding=”20”>
align,valign,width,height
Syntax:
Syntax:
<table width="100%" border="1" >
<caption>Test Ranking</caption>
<thead>
<tr height="80">
<th width="100" align="left" valign="top">Pos</th>
<th width="300" align="right">Team</th>
<th width="100">Players</th>
<th width="80">Rating</th>
<th width="400">Career Best Rating</th>
</tr>
</thead>
background,bgcolor
Syntax:
<table bgcolor=”color”>
<tr bgcolor=”color”>
<td bgcolor=”color”>text</td>
</tr>
</table>
Syntax:
rowspan,colspan
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IPL</title>
</head>
<body>
<table width="100%" border="1">
<caption>Test Ranking</caption>
<thead>
<tr height="80">
</tr>
</thead>
<tbody>
<tr height="100">
<td >01</td>
<td><img src="images/ind.JPG" >IND</td>
<td >Rohit Sharma</td>
<td>1000</td>
<td>923 v India at Edgbaston 2022</td>
</tr>
<tr >
<td>02</td>
<td><img src="images/eng.JPG" >ENG</td>
<td>Joe Root</td>
<td>872</td>
<td>923 v India at Edgbaston 2022</td>
</tr>
<tr >
<td>03</td>
<td><img src="images/nz.JPG" >NZ</td>
<td> Kane Williamson</td>
<td>859</td>
<td>919 v Pakistan at Christchurch 2021</td>
</tr>
<tr >
<td>04</td>
<td><img src="images/pak.JPG" >PAK</td>
<td> Babar Azam</td>
<td>768</td>
<td>882 v New Zealand at Karachi 2022</td>
</tr>
</tbody>
<tfoot>
<tr ><th colspan="5" align="right">ICC Test Ranking</th></tr>
</tfoot>
</table>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table
{
font-size: 30px;
font-weight: bold;
}
</style>
</head>
<body>
<table border="1" width="100%">
<caption>Marks Sheet</caption>
<tr>
<td>Rollno</td>
<td colspan="3">101</td>
</tr>
<tr>
<td>Name</td>
<td colspan="3">Naresh</td>
</tr>
<tr>
<td>Subject1</td>
<td>Subject2</td>
<td colspan="2">Subject3</td>
</tr>
<tr>
<td>99</td>
<td>99</td>
<td colspan="2">99</td>
</tr>
<tr>
<td>Total</td>
<td>297</td>
<td>Result</td>
<td>Pass</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courses Details</title>
<style>
table
{
font-size: 30px;
font-family: Arial;
}
</style>
</head>
<body>
<table border="5" width="80%">
<tr>
<th colspan="2">Language and FrameWorks</th>
</tr>
<tr>
<td>Python</td>
<td>Django</td>
</tr>
<tr>
<td rowspan="2">JavaScript</td>
<td>React.Js</td>
</tr>
<tr>
<td>Vue.Js</td>
</tr>
<tr>
<td>Ruby</td>
<td>Ruby on Rails</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courses Details</title>
<style>
table
{
font-size: 30px;
font-family: Arial;
}
</style>
</head>
<body>
<table border="5" width="100%" cellpadding="10">
<tr>
<th rowspan="3">Day</th>
<th colspan="3">Seminar</th>
</tr>
<tr>
<th colspan="2">Schedule</th>
<th rowspan="2">Topic</th>
</tr>
<tr>
<th>Begin</th>
<th>End</th>
</tr>
<tr>
<td rowspan="2">Monday</td>
<td rowspan="2">8:00 am</td>
<td rowspan="2">5:00 pm</td>
<td>Introduction to XML</td>
</tr>
<tr>
<td>Validity:DTD and RelaxNG</td>
</tr>
<tr>
<td rowspan="3">TuesDay</td>
<td>8:00am</td>
<td>11:00am</td>
<td rowspan="2">XPath</td>
</tr>
<tr>
<td>11:00am</td>
<td>2:00pm</td>
</tr>
<tr>
<td>2:00pm</td>
<td>5:00pm</td>
<td>XSL Tansformations</td>
</tr>
<tr>
<td>WednesDay</td>
<td>8:00am</td>
<td>12:00pm</td>
<td>XSL Formatting Objects</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Courses Details</title>
<style>
table
{
font-size: 30px;
font-family: Arial;
}
</style>
</head>
<body>
<table border="2" width="80%">
<tr>
<th colspan="6">Time Table</th>
</tr>
<tr>
<th rowspan="6">Hours</th>
<th>Mon</th>
<th>Tue</th>
<th>Web</th>
<th>Thu</th>
<th>Fri</th>
</tr>
<tr>
<td>Maths</td>
<td>Science</td>
<td>Maths</td>
<td>Science</td>
<td>Arts</td>
</tr>
<tr>
<td>Maths</td>
<td>Science</td>
<td>Maths</td>
<td>Science</td>
<td>Arts</td>
</tr>
<tr>
<td colspan="5" align="center">Lunch</td>
</tr>
<tr>
<td>Maths</td>
<td>Science</td>
<td>Maths</td>
<td rowspan="2" colspan="2">Project</td>
</tr>
<tr>
<td>Maths</td>
<td>Science</td>
<td>Maths</td>
</tr>
</table>
</body>
</html>
What is form?
A form is container, where end user or client input data and
submit this data to backend or another program.
Syntax:
<form action=”URL” method=”Request Method”>
</form>
action
Action is event which is executed when end user click on submit
button.
When end user click on submit button form data is submitted to
resource given in action.
Method
action
Action is event which is executed when end user click on submit
button.
When end user click on submit button form data is submitted to
resource given in action.
method
What is request?
Input given by end user to the server is called request.
What is response?
The output given by server to the client is called response
GET:
GET is request to read information from server but not writing
information to server.
Example:
1. Type URL in browser and press enter
2. Query data or information
POST
In request method POST, the data is send as part request body
(OR) send as stream. It is not visible on Address/URL bar.
POST is request writing information to server.
Example:
Inserting data/registration
In post request,
1. Any type of data can be send
2. There is no restriction on sending of data
3. There is no chance of URL injection
target
[email protected]
Form Elements or tags
Label
Label is used for creating caption for input element
Label is used to identify input element (OR) data.
Syntax:
<label for=”name”>text</label>
Input
1. Submit button
Syntax:
<input type=”submit” value=”text”>
Value is used to change display text, the default display text form
input type submit is submit.
2. Reset button
Syntax:
<input type=”reset” value=”text”>
3. Button
Syntax:
<input type=”button” value=”text” onclick=function>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
fieldset
{
font-size: 20px;
font-weight: bold;
padding:50px;
}
label {
border: 1px solid black;
color:blue;
}
.s {
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
padding: 20px;
background-color: aqua;
color:red;
border-color: blueviolet;
border-radius: 15px;
width: 150px;
}
</style>
</head>
<body>
<form action="index.html">
<fieldset>
<legend>User Information</legend>
<label for="uname">UserName</label>
<input type="text" name="uname" id="uname"><br><br>
<label for="name">Name</label>
<input type="text" name="name" id="name"><br><br>
<input type="submit" value="Login" class="s">
<input type="reset" value="clear" class="s">
<input type="button" value="validate" class="s">
</fieldset>
</form>
</body>
</html>
<input type=”password”>
This input type used to input password values. The content input
inside password field is not visible.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Login Form</title>
<style>
</style>
</head>
<body>
<form>
<table border="1" width="80%">
<caption>Login</caption>
<tr>
<td><label for="uname">UserName</label></td>
<td><input type="text" name="uname" id="uname"
required></td>
</tr>
<tr>
<td><label for="pwd">Password</label></td>
<td><input type="password" name="pwd" id="pwd"
required></td>
</tr>
<tr>
<td><input type="submit"></td>
<td><input type="reset"></td>
</tr>
</table>
</form>
</body>
</html>
Attribute
required : if this attribute is assigned to any input field, input is
required before submitting form.
<input type=number>
Syntax:
<input type=”number” name=”field-name”>
Attributes
1. Min : This define minimum value
2. Max : This define maximum value
3. Value: This define default value
4. Placeholder : text displayed within input field
<input type=hidden>
This is for creating hidden field, this field is not visible to end user.
End user cannot input value inside hidden field.
<input type=”email”>
<input> elements of type email are used to let the user enter and
edit an email address
Syntax:
<input type=”email” [email protected] placeholder=”Mail
Address” multiple=”true/false”>
<input type=”tel”>
<input> elements of type tel are used to let the user enter and
edit a telephone number.
Syntax:
<input type=”tel”>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<script>
</script>
<style>
</style>
</head>
<body>
<form>
<label for="age">Age</label>
<input type="number" name="personage" id="age" min="1"
max="200" value="10" ><br><br>
<label for="name">Name</label>
<input type="text" name="pname" id="name"
placeholder="Person Name"><br>
<input type="hidden" name="uname" value="nit"><br>
<label for="email">Email</label>
<input type="email" name="email" id="email" multiple="true"
placeholder="Email Address"><br>
<label for="phno">Telephone No</label>
<input type="tel" name="phno" id="phno" pattern="[0-9]{10}">
<input type="submit">
</form>
</body>
</html>
What is CSS?
Types of CSS
.
Inline CSS: Inline CSS are directly applied on the HTML
elements.
HTML element is having an attribute called style.
Syntax:
<p style="font-size: 60px; font-family: 'Times New Roman', Times,
serif;">Hello</p>
Syntax:
<head>
<style>
selector
{
css-property:value;
css-property:value;
}
selector
{
Css-property:value;
Css-property:value;
}
</style>
</head>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Inline CSS</title>
<style>
p{
font-size: 40px;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet
MS', sans-serif;
color: blue;
}
</style>
</head>
<body>
<p >Hello</p>
<p>Hyper Text Markup Language</p>
<p>Cacading Style Sheets</p>
<p>Bootstrap</p>
<p>JavaScript</p>
</body>
</html>
Syntax:
<link rel=”stylesheet” href=”path”>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Inline CSS</title>
<link rel="stylesheet" href="css/style1.css">
</head>
<body>
<p >Hello</p>
<p>Hyper Text Markup Language</p>
<p>Cacading Style Sheets</p>
<p>Bootstrap</p>
<p>JavaScript</p>
</body>
</html>
CSS Syntax
Following is the syntax of styling using CSS.
selector {
property: value;
}
CSS Selectors are used to select the HTML elements you want
to style on a web page. They allow you to target specific
elements or groups of elements to apply styles like colors,
fonts, margins, and more.
Types of Selectors
1. Universal Selectors
2. Element Selectors
3. Class Selectors
4. Id Selectors
5. Attribute Selectors
6. Group Selectors
7. Pseudo-element Selectors
8. Pseudo-class Selectors
9. Descendant Selectors
10. Child Selectors
11. Adjacent Sibling Selectors
12. General Sibling Selectors
Syntax
*{
margin: 0;
padding: 0;
}
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
*{
font-size: 40px;
color:blue;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<h1>UI Technologies</h1>
<h2>HTML</h2>
<h2>CSS</h2>
<h2>JavaScript</h2>
<h2>Bootstrap</h2>
<p>UI stands for User Interface</p>
<div>
<span>UI</span>
</div>
<table border="1">
<tr>
<th>Rollno</th>
<th>Name</th>
</tr>
</table>
</body>
</html>
Syntax
/* Sets text color of all p tags to green */
p{
color: green;
}
/* Add underline to all h1 tags in document */
h1 {
text-decoration-line: underline;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
h1 {
color:blue;
}
h2 {
color:red;
}
p
{
color:blueviolet;
}
span {
font-weight: bold;
}
th {
font-size: 40px;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<h1>UI Technologies</h1>
<h2>HTML</h2>
<h2>CSS</h2>
<h2>JavaScript</h2>
<h2>Bootstrap</h2>
<p>UI stands for User Interface</p>
<div>
<span>UI</span>
</div>
<table border="1">
<tr>
<th>Rollno</th>
<th>Name</th>
</tr>
</table>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.header1 {
font-size: 40px;
text-decoration-line: underline;
}
.header2 {
font-size: 30px;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<h1 class="header1">UI Technologies</h1>
<h2 class="header2">HTML</h2>
<h2>CSS</h2>
<h2>JavaScript</h2>
<h2 class="header2">Bootstrap</h2>
<p>UI stands for User Interface</p>
<div>
<span>UI</span>
</div>
<table border="1">
<tr>
<th>Rollno</th>
<th>Name</th>
</tr>
</table>
</body>
</html>
CSS ID Selector
An ID selector targets single element with a particular value
for id attribute to style it. An id in CSS is denoted by "#"
(hash) symbol. Same class can be applied to multiple elements,
but an id is unique for an element.
Syntax:
#style-p {
color: green;
font-size: 25px;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
#id1 {
font-size: 30px;
color:blue;
}
</style>
</head>
<body>
<h1 >UI Technologies</h1>
<h2 id="id1" >HTML</h2>
<h2>CSS</h2>
<h2>JavaScript</h2>
<h2 >Bootstrap</h2>
<p>UI stands for User Interface</p>
<div>
<span>UI</span>
</div>
<table border="1">
<tr>
<th>Rollno</th>
<th>Name</th>
</tr>
</table>
</body>
</html>
CSS Attribute Selector
An attribute selector targets an element based on a specific
attribute or attribute values on an element.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
label {
font-size: 30px;
margin-right: 50px;
}
input[type]{
font-size: 30px;
font-family: Arial, Helvetica, sans-serif;
color:blue;
border: 2px solid red;
}
</style>
</head>
<body>
<form>
<label for="name">Name</label>
<input type="text" id="name"><br>
<label for="uname" >UserName</label>
<input type="text" id="uname"><br>
<label for="pwd">Password</label>
<input type="password" id="pwd"><br>
</form>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
label {
font-size: 30px;
margin-right: 50px;
}
input[type=text]{
font-size: 30px;
font-family: Arial, Helvetica, sans-serif;
color:blue;
border: 2px solid red;
}
input[type=password]{
font-size: 30px;
font-family: Arial, Helvetica, sans-serif;
color:red;
border: 2px solid black;
}
</style>
</head>
<body>
<form>
<label for="name">Name</label>
<input type="text" id="name"><br>
<label for="uname" >UserName</label>
<input type="text" id="uname"><br>
<label for="pwd">Password</label>
<input type="password" id="pwd"><br>
</form>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
a[href^=https]
{
text-decoration: none;
font-size: 40px;
color:black;
}
</style>
</head>
<body>
<a href="http://www.nareshit.com">Nareshit</a><br>
<a href="https://www.hdfc.com">HDFC</a><br>
</form>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
img[src$=avif] {
width: 100px;
height: 100px;
}
</style>
</head>
<body>
<img src="images/eng.JPG">
<img src="images/ind.JPG">
<img src="images/kids-banner.avif">
<img src="images/banner.avif">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.class1 {
width:300px;
height: 300px;
border: 1px solid black;
}
div[class~="head"]
{
background-color: aqua;
color:blue;
}
</style>
</head>
<body>
<div class="class1">
<div class="head one">FrontEnd</div>
<div>HTML</div>
<div>CSS</div>
<div>JavaScript</div>
<div>Bootstrap</div>
<div>AngularJs</div>
</div>
<div class="class1">
<div class="head two">BackEnd</div>
<div>Django</div>
<div>Flask</div>
<div>RestAPI</div>
</div>
<div class="class1">
<div class="head three">Database</div>
<div>Oracle</div>
<div>MySQL</div>
<div>MongoDB</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
h1,h2,h3 {
color:blue;
}
</style>
</head>
<body>
<h1>FrontEnd</h1>
<h2>HTML</h2>
<h3>Hyper Text Markup Language</h3>
<h2>CSS</h2>
<h3>Cascading Style Sheets</h3>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio iste
sint laudantium consequuntur esse, minima officia in quaerat, est
suscipit excepturi similique illo accusamus atque dolor sit earum veritatis
neque.
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Molestiae
dicta, eaque, temporibus veritatis nesciunt voluptatem maxime dolor
delectus inventore facere sunt ipsam architecto necessitatibus
exercitationem esse repellendus laborum odit incidunt.
</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
h1,li,p {
margin-left: 100px;
}
</style>
</head>
<body>
<h1>FrontEnd</h1>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odio iste
sint laudantium consequuntur esse, minima officia in quaerat, est
suscipit excepturi similique illo accusamus atque dolor sit earum veritatis
neque.
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Molestiae
dicta, eaque, temporibus veritatis nesciunt voluptatem maxime dolor
delectus inventore facere sunt ipsam architecto necessitatibus
exercitationem esse repellendus laborum odit incidunt.
</p>
</body>
</html>
CSS Pseudo Class Selector
A pseudo-class selector is used to style a specific state of an element, such as :hover is used to style an
element when hovered.
1. :hover
button:hover {
background-color: #4CAF50;
color: white;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
a:hover
{
font-size: 30px;
}
img:hover {
width:200px;
height: 200px;
}
input[type=submit]:hover {
background-color: #4CAF50;
color: white;
}
</style>
</head>
<body>
<a href="http://www.nareshit.com">Nareshit</a><br>
<img src="images/ind.JPG"><br>
<input type="submit">
</body>
</html>
2. :focus
Applies styles when an element gains focus, such as when a user clicks on an input field.
input:focus {
outline: none;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input[type=text]:focus {
background-color: aqua;
}
input[type=password]:focus {
background-color: yellow;
}
</style>
</head>
<body>
<form>
<label for="uname">UserName</label>
<input type="text" id="uname"><br>
<label for="pwd">Password</label>
<input type="password" id="pwd"><br>
<input type="submit">
</form>
</body>
</html>
3. :active
a:active {
color: red;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
a:active {
color: blue;
}
input[type=button]:active{
color:red;
}
</style>
</head>
<body>
<a href="http://www.nareshit.com">nareshit</a>
<form>
<input type="button" value="Login">
</form>
</body>
</html>
4. :first-child
ulli:first-child {
margin-top: 0;
5. :last-child
.container p:last-child {
margin-bottom: 0;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table tr:first-child
{
background-color: aqua;
color:red;
}
table tr:last-child {
background-color: yellow;
}
</style>
</head>
<body>
<table border="2" width="100%">
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Course</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>Python</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
<td>Java</td>
</tr>
<tr>
<td>3</td>
<td>Kishore</td>
<td>Java</td>
</tr>
<tr></tr>
<td>4</td>
<td>Naresh</td>
<td>Python</td>
</tr>
<tr>
<td>5</td>
<td>Suresh</td>
<td>Java</td>
</tr>
<tr>
<td>6</td>
<td>Kishore</td>
<td>Java</td>
</tr>
</table>
</body>
</html>
6. :nth-child(n)
Selects elements based on their position in a parent, where n can be a number, keyword, or formula.
table tr:nth-child(even) {
background-color: #f2f2f2;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table tr:nth-child(even)
{
background-color: aqua;
}
table tr:nth-child(odd) {
background-color: yellow;
}
table tr:nth-child(1) {
background-color: yellowgreen;
}
table tr:nth-child(3) {
background-color: aquamarine;
}
</style>
</head>
<body>
<table border="2" width="100%">
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Course</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>Python</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
<td>Java</td>
</tr>
<tr>
<td>3</td>
<td>Kishore</td>
<td>Java</td>
</tr>
<tr>
<td>4</td>
<td>Naresh</td>
<td>Python</td>
</tr>
<tr>
<td>5</td>
<td>Suresh</td>
<td>Java</td>
</tr>
<tr>
<td>6</td>
<td>Kishore</td>
<td>Java</td>
</tr>
</table>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container span:nth-child(1) {
background-color: aqua;
color:red;
font-family: Arial, Helvetica, sans-serif;
font-size: 20px;
}
.container span:nth-child(3) {
background-color: yellowgreen;
color:blue;
font-size: 20px;
}
</style>
</head>
<body>
<div class="container">
<span>Home</span>
<span>Courses</span>
<span>Contact Us</span>
</div>
</body>
</html>
7. :nth-of-type(n)
.container p:nth-of-type(3n) {
color: blue;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container p:nth-of-type(2n) {
background-color: aqua;
}
</style>
</head>
<body>
<div class="container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla vero
praesentium in ut fuga provident blanditiis ipsa cumque. Error saepe qui
cumque, nam temporibus assumenda aut sapiente consequuntur porro
reprehenderit!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quibusdam
voluptas modi eveniet? In eius distinctio voluptates, consequatur maxime
magni exercitationem molestias ad! Enim provident repudiandae, hic id ut
vel voluptas?
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Reiciendis
saepe ex consequatur perspiciatis laboriosam nostrum, nihil impedit quam
delectus praesentium, quaerat voluptatibus inventore. Nostrum, nam
deleniti nisi libero pariatur deserunt?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
consectetur, in libero officiis aliquam accusantium facilis nisi quibusdam
quia adipisci omnis, voluptatum quae, repudiandae asperiores iure quidem.
Temporibus, minus doloremque.
</p>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cum
dolorem, ab porro ratione fugiat amet! Mollitia ipsam dolore, itaque
obcaecati, repellendus eum eius dolorem, qui sunt dicta assumenda
placeat accusantium.
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Itaque id
tempore, voluptate, ratione eveniet quibusdam saepe maxime ex
dignissimos molestiae soluta voluptates ullam asperiores eligendi dolores
illum dolor sint enim.
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex ipsum
eaque provident vel! In architecto, tempore tempora porro libero facere
aperiam quod eligendi voluptatum maiores assumenda. Incidunt veniam
nemo vero!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti
nobis esse quo est accusamus aut id autem itaque eos placeat cumque
eligendi corporis tempora enim odio corrupti rerum, atque unde?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex ipsum
eaque provident vel! In architecto, tempore tempora porro libero facere
aperiam quod eligendi voluptatum maiores assumenda. Incidunt veniam
nemo vero!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti
nobis esse quo est accusamus aut id autem itaque eos placeat cumque
eligendi corporis tempora enim odio corrupti rerum, atque unde?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex ipsum
eaque provident vel! In architecto, tempore tempora porro libero facere
aperiam quod eligendi voluptatum maiores assumenda. Incidunt veniam
nemo vero!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti
nobis esse quo est accusamus aut id autem itaque eos placeat cumque
eligendi corporis tempora enim odio corrupti rerum, atque unde?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex ipsum
eaque provident vel! In architecto, tempore tempora porro libero facere
aperiam quod eligendi voluptatum maiores assumenda. Incidunt veniam
nemo vero!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti
nobis esse quo est accusamus aut id autem itaque eos placeat cumque
eligendi corporis tempora enim odio corrupti rerum, atque unde?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex ipsum
eaque provident vel! In architecto, tempore tempora porro libero facere
aperiam quod eligendi voluptatum maiores assumenda. Incidunt veniam
nemo vero!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Deleniti
nobis esse quo est accusamus aut id autem itaque eos placeat cumque
eligendi corporis tempora enim odio corrupti rerum, atque unde?
</p>
</div>
</body>
</html>
8. :not(selector)
input:not([type="password"]) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:not(img){
border: 2px solid black;
}
</style>
</head>
<body>
<div class="container">
<h1>Heading</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla vero
praesentium in ut fuga provident blanditiis ipsa cumque. Error saepe qui
cumque, nam temporibus assumenda aut sapiente consequuntur porro
reprehenderit!
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Quibusdam
voluptas modi eveniet? In eius distinctio voluptates, consequatur maxime
magni exercitationem molestias ad! Enim provident repudiandae, hic id ut
vel voluptas?
</p>
<img src="images/kids-banner.avif">
</div>
</body>
</html>
9. :checked
Selects input elements that are checked (like checkboxes or radio buttons).
input[type="checkbox"]:checked + label {
font-weight: bold;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
input[type=checkbox]:checked+label {
font-weight: bold;
}
input[type=radio]:checked+label{
color:blue;
font-weight: bold;
}
</style>
</head>
<body>
<form>
<input type="checkbox">
<label for="java">Java</label><br>
<input type="radio" name="c">
<label for="python">Python</label>
<input type="radio" name="c">
<label for="oracle" >Oracle</label>
</form>
</body>
</html>
10. :disabled
input:disabled {
background-color: #e0e0e0;
cursor: not-allowed;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
:disabled {
color:red;
}
</style>
</head>
<body>
<form>
<input type="button" disabled="true" value="button">
<input type="button" value="button">
<input type="button" value="button">
</form>
</body>
</html>
11. :before and :after
Add content before or after an element’s content.
Ul li::before {
content: "•";
color: red;
margin-right: 5px;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
span {
color:blue;
font-size: 20px;
}
span:before {
content: "#";
color:red;
font-size:20px;
}
span:after {
content: "*";
font-size: 20px;
color:red;
}
</style>
</head>
<body>
<h2>Courses</h2>
<div>
<span>Java</span><br>
<span>Oracle</span><br>
<span>Python</span><br>
</div>
</body>
</html>
CSS Descendant Selector
Descendant selector is used in css to style all the tags which are
child of a particular specified tag. A single space between parent
element and child element is used to mention as descendant .
Syntax
parent-element child-element
{
css-property:value;
css-property:value;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div p {
border: 2px solid black;
}
tr th{
background-color: aqua;
}
tr td {
background-color: yellow;
}
</style>
</head>
<body>
<div>
<p>
Lorem ipsum, dolor sit amet
consectetur adipisicing elit. Eveniet
accusamus enim cupiditate error, quasi
assumenda ratione reiciendis odio. Autem,
voluptatibus praesentium nesciunt
repudiandae quia sunt temporibus facilis
laborum totam animi.
Lorem ipsum dolor sit amet
consectetur adipisicing elit. Ratione beatae
eius vitae dolore dicta omnis iusto rerum
eveniet, quod ex delectus autem? Laboriosam
aspernatur at consectetur, rerum dolor iste
sint!
</p>
<p>
Lorem, ipsum dolor sit amet
consectetur adipisicing elit. Reprehenderit
animi ducimus nesciunt quam ex beatae
cumque harum, corporis iure impedit
consequuntur dignissimos aliquam ratione
saepe officia cum quo libero fugiat?
</p>
<span>HTML</span><br>
<p>
Lorem ipsum dolor sit amet
consectetur adipisicing elit. Distinctio nostrum
exercitationem velit? Repellendus autem eum
facilis voluptas dolorem saepe! Voluptatum
quos ad debitis tenetur illo maiores facilis nisi
architecto accusamus!
</p>
</div>
<div>
<span>HTML</span><br>
<span>CSS</span>
</div>
<table border="2" width="100%">
<tr>
<th>Rollno</th>
<th>Name</th>
<th>Course</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
<td>Java</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
<td>Python</td>
</tr>
</table>
</body>
</html>
CSS Child Selector
The child selector in css is used to target all the direct child of a
particular element. This is denoted by '>' (Greater than) symbol.
Syntax
div > p {
color: blue;
}
The above code set text color of paragraph tags that are directly
inside div element to blue.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div>p {
color:red;
}
</style>
</head>
<body>
<div>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ipsa
porro doloremque quaerat fugit omnis. Laborum officia deserunt ullam
amet, iste pariatur maiores totam excepturi eos nisi quam incidunt
minima voluptatum!</p>
<span>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Laborum eum ex alias corporis commodi accusantium non, illum
beatae ratione odio sit necessitatibus incidunt in debitis, architecto
nobis minus voluptas ipsa?</p>
</span>
</div>
</body>
</html>
Tr+th
Img+p
div+span
Syntax
h1 + p {
margin-top: 0;
}
The above code sets top margin of paragraph tag just after h1 tag
to 0.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
h1+p {
border: 1px solid black;
}
h2+p {
color:blue;
}
div+span{
border: 1px solid black;
}
</style>
</head>
<body>
<h1>HTML</h1>
<p>Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Exercitationem velit excepturi
corporis, est non accusamus eos nemo
commodi explicabo voluptatum consequatur
dolore unde, doloribus quae natus dignissimos
voluptatibus esse? Accusamus.</p>
<h2>What is HTML</h2>
<p>Lorem ipsum dolor sit amet consectetur
adipisicing elit. At blanditiis cupiditate dolores
laborum repellat ipsum odit provident
assumenda atque voluptas magnam maxime
culpa, iste possimus reiciendis ut repudiandae
molestiae quo.</p>
<h2>History of HTML</h2>
<p>Lorem ipsum dolor sit amet consectetur
adipisicing elit. Quas, voluptates laudantium id
quae dolore non, dolorum ratione et ipsam
incidunt quidem labore obcaecati suscipit
officiis, culpa cum enim explicabo sint?</p>
<p>Lorem ipsum dolor sit amet consectetur
adipisicing elit. Unde quod, inventore, sunt
doloribus praesentium quidem recusandae
aperiam dignissimos quis deleniti
necessitatibus fugiat mollitia, architecto a
perferendis nemo. Excepturi, a neque.</p>
<p>Lorem ipsum dolor sit amet consectetur
adipisicing elit. Pariatur earum doloribus
tempora reiciendis ullam possimus minima
delectus tenetur obcaecati id architecto, dolor
suscipit. In dolore sunt consequuntur ratione
possimus veritatis.</p>
<div>HTML</div>
<span>HTML</span>
</body>
</html>
Syntax
nav {
&ul {
list-style: none;
& li {
display: inline-block;
&a{
text-decoration: none;
color: blue;
&:hover {
color: red;
}
}
}
}
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div {
background-color: aqua;
border: 2px solid black;
& p{
font-size: 20px;
color:red;
& img {
width:200px;
height:200px;
}
}
}
</style>
</head>
<body>
<div>
<p>
Lorem, ipsum dolor sit amet
consectetur adipisicing elit. Laborum, fugit
totam praesentium suscipit tempora harum sit
cupiditate quibusdam? Voluptatem illo
doloribus dolore, corrupti perferendis dolor
expedita temporibus iusto saepe laudantium.
<img src="images/kids-banner.avif">
</p>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
nav {
& ul {
list-style: none;
& li {
display: inline-block;
&a{
text-decoration: none;
color: blue;
&:hover {
color: red;
}
}
}
}
}
</style>
</head>
<body>
<nav>
<ul>
<li><a>HOME</a></li>
<li><a>Courses</a></li>
<li><a>Contacts</a></li>
</ul>
</nav>
</body>
</html>
CSS Borders
Applying border to elements
Shorthand
border: width style color
Example:
h1 {
border-top: 1px solid black;
border-bottom: 1px solid red;
border-left: 3px blue double;
border-right: 3px blue double;
}
</style>
</head>
<body>
<h1>Hyper Text Markup Language </h1>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
h1 {
border-left-style: dotted;
border-right-style: double;
border-top-style:solid;
border-bottom-style: dashed;
border-left-color: blue;
border-right-color: red;
border-top-color: green;
border-bottom-color: blueviolet;
border-top-width: 5px;
border-bottom-width: 10px;
}
</style>
</head>
<body>
<h1>Hyper Text Markup Language </h1>
</body>
</html>
CSS Borders
Applying border to elements
Shorthand
border: width style color
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container
{
width:400px;
height:200px;
border:2px solid black;
border-top-left-radius: 50px;
border-bottom-right-radius: 50px;
}
</style>
</head>
<body>
<div class="container">
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
table {
border-collapse: collapse;
}
</style>
</head>
<body>
<table border="3px" width="80%">
<tr>
<th>Rollno</th>
<th>Name</th>
</tr>
<tr>
<td>1</td>
<td>Naresh</td>
</tr>
<tr>
<td>2</td>
<td>Suresh</td>
</tr>
<tr>
<td>3</td>
<td>Kishore</td>
</tr>
</table>
</body>
</html>
Border-block (shorthand)
Border-block-start-width
Border-block-start-style
Border-block-start-color
Border-block-end-width
Border-block-end-style
Border-block-end-color
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div {
border-block-start-width: 5px;
border-block-start-color: black;
border-block-start-style: dotted;
border-block-end-style: solid;
border-block-end-width: 5px;
border-block-end-color: red;
}
</style>
</head>
<body>
<div>
<span>HTML</span>
</div>
</body>
</html>
Box-shadow
Syntax:
container
{
Box-shadow:x-pos y-pos color
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div {
border:2px solid black;
width:300px;
height:200px;
box-shadow:10px 10px gray;
}
</style>
</head>
<body>
<div>
<span>HTML</span>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
img {
border: 2px solid black;
width:300px;
height: 300px;
box-shadow: 10px 10px blue;
}
p{
border: 2px solid black;
box-shadow:10px 5px blue ;
}
</style>
</head>
<body>
<img src="images/kids-banner.avif"><br>
<p>
Hyper Text Markup Language
</p>
</body>
</html>
CSS Layouts
What is layout?
Layout is organizing of elements or content within web page is
called layout.
Grid
Flex
Block
Inline
Inline block
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
a{
display:block;
border:2px solid black;
width:fit-content;
}
div {
display:inline;
}
</style>
</head>
<body>
<a>Link1</a>
<a>Link2</a>
<a>Link3</a>
<div> <span>Division1</span></div>
<div> <span>Division2</span> </div>
<div> <span>Division3</span> </div>
</body>
</html>
Inline-block
Inline-block display property is used with inline elements
If inline element display property not inline-block the size cannot
modified.
Syntax:
a{
width:100px;
height:150px;
display:inline-block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div {
width:100%;
border:2px solid black;
}
span {
width:300px;
height: 100px;
display:inline-block;
color:blue;
}
</style>
</head>
<body>
<div class="container">
<span>Span-1</span>
<span>Span-2</span>
<span>Span-3</span>
</div>
</body>
</html>
display:none
Syntax:
selector {
display:none;
}
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
div {
display:none;
}
a:hover {
& div{
display:block;
}
}
</style>
</head>
<body>
<a href="#">Home</a>
<div class="container">
<span>Span-1</span>
<span>Span-2</span>
<span>Span-3</span>
</div>
</body>
</html>
display: flex
flex-direction
the value of flex-direction can be,
1. column
2. row
3. column-reverse
4. row-reverse
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container
{
border:2px solid black;
display:flex;
flex-direction: column;
}
.container>div {
border: 2px solid red;
font-size: 20px;
</style>
</head>
<body>
<div class="container">
<div style="order:2;">
Div1
</div>
<div style="order:1">
Div2
</div>
<div style="order:3">
Div3
</div>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container
{
border:2px solid black;
display:flex;
flex-direction: row-reverse;
}
</style>
</head>
<body>
<div class="container">
<img style="order:2" src="images/kids-banner.avif">
<img style="order:3" src="images/men-banner.avif">
<img style="order:1" src="images/women-banner.avif">
</div>
</body>
</html>
flex-flow
Syntax:
Flex-flow: flex-direction flex-wrap
Example:
Flex-flow: row nowrap
Flex-flow: column nowrap
Flex-flow: row wrap
Flex-flow: column column-wrap/wrap
Display:flex
Flex-direction: row/column
Flex-wrap:wrap/nowrap
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container {
border: 1px solid black;
padding: 20px;
background-color: aqua;
display:flex;
flex-flow:column wrap;
height: 400px;
}
.container>div {
padding: 20px;
border: 1px solid black;
background-color: yellowgreen;
font-size: 40px;
font-weight: bold;
margin: 20px;
}
</style>
</head>
<body>
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
</div>
</body>
</html>
The justify-content property in CSS is used to align and
distribute space between flex items along the main axis of a
flex container. This property is part of the Flexbox layout model,
which helps create flexible and responsive layouts.
Values of justify-content
1. flex-start
o Description: Aligns flex items at the start of the
container.
o Example: Items are aligned to the left (or top,
depending on the flex direction).
2. flex-end
o Description: Aligns flex items at the end of the
container.
o Example: Items are aligned to the right (or bottom,
depending on the flex direction).
3. center
o Description: Centers flex items within the container.
o Example: Items are centered horizontally (or
vertically, depending on the flex direction).
4. space-between
o Description: Distributes flex items with equal space
between them, with no space at the start or end.
o Example: Items are spread out with equal spacing
between them.
5. space-around
o Description: Distributes flex items with equal space
around them, including space before the first item
and after the last item.
o Example: Items have equal space around them, with
half of the space at the start and end of the
container.
6. space-evenly
o Description: Distributes flex items with equal space
between and around them.
o Example: Items have equal spacing between them
and also at the start and end of the container.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container {
display:flex;
border: 1px solid black;
justify-content: space-between;
flex-direction: row;
height: 500px;
}
.container>div {
margin: 10px;
padding: 10px;
border:1px solid blue;
font-size: 30px;
width:50px;
height: 50px;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container
{
display:flex;
flex-direction: row;
justify-content: space-between;
border: 1px solid black;
padding:20px;
background-color: bisque;
}
.container>div {
width:400px;
background-color:azure;
}
.img {
display: flex;
flex-direction: column;
}
.container1 {
display:flex;
flex-wrap: wrap;
}
</style>
</head>
<body>
<div class="container">
<div>
<h2>Gaming accessories</h2>
<div class="container1">
<div class="img">
<img src="images/i1.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i2.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i3.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i4.jpg">
<span>Headsets</span>
</div>
</div>
</div>
<div>
<h2>New home arrivals under $50</h2>
<div>
<img src="images/k1.jpg">
<img src="images/k2.jpg">
<img src="images/k3.jpg">
<img src="images/k4.jpg">
</div>
</div>
<div>
<h2>Shop deals in Fashion</h2>
<div>
<img src="images/f1.jpg">
<img src="images/f2.jpg">
<img src="images/f3.jpg">
<img src="images/f4.jpg">
</div>
</div>
<div>
<h2>Refresh your space</h2>
<div>
<img src="images/d1.jpg">
<img src="images/d2.jpg">
<img src="images/d3.jpg">
<img src="images/d4.jpg">
</div>
</div>
</div>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Justify Content Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container flex-start">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
.container {
display: flex;
width: 80%;
margin-bottom: 20px;
border: 1px solid #ccc;
background-color: #fff;
padding: 10px;
}
.item {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px;
margin: 5px;
border-radius: 4px;
}
.flex-start {
justify-content: flex-start;
}
.flex-end {
justify-content: flex-end;
}
.center {
justify-content: center;
}
.space-between {
justify-content: space-between;
}
.space-around {
justify-content: space-around;
}
.space-evenly {
justify-content: space-evenly;
}
The position property in CSS is used to control the positioning of
an element on a webpage. It determines how an element is
placed within its containing element and how it interacts with
other elements. The position property can take several values:
static, relative, absolute, fixed, and sticky.
Here's a brief overview of each value with examples:
1. static
Definition: This is the default positioning for all elements.
Elements with position: static are positioned according to the
normal flow of the document. They are not affected by the top,
right, bottom, or left properties.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Static Position Example</title>
<style>
.static-box {
background-color: lightblue;
width: 200px;
height: 100px;
border: 2px solid blue;
}
</style>
</head>
<body>
<div class="static-box">Static Position</div>
</body>
</html>
Explanation:The .static-box element is positioned in the normal
document flow. It will appear where it would naturally fall in the
layout.
2. relative
Definition: An element with position: relative is positioned
relative to its normal position. It can be moved using the top,
right, bottom, and left properties, but the space originally
occupied by the element is still preserved.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.relative-box {
position: relative;
background-color: lightcoral;
width: 200px;
height: 100px;
border: 2px solid red;
top: 20px; /* Move down by 20px */
left: 30px; /* Move right by 30px */
}
</style>
</head>
<body>
<div class="relative-box">Relative Position</div>
</body>
</html>
Explanation:The .relative-box is moved 20px down and 30px
right from its normal position, but it still takes up the same
amount of space in the layout.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.container
{
width: 300px;
height:300px;
border: 1px solid black;
background-color: aquamarine;
}
.div1 {
position: relative;
left:100px;
}
.div2 {
position: relative;
right: 50px;
top:50px;
}
</style>
</head>
<body>
<div class="container div1">Division1</div>
<div class="container div2">Division2</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.s2 {
position: relative;
top:-5px;
left:-10px;
}
</style>
</head>
<body>
<div class="container">
<span class="s1">A</span>
<span class="s2">2</span>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Relative Position Example</title>
<style>
.bi-cart {
font-size: 50px;
}
.value {
font-size:20px ;
position: relative;
left:-30px;
top:-35px;
color:red;
}
.cart {
font-size: 20px;
font-weight: bold;
left:-20px;
top:10px;
position: relative;
}
</style>
</head>
<body>
<div>
<span class="bi bi-cart"></span>
<span class="value">0</span>
<span class="cart">Cart</span>
</div>
</body>
</html>
3. absolute
Definition: An element with position: absolute is positioned
relative to its nearest positioned ancestor (i.e., an ancestor with
position other than static). If no such ancestor exists, it is
positioned relative to the initial containing block (usually the
<html> element).
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Absolute Position Example</title>
<style>
.relative-container {
position: relative;
background-color: lightgrey;
width: 300px;
height: 200px;
border: 2px solid grey;
padding: 20px;
}
.absolute-box {
position: absolute;
background-color: lightgreen;
width: 150px;
height: 75px;
border: 2px solid green;
top: 20px; /* 20px from the top of the .relative-container */
right: 20px; /* 20px from the right of the .relative-
container */
}
</style>
</head>
<body>
<div class="relative-container">
<div class="absolute-box">Absolute Position</div>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-icons.min.css">
<title>Relative Position Example</title>
<style>
div {
width:400px;
height:300px;
border: 1px solid black;
position: absolute;
left:20px;
top:50px;
}
span {
font-size: 40px;
font-weight: bold;
position: absolute;
top:100px;
left:50px;
}
</style>
</head>
<body>
<div>
<span>Span</span>
</div>
</body>
</html>
Values of justify-content
1. flex-start
o Description: Aligns flex items at the start of the
container.
o Example: Items are aligned to the left (or top,
depending on the flex direction).
2. flex-end
o Description: Aligns flex items at the end of the
container.
o Example: Items are aligned to the right (or bottom,
depending on the flex direction).
3. center
o Description: Centers flex items within the container.
o Example: Items are centered horizontally (or
vertically, depending on the flex direction).
4. space-between
o Description: Distributes flex items with equal space
between them, with no space at the start or end.
o Example: Items are spread out with equal spacing
between them.
5. space-around
o Description: Distributes flex items with equal space
around them, including space before the first item
and after the last item.
o Example: Items have equal space around them, with
half of the space at the start and end of the
container.
6. space-evenly
o Description: Distributes flex items with equal space
between and around them.
o Example: Items have equal spacing between them
and also at the start and end of the container.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container {
display:flex;
border: 1px solid black;
justify-content: space-between;
flex-direction: row;
height: 500px;
}
.container>div {
margin: 10px;
padding: 10px;
border:1px solid blue;
font-size: 30px;
width:50px;
height: 50px;
background-color: yellowgreen;
}
</style>
</head>
<body>
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<style>
.container
{
display:flex;
flex-direction: row;
justify-content: space-between;
border: 1px solid black;
padding:20px;
background-color: bisque;
}
.container>div {
width:400px;
background-color:azure;
}
.img {
display: flex;
flex-direction: column;
}
.container1 {
display:flex;
flex-wrap: wrap;
}
</style>
</head>
<body>
<div class="container">
<div>
<h2>Gaming accessories</h2>
<div class="container1">
<div class="img">
<img src="images/i1.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i2.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i3.jpg">
<span>Headsets</span>
</div>
<div class="img">
<img src="images/i4.jpg">
<span>Headsets</span>
</div>
</div>
</div>
<div>
<h2>New home arrivals under $50</h2>
<div>
<img src="images/k1.jpg">
<img src="images/k2.jpg">
<img src="images/k3.jpg">
<img src="images/k4.jpg">
</div>
</div>
<div>
<h2>Shop deals in Fashion</h2>
<div>
<img src="images/f1.jpg">
<img src="images/f2.jpg">
<img src="images/f3.jpg">
<img src="images/f4.jpg">
</div>
</div>
<div>
<h2>Refresh your space</h2>
<div>
<img src="images/d1.jpg">
<img src="images/d2.jpg">
<img src="images/d3.jpg">
<img src="images/d4.jpg">
</div>
</div>
</div>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Justify Content Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container flex-start">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
Style.css
body {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
background-color: #f0f0f0;
}
.container {
display: flex;
width: 80%;
margin-bottom: 20px;
border: 1px solid #ccc;
background-color: #fff;
padding: 10px;
}
.item {
background-color: #4CAF50;
color: white;
text-align: center;
padding: 20px;
margin: 5px;
border-radius: 4px;
}
.flex-start {
justify-content: flex-start;
}
.flex-end {
justify-content: flex-end;
}
.center {
justify-content: center;
}
.space-between {
justify-content: space-between;
}
.space-around {
justify-content: space-around;
}
.space-evenly {
justify-content: space-evenly;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Static Position Example</title>
<style>
.static-box {
background-color: lightblue;
width: 200px;
height: 100px;
border: 2px solid blue;
}
</style>
</head>
<body>
<div class="static-box">Static Position</div>
</body>
</html>
Explanation:The .static-box element is positioned in the
normal document flow. It will appear where it would naturally
fall in the layout.
2. relative
Definition: An element with position: relative is positioned
relative to its normal position. It can be moved using the top,
right, bottom, and left properties, but the space originally
occupied by the element is still preserved.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.relative-box {
position: relative;
background-color: lightcoral;
width: 200px;
height: 100px;
border: 2px solid red;
top: 20px; /* Move down by 20px */
left: 30px; /* Move right by 30px */
}
</style>
</head>
<body>
<div class="relative-box">Relative Position</div>
</body>
</html>
Explanation:The .relative-box is moved 20px down and 30px
right from its normal position, but it still takes up the same
amount of space in the layout.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.container
{
width: 300px;
height:300px;
border: 1px solid black;
background-color: aquamarine;
}
.div1 {
position: relative;
left:100px;
}
.div2 {
position: relative;
right: 50px;
top:50px;
}
</style>
</head>
<body>
<div class="container div1">Division1</div>
<div class="container div2">Division2</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Relative Position Example</title>
<style>
.s2 {
position: relative;
top:-5px;
left:-10px;
}
</style>
</head>
<body>
<div class="container">
<span class="s1">A</span>
<span class="s2">2</span>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-
icons.min.css">
<title>Relative Position Example</title>
<style>
.bi-cart {
font-size: 50px;
}
.value {
font-size:20px ;
position: relative;
left:-30px;
top:-35px;
color:red;
}
.cart {
font-size: 20px;
font-weight: bold;
left:-20px;
top:10px;
position: relative;
}
</style>
</head>
<body>
<div>
<span class="bi bi-cart"></span>
<span class="value">0</span>
<span class="cart">Cart</span>
</div>
</body>
</html>
3. absolute
Definition: An element with position: absolute is positioned
relative to its nearest positioned ancestor (i.e., an ancestor with
position other than static). If no such ancestor exists, it is
positioned relative to the initial containing block (usually the
<html> element).
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Absolute Position Example</title>
<style>
.relative-container {
position: relative;
background-color: lightgrey;
width: 300px;
height: 200px;
border: 2px solid grey;
padding: 20px;
}
.absolute-box {
position: absolute;
background-color: lightgreen;
width: 150px;
height: 75px;
border: 2px solid green;
top: 20px; /* 20px from the top of the .relative-container
*/
right: 20px; /* 20px from the right of the .relative-
container */
}
</style>
</head>
<body>
<div class="relative-container">
<div class="absolute-box">Absolute Position</div>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<link rel="stylesheet"
href="../node_modules/bootstrap-icons/font/bootstrap-
icons.min.css">
<title>Relative Position Example</title>
<style>
div {
width:400px;
height:300px;
border: 1px solid black;
position: absolute;
left:20px;
top:50px;
}
span {
font-size: 40px;
font-weight: bold;
position: absolute;
top:100px;
left:50px;
}
</style>
</head>
<body>
<div>
<span>Span</span>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Fixed Position Example</title>
<style>
.fixed-box {
position: fixed;
background-color: lightpink;
width: 150px;
height: 75px;
border: 2px solid pink;
bottom: 20px; /* 20px from the bottom of the viewport
*/
right: 20px; /* 20px from the right of the viewport */
}
</style>
</head>
<body>
<div class="fixed-box">Fixed Position</div>
<div style="height: 1500px;">Scroll down to see the fixed
box</div>
</body>
</html>
Explanation:The .fixed-box remains 20px from the bottom and
right of the viewport, regardless of scrolling.
5. sticky
Definition: An element with position: sticky toggles between
relative and fixed, depending on the user's scroll position. It
acts like relative until it crosses a defined threshold, at which
point it behaves like fixed.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Sticky Position Example</title>
<style>
header {
background-color: lightblue;
padding: 10px;
text-align: center;
position: sticky;
top: 0; /* Stick to the top of the viewport */
z-index: 1000; /* Ensure it is on top of other content */
}
.content {
height: 1500px; /* To make the page scrollable */
padding: 20px;
}
</style>
</head>
<body>
<header>
Sticky Header
</header>
<div class="content">
Scroll down to see the sticky header in action.
</div>
</body>
</html>
Explanation: The header element with position: sticky sticks
to the top of the viewport as you scroll down the page.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Sticky Position Example</title>
<style>
.container {
border: 1px solid red;
}
.child{
border: inherit;
}
</style>
</head>
<body>
<div class="container">
<div class="child">Div1</div>
<div class="child">Div2</div>
<div class="child">Div3</div>
</div>
</body>
</html
CSS float
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Sticky Position Example</title>
<style>
.container1{
float:right;
width:200px;
height:200px;
background-color: aquamarine;
}
.container2{
float:left;
width:200px;
height:200px;
background-color: aquamarine;
}
.container3{
float:left;
width:700px;
height:200px;
background-color: aquamarine;
margin-left: 150px;
}
.container4{
float:none;
width:200px;
height:200px;
background-color: aquamarine;
}
</style>
</head>
<body>
<div class="container1">
Container1
</div>
<div class="container2">
Container2
</div>
<div class="container3">
Container3
</div>
<div class="container4">
Container4
</div>
</body>
</html>
The z-index property in CSS controls the stacking order of positioned elements. It determines which
elements appear on top of others when they overlap. This property only works on elements that have a
position value other than static (i.e., relative, absolute, fixed, or sticky).
1. Stacking Context:
o Stacking Context: An element with a z-index value creates a new stacking context. This
means it will be stacked relative to other elements within the same stacking context, not
necessarily to the entire document.
Positive Values: Elements with a higher z-index value will be stacked above those with lower
values.
Negative Values: Elements with negative z-index values will be stacked below those with positive
values or the default stacking order.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Z-Index Example</title>
</head>
<body>
<div class="container">
</div>
</body>
</html>
Styles.css
.container {
position: relative;
width: 200px;
height: 200px;
.box {
position: absolute;
width: 100px;
height: 100px;
color: white;
text-align: center;
.box1 {
background-color: red;
top: 10px;
left: 10px;
.box2 {
background-color: green;
top: 30px;
left: 30px;
z-index: 3; /* Stacks above box1 */
.box3 {
background-color: blue;
top: 50px;
left: 50px;
Create the Container: Use a container element to hold the content you want to overlay. A
container can be div element, span element or even an image.
Set Up the Positioning: Make the container position: relative so that any absolutely positioned
elements inside it will be positioned relative to this container.
Add the Overlay Element: Inside the container, add another element (the overlay) and
set position: absolute to ensure it covers the entire container. Also make sure the overlay's top,
left properties are set to 0 and width, height properties are set to 100%, so it fully covers the
container.
Style the Overlay: Set the background color of the overlay using rgba() function to give a semi-
transparent effect. And initially, set the opacity of the overlay to 0 to make it invisible by default.
Add Hover Effect: Use hover pseudo-class to the overlay container to change the overlay's
opacity from 0 to 1 when user moves mouse over container.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.container {
position: relative;
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(7, 250, 7, 0.5);
opacity: 0;
transition: opacity 1s ease;
.overlay-container:hover .overlay {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<div class="overlay-container">
<img src="images/moto.jpg" alt="Image">
<div class="overlay">
Learn CSS
</div>
</div>
</div>
</body>
</html>
The CSS transition property is used to create smooth,
animated changes between different states of an element.
It allows you to specify which CSS properties should
animate, how long the transition should last, the timing
function that controls the speed of the transition, and any
delay before the transition starts.
Key Concepts
1. Properties to Animate: You can specify specific CSS
properties (like background-color, width, etc.) that you
want to transition. Alternatively, you can use all to
apply transitions to every animatable property.
2. Duration: This defines how long the transition takes
to complete. It can be specified in seconds (s) or
milliseconds (ms).
3. Timing Function: This defines the acceleration curve
of the transition. Common options include:
o ease: Starts slow, speeds up, then slows down.
o linear: Constant speed throughout.
o ease-in: Starts slow and speeds up.
o ease-out: Starts fast and slows down.
o ease-in-out: Starts and ends slow, with a faster
middle.
4. Delay: This specifies a delay before the transition
starts, allowing for timing adjustments.
<div class="color-box"></div>
.color-box {
width: 100px;
height: 100px;
background-color: blue;
transition: background-color 0.5s ease;
}
.color-box:hover {
background-color: green;
}
<div class="size-box"></div>
.size-box {
width: 100px;
height: 100px;
background-color: orange;
transition: width 0.4s ease, height 0.4s ease;
}
.size-box:hover {
width: 150px;
height: 150px;
}
3. Opacity Transition
<div class="fade-box"></div>
.fade-box {
width: 100px;
height: 100px;
background-color: purple;
opacity: 1;
transition: opacity 0.6s ease;
}
.fade-box:hover {
opacity: 0.5;
}
4. Transform Transition
<div class="transform-box"></div>
.transform-box {
width: 100px;
height: 100px;
background-color: red;
transition: transform 0.3s ease-in-out;
}
.transform-box:hover {
transform: rotate(45deg) scale(1.1);
}
5. Multiple Properties Transition
<div class="multi-box"></div>
.multi-box {
width: 100px;
height: 100px;
background-color: teal;
transition: background-color 0.5s ease, transform 0.3s
ease;
}
.multi-box:hover {
background-color: yellow;
transform: translateY(20px);
}
6. Delay Transition
<div class="delay-box"></div>
.delay-box {
width: 100px;
height: 100px;
background-color: pink;
transition: background-color 0.5s ease 0.2s; /* 0.2s delay
*/
}
.delay-box:hover {
background-color: lightblue;
}
7. Using all for Simplicity
<div class="all-box"></div>
.all-box {
width: 100px;
height: 100px;
background-color: lightgreen;
transition: all 0.5s ease;
}
.all-box:hover {
background-color: lime;
width: 120px;
height: 120px;
}
The CSS transform property is used to apply various
transformations to an element, allowing you to change its
size, shape, position, and orientation. This property can be
used for effects like rotation, scaling, translation, and
skewing, enhancing the visual dynamics of web pages.
Syntax
transform: transform-function(value);
Common Transform Functions
1. Translate: Moves an element from its current
position.
o Syntax: translate(x, y)
o Example:
transform: rotate(45deg);
4. Skew: Distorts the shape of an element along the X
and Y axes.
o Syntax: skew(x-angle, y-angle)
o Example:
<div class="transform-box"></div>
.transform-box {
width: 100px;
height: 100px;
background-color: blue;
transition: transform 0.3s ease;
}
.transform-box:hover {
transform: translate(20px, 20px) rotate(45deg) scale(1.2);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.color-box {
width: 100px;
height: 100px;
background-color: blue;
transition: background-color 2.5s ease;
}
.color-box:hover {
background-color: green;
}
.size-box {
width: 100px;
height: 100px;
background-color: orange;
transition: width 0.4s ease, height 0.4s ease;
}
.size-box:hover {
width: 150px;
height: 150px;
}
.fade-box {
width: 100px;
height: 100px;
background-color: purple;
opacity: 1;
transition: opacity 0.6s ease;
}
.fade-box:hover {
opacity: 0.5;
}
.transform-box {
width: 100px;
height: 100px;
background-color: red;
transition: transform 2s ease-in-out;
}
.transform-box:hover {
transform: rotate(180deg) scale(2.0,2.0);
}
.multi-box {
width: 100px;
height: 100px;
background-color: teal;
transition: background-color 0.5s ease, transform 0.3s ease;
}
.multi-box:hover {
background-color: yellow;
transform: translateX(20px);
}
.delay-box {
width: 100px;
height: 100px;
background-color: pink;
transition: background-color 0.5s ease 1s; /* 0.2s delay */
}
.delay-box:hover {
background-color: lightblue;
}
.all-box {
width: 100px;
height: 100px;
background-color: lightgreen;
transition: all 0.5s ease;
}
.all-box:hover {
background-color: lime;
width: 120px;
height: 120px;
}
.transform-box {
width: 100px;
height: 100px;
background-color: blue;
transition: transform 0.3s ease;
}
.transform-box:hover {
transform: translate(50px, 20px) rotate(45deg) scale(1.2);
}
</style>
</head>
<body>
<div class="color-box"></div>
<div class="size-box"></div>
<div class="fade-box"></div>
<div class="transform-box">Text</div>
<div class="multi-box"></div>
<div class="delay-box"></div>
<div class="all-box"></div>
<div class="transform-box"></div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.btn {
width:100px;
height: 100px;
background-color: blue;
color:white;
font-size: 20px;
transition: color 1s ease, font-size 1s ease;
}
.btn:hover
{
color:red;
font-size: 10px;
}
</style>
</head>
<body>
<form>
<input type="button" value="Login" class="btn">
</form>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img
{
opacity: 0.5;
transition: opacity 0.5s ease, transform 0.5s ease;
}
img:hover
{
opacity: 1;
transform: translateX(100px);
}
</style>
</head>
<body>
<img src="images/kids-banner.avif">
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
img
{
opacity: 0.5;
transition: opacity 0.5s ease, transform 0.5s ease;
}
img:hover
{
opacity: 1;
transform: skewY(20deg);
}
</style>
</head>
<body>
<img src="images/kids-banner.avif">
</body>
</html>
The z-index property in CSS controls the stacking order of positioned elements.
It determines which elements appear on top of others when they overlap. This
property only works on elements that have a position value other than static
(i.e., relative, absolute, fixed, or sticky).
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Z-Index Example</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>
<div class="box box3">Box 3</div>
</div>
</body>
</html>
Styles.css
.container {
position: relative;
width: 200px;
height: 200px;
}
.box {
position: absolute;
width: 100px;
height: 100px;
color: white;
text-align: center;
line-height: 100px; /* Center text vertically */
}
.box1 {
background-color: red;
top: 10px;
left: 10px;
z-index: 1; /* Stacks above elements with lower z-index */
}
.box2 {
background-color: green;
top: 30px;
left: 30px;
z-index: 3; /* Stacks above box1 */
}
.box3 {
background-color: blue;
top: 50px;
left: 50px;
z-index: 2; /* Stacks above box1 but below box2 */
}
Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.container {
position: relative;
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(7, 250, 7, 0.5);
opacity: 0;
transition: opacity 1s ease;
.overlay-container:hover .overlay {
opacity: 1;
}
</style>
</head>
<body>
<div class="container">
<div class="overlay-container">
<img src="images/moto.jpg" alt="Image">
<div class="overlay">
Learn CSS
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
img {
width: 200px;
height: 200px;
margin-left: 40%;
}
.overlay-container {
position: relative;
width: 25%;
height: auto;
}
.overlay-container:hover .top-bottom {
opacity: 1;
height: 200px;
}
.top-bottom{
position: absolute;
transition: 0.9s ease;
opacity: 0.3;
width: 200px;
border-radius: 5px;
height: 0;
top: 0;
left: 40%;
background-color: #d346e6;
text-align: center;
color: #ffffff;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<h2> Hover your cursor over the image.</h2>
<div class="overlay-container">
<imgsrc= "/css/images/tutimg.png">
<div class="top-bottom">
<h2> Top to Bottom Image Overlay </h2>
</div>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
img {
width:200px;
height:200px;
position:absolute;
}
.overlay-container {
position: relative;
width: 25%;
height: auto;
}
.overlay-container:hover .top-bottom {
opacity: 1;
height: 200px;
}
.top-bottom{
position: absolute;
transition: 0.9s ease;
opacity: 0;
width: 200px;
height: 0;
background-color: #d346e6;
text-align: center;
color:black;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<div class="overlay-container">
<img src="images/kids-banner.avif">
<div class="top-bottom">
<h2> Top to Bottom Overlay </h2>
</div>
</div>
</body>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.overlay-container
{
width: 300px;
height:300px;
background-color: blue;
position: relative;
}
.overlay-container:hover .overlay{
opacity: 1;
height: 300px;
}
.overlay {
transition: 1s ease;
width:300px;
height:0px;
position: absolute;
background-color: brown;
opacity: 0;
}
</style>
</head>
<body>
<div class="overlay-container">
<div class="overlay">
<h2>Overlay</h2>
</div>
</div>
</body>
<head>
<style>
img {
width: 200px;
height: 200px;
}
.overlay-container {
position: relative;
width: 25%;
height: auto;
}
.overlay-container:hover .bottom-top {
opacity: 1;
height: 200px;
}
.bottom-top {
position: absolute;
transition: 0.9s ease;
opacity: 0.3;
width: 200px;
border-radius: 5px;
height: 0;
bottom: 0;
background-color: #d346e6;
text-align: center;
color: #ffffff;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<h2>Hover your cursor over the image.</h2>
<div class="overlay-container">
<imgsrc= "/css/images/tutimg.png">
<div class="bottom-top">
<h2>Bottom to Top Image Overlay</h2>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.overlay-container
{
width: 300px;
height:300px;
background-color: blue;
position: relative;
}
.overlay-container:hover img{
opacity: 1;
height: 300px;
}
img {
width:300px;
height:0px;
position: absolute;
opacity: 0;
bottom:0px;
transition: 1s ease;
}
</style>
</head>
<body>
<div class="overlay-container">
<img src="images/kids-banner.avif">
</div>
</body>
<!DOCTYPE html>
<html lang="en">
<head>
<style>
img {
width: 200px;
height: 200px;
}
.overlay-container {
position: relative;
width: 25%;
height: auto;
}
.overlay-container:hover .left-right {
opacity: 1;
width: 200px;
}
.left-right {
position: absolute;
transition: 0.9s ease;
opacity: 0.3;
width: 0;
border-radius: 5px;
height: 200px;
top: 0;
left: 0;
background-color: #d346e6;
text-align: center;
color: #ffffff;
}
h2 {
text-align: center;
}
</style>
</head>
<body>
<h2>Hover your cursor over the image.</h2>
<div class="overlay-container">
<imgsrc="/css/images/tutimg.png">
<div class="left-right">
<h2>Left to Right Image Overlay</h2>
</div>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.overlay-container
{
width:300px;
height:300px;
position: relative;
background-color: blueviolet;
}
.overlay-container:hover .overlay {
width:300px;
opacity: 1;
}
.overlay
{
height:300px;
position: absolute;
left:0px;
width:0px;
background-color:brown;
transition: 1s ease;
opacity: 0;
}
</style>
</head>
<body>
<div class="overlay-container">
<div class="overlay">
<h2>Left to Right</h2>
</div>
</div>
</body>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.overlay-container
{
width:300px;
height:300px;
position: relative;
background-color: blueviolet;
}
.overlay-container:hover .overlay{
transition:2s ease;
transform: rotate(360deg);
opacity: 1;
}
.overlay
{
width:300px;
height:300px;
position: absolute;
background-color: brown;
opacity: 0;
}
</style>
</head>
<body>
<div class="overlay-container">
<div class="overlay">
<h2>Left to Right</h2>
</div>
</div>
</body>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.overlay-container
{
width:300px;
height:300px;
position:relative;
background-color: rgb(251, 255, 0);
}
img {
position: absolute;
top:50px;
left:100px;
width:100px;
height:100px;
}
h2
{
position: absolute;
bottom: 50px;
left: 30px;
}
.overlay
{
opacity: 0;
background-color: bisque;
width:300px;
height:300px;
}
.overlay-container:hover .overlay {
opacity: 1;
transition: 0.1s ease;
}
</style>
</head>
<body>
<div class="overlay-container">
<img src="images/chennai.png">
<h2> Chennai Super Kings</h2>
<div class="overlay">
<img src="images/iplcup.jpg">
</div>
</div>
</body>
CSS Slide Show
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<style>
* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
/* Slideshow container */
.slideshow-container {
position: relative;
background: #f1f1f1f1;
}
/* Slides */
.mySlides {
display: none;
padding: 80px;
text-align: center;
}
/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
<div class="slideshow-container">
<div class="mySlides">
<q>I love you the more in that I believe you had liked me for
my own sake and for nothing else</q>
<p class="author">- John Keats</p>
</div>
<div class="mySlides">
<q>But man is not made for defeat. A man can be destroyed
but not defeated.</q>
<p class="author">- Ernest Hemingway</p>
</div>
<div class="mySlides">
<q>I have not failed. I've just found 10,000 ways that won't
work.</q>
<p class="author">- Thomas A. Edison</p>
</div>
</div>
<div class="dot-container">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n >slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i<slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i<dots.length; i++) {
dots[i].className = dots[i].className.replace(" active",
"");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-
scale=1">
<style>
.slideshow-container
{
position: relative;
}
.mySlides
{
display:none;
}
img {
width:100%;
height: 500px;
}
.prev, .next {
position: absolute;
top: 50%;
width: auto;
margin-top: -30px;
padding: 16px;
color:black;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select: none;
}
.next {
position: absolute;
right: 0;
border-radius: 3px 0 0 3px;
}
</style>
</head>
<body>
<div class="slideshow-container">
<div class="mySlides">
<img src="images/img1.jpg">
</div>
<div class="mySlides">
<img src="images/img2.jpg">
</div>
<div class="mySlides">
<img src="images/img3.jpg">
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
if (n >slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i<slides.length; i++) {
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
}
</script>
</body>
</html>
JavaScript History, Versions
What is JavaScript?
Mocha: The project’s original name was Mocha, later renamed to LiveScript
during its development in September 1995.
JavaScript: In December 1995, Netscape Navigator 2.0 Beta 3 introduced the
language under the name JavaScript, capitalizing on the popularity of
Java, although the two languages are distinct and were developed
independently.
ES2 and ES3: Released in 1998 and 1999, respectively, these versions
introduced minor improvements and new features, with ES3 being
particularly notable for its regular expressions, try/catch exception
handling, and more.
Current Version of ECAMScript is ECMAScript2023
ES14 ECMAScript 2023
Why JavaScript?
Syntax:
<script>
javascript
</script>
Syntax:
<script>
javascript
</script>
Syntax:
<head>
<script language=”javascript”>
Statement-1;
Statement-2;
</script>
</head>
Syntax:
<script src=”path”>
<script src=”x.js”>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
alert("Inside Head");
</script>
</head>
<body>
<script>
alert("Inside Body");
</script>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script src="/src/js1.js"></script>
</head>
<body>
</body>
</html>
Keywords
Keywords are reserved words, the meaning of these words are
reserved by java script translator. These are predefined words or
language related words
List of Keywords
while,case,class,void,function,instanceof
throw,export,delete,catch,private,package
true,debugger,extends,default,interface,super
with,enum,if,return,switch,try
let,yield,typeof,public,for,static
new,else,finally,false,import,var
do,protected,null,in,implements,this
await,const,continue,break
Identifier
Identifiers are user defined words, which are used for identifying
programming elements.
1. Variable name
2. Constant name
3. Function name
4. Class name
student rollno=1
VM131:1 Uncaught SyntaxError: Unexpected identifier 'rollno'
Example:
a=10
10
A=20
20
a
10
A
20
_=100
100
console.log(_)
VM570:1 100
undefined
$=200
200
console.log($)
VM647:1 200
undefined
amt$=100
100
console.log(amt$)
VM730:1 100
x=9999999999999999999999999999999999999999999999
1e+46
y=99999999999999999999999999999999999999999999999999
9999999999999999999999999
1e+75
Java Script data types
1. number
x=9999999999999999999999999999999999999999999999
1e+46
y=99999999999999999999999999999999999999999999999999
9999999999999999999999999
1e+75
let keyword
Example:
let x,y;
Example:
let a; // Declaration
a=10 // Assignment
a=20 // Assignment
Example:
let x=100,y=200;
let p,q;
var
This keyword is used for creating variables.
This is used for creating global variables. These variables can be
accessible within block and outside the block.
Syntax:
var <variable-name>;
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
if(10>2)
{
let a=100;
var b=300;
}
alert(b);
</script>
</head>
<body>
</body>
</html>
Scope:
var: Declared variables have function scope, meaning they're
accessible within the entire function.
let: Declared variables have block scope, meaning they're only
accessible within the block where they're declared.
Hoisting:
var: Variables declared with var are hoisted to the top of their
scope, meaning they can be used before they're declared. This
can sometimes lead to unexpected behavior.
let: Variables declared with let are not hoisted. Using them before
they're declared will result in a ReferenceError.
Redeclaration:
var: You can redeclare variables using var within the same scope.
let: You cannot redeclare variables using let within the same
scope. This will result in a SyntaxError.
const keyword
Example:
const PI=3.14;
console.log(PI);
PI=3.147; Syntax Error
Java script does not support single character data type (there is
no char data type).
Example:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=100;
let b=200;
let c=a+b;
let s1=`sum of ${a} and ${b} is ${c}`;
alert(s1);
let s2='sum of ${a} and ${b} is ${c}';
alert(s2);
</script>
</head>
<body>
</body>
</html>
null value
let name=null;
typeof name object
alert()
This function display message window and waits until end user
press ok. Until this window is not closed end user cannot
communicate with web page.
Syntax: alert(message)
Example:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
alert("Alert Window")
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
prompt()
This function display input window, where end user input value.
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let name=prompt("Name","Name");
alert(name)
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Example:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let num1=prompt("Number1 ");
let num2=prompt("Number2 ");
let num3=num1+num2
alert(num3);
alert(typeof num1)
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
confirm()
This function display confirm window
The function confirm shows a modal window with a question and
two buttons: OK and Cancel.
This function returns Boolean value(True/False)
If end user click on Ok, it returns True
If end user click on Cancel, it returns False
Syntax: confirm(message)
Example:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let num1=prompt("Number1 ");
let num2=prompt("Number2 ");
let b=confirm("Add Numbers?");
if(b)
{
alert(num1+num2);
}
else
{
alert(num1+","+num2);
}
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Type conversions or type casting
1. Number()
2. Boolean()
3. String()
Number()
It is predefined function provided by java script.
This function is used to perform the following conversions
1. Integer to integer (number to number)
2. Float to float (number to number)
3. String to number
4. Boolean to number
Syntax: Number(value)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=Number(34);
let b=Number(1.5);
let c=Number("45");
let d=Number("1.5");
let e=Number(true);
let f=Number(false);
alert(a);
alert(b);
alert(c);
alert(d);
alert(e);
alert(f);
let g=Number("a");
alert(g);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=prompt("Enter First Number");
let b=prompt("Enter Second Number");
let c=Number(a)+Number(b);
alert(c);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
String()
String is a predefined function in java script.
This function is used to convert others types into string type.
Syntax: String(value)
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=String(45);
let b=String(1.5);
let c=String("JS");
let d=String(true);
let f=String(false);
alert(a+b+c+d+f);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Boolean()
This function is used to convert other types into Boolean type
(true/false).
Syntax: Boolean(value)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=Boolean(1);
let b=Boolean(0);
alert(a);
alert(b);
let c=Boolean(100);
alert(c);
let d=Boolean(1.5);
alert(d);
let e=Boolean("true");
alert(e);
let f=Boolean("false");
alert(f);
let g=Boolean("A");
alert(g);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Operators
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. String Operators
5. Logical Operators
6. Bitwise Operators
7. Ternary Operators
8. Type Operators
Arithmetic Operators
These operators are used for perform arithmetic operations.
Operators Description
+ Adding and concatenation
- Subtraction
* Multiplication
/ Division
% Modular
** Power of
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=10;
let b=20;
let c=a+b;
alert(c);
let f1=1.5;
let f2=1.3;
let f3=f1+f2;
alert(f3);
let f4=a+f1;
alert(f4);
let x=15;
let y="20";
let z=x+y;
alert(z);
let p=f1+"1.2";
alert(p);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
alert(10+20);
alert(10-5);
alert(5*3);
alert(5/2);
alert(5%2);
alert(5**2);
</script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
Operato Description
r
=
+=
-=
*=
/=
%=
**=
Assignment Operators (OR) Update Operators
Operato
r
=
+=
-=
*=
/=
%=
**=
Example
Js1.js Jstest3.html
let x=10; <!DOCTYPE html>
console.log(x); <html lang="en">
x+=5; <head>
console.log(x); <meta charset="UTF-8">
let y=5 <meta name="viewport"
console.log(y); content="width=device-width,
y-=2; initial-scale=1.0">
console.log(y); <title>Document</title>
let z=9; <script
console.log(z); src="/src/js1.js"></script>
z*=3 </head>
console.log(z); <body>
let a=6;
console.log(a); </body>
a/=3; </html>
console.log('a='+a);
let b=5;
b**=2;
console.log('b='+b);
Unary ++,-- operator
++opr pre-increment
opr++ post-increment
opr-- post decrement
--opr pre decrement
Js1.js Jstest4.html
let x=5; <!DOCTYPE html>
let y=x++; <html lang="en">
console.log(y); <head>
console.log(x); <meta charset="UTF-8">
<meta name="viewport"
let a=10; content="width=device-width,
let b=++a; initial-scale=1.0">
console.log(b); <title>Document</title>
console.log(a); <script
src="/src/js1.js"></script>
let c=8; </head>
console.log(c++); <body>
console.log(c);
</body>
let d=9; </html>
console.log(++d);
let p=5;
let q=--p;
console.log(q);
let e=9;
let f=e--;
console.log(e);
console.log(f);
let num=5;
num++;
console.log(num);
Logical Operators
These operators are used for combining two or more logical
expressions or boolean expressions.
Operator Description
&& Logical and operator
|| Logical or operator
! Logical NOT operator
Operat Description
or
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
console.log(1==true);
console.log(0==false);
console.log(1===true);
console.log(0===false);
console.log(10>2);
let p=5;
console.log(++p>5);
console.log(10<2);
console.log(10<=10);
console.log(5>=4);
</body>
</html>
Conditional operator
Conditional operator is ternary operator and required 3 operands.
Conditional operator is used for creating conditional expression.
Syntax: opr1?opr2:opr3
Syntax:
switch(variable/expression)
{
case <value>:
statement-1;
statement-2;
break;
case <value>:
statement-3
statement-4
break;
case <value>:
statement-5
statement-6:
break;
….
default:
statement-7
statement-8;
}
Example:
let course=prompt("Enter Course");
switch(course)
{
case "java":
console.log("Java Fee 2000");
break;
case "python":
console.log("Python Fee 6000");
break;
case "oracle":
console.log("Oracle Fee 1000");
break;
default:
console.log("Invalid Course Name");
}
while loop
“while” is keyword, which represents looping statement.
While loop required 3 statements
1. initialization statement
2. condition
3. update statement
Syntax:
while(<condition>)
{
Statement-1;
Statement-2;
}
Example:
let x=1; // initialization statement
while(x<=5) //condition
{
console.log("JAVASCRIPT");
++x;
Example:
// Script to count digits
for loop
for loop is used to execute block of statements number of times.
Syntax:
for([initialization];[condition];[update])
{
Statement-1;
Statement-2;
}
Syntax:
for([initialization];[condition];[update])
{
Statement-1;
Statement-2;
}
for(let i=1;i<=10;i++)
{
console.log(i);
}
for(;;)
{
console.log("JAVASCRIPT");
}
do..while
do..while is exit control loop.
In exit control loop, the condition is verified after executing
statements.
Syntax:
do
{
Statement-1;
Statement-2;
}while(condition);
}
// Write script to generate factorial of numbers from 1 to 5
for(let num=1;num<=5;num++)
{
let i=1;
let fact=1;
do
{
fact=fact*i;
i++;
}while(i<=num);
console.log(fact);
}
break, continue
Syntax-1: break;
Syntax-2: break <label>;
Syntax-1: continue;
Syntax-2: continue <label>;
Example:
for(let i=1;i<=100;i++)
{
console.log("JAVASCRIPT");
if(i==5)
break;
Example:
for(let i=1;i<=50;i++)
{
if(i%2==0)
continue;
console.log(i);
}
Example:
// Prime Number
let num=Number(prompt("Enter any number "));
let c=0;
for(let i=1;i<=num;i++)
{
if(num%i==0)
c+=1;
if(c>2)
break;
}
if(c==2)
console.log("Prime");
else
console.log("Not Prime");
Label loop
Syntax:
Example:
outer:for(let i=1;i<=5;i++)
{
for(let j=1;j<=5;j++)
{
console.log(j);
if(j==3)
continue outer;
}
}
Example:
outer:for(let i=1;i<=5;i++)
{
for(let j=1;j<=5;j++)
{
console.log(j);
if(j==3)
break outer;
}
}
Arrays in JavaScript
Example
let a=[];
console.log(a);
console.log(typeof a);
let b=new Array();
console.log(b);
console.log(typeof b);
let c=new Array(5);
console.log(c);
console.log(typeof c);
console.log(c.length);
let d=Array();
console.log(d);
Example:
let a=[10,20,30,40];
console.log(a);
console.log(a.length);
a.length=10;
a.length=2;
let b=["HTML","JS","CSS"];
console.log(b);
let c=["HTML",5.1];
console.log(c);
How to read content of array?
1. Index
2. forEach() method of array
Example:
let a=[10,20,30,40,50];
console.log(a[0]);
console.log(a[1]);
console.log(a[2]);
console.log(a[3]);
console.log(a[4]);
for(let i=0;i<a.length;i++)
console.log(a[i]);
for(let i=a.length-1;i>=0;i--)
console.log(a[i]);
forEach()
forEach method of array read each element from array perform
action or operation.
Syntax: array-object.forEach(callback-function)
Syntax: array-name.push(element)
Example:
let a=[];
console.log(a.length);
a.push(10);
a.push(20);
a.push(30);
console.log(a.length);
for(let i=0;i<a.length;i++)
console.log(a[i]);
Example:
let a=Array();
for(let i=0;i<5;i++)
{
ele=Number(prompt("Enter any number "));
a.push(ele);
}
console.log(a);
Syntax: array-name[index]=value
Example
let a=[10,20,30,40,50];
console.log(a);
a[0]=100;
a[4]=500;
console.log(a);
a[5]=90;
console.log(a);
let b=[]
console.log(b);
b[0]=100;
console.log(b);
b[0]=200;
console.log(b);
b[1]=300;
console.log(b);
1. pop()
Example:
let a=[10,20,30,40,50];
console.log(a.length);
ele1=a.pop();
console.log(ele1);
console.log(a);
ele2=a.pop();
console.log(ele2);
console.log(a);
2. shift()
This method remove first element from array.
Example:
let a=[10,20,30,40,50];
console.log(a);
e1=a.shift();
console.log(e1);
console.log(a);
3. splice()
This method is used for deleting or removing more than one
element.
Syntax: splice(start,count)
Example:
let a=[10,20,30,40,50];
console.log(a);
e1=a.splice(2,3);
console.log(e1);
console.log(a);
Example:
let a=[10,20,30,40,50];
console.log(typeof a);
let b=a.toString()
console.log(typeof b);
console.log(typeof b[0]);
console.log(typeof a[0]);
Example:
let a=[5,2,8,4,7,1];
console.log(a);
a.sort()
console.log(a);
let b=["java","python","django"]
console.log(b);
b.sort()
console.log(b);
let c=[10,20,"20","30",30,"1"]
console.log(c);
c.sort()
console.log(c);
Functions in JavaScript
What is a function?
A function is self contained block, which contain set of instructions
to perform some operation.
A function is named block
Advantage of functions
1. Reusability : Functions allows to write code once and use
many times
2. Modularity : Dividing instructions according their
operations into small pieces
3. Readability : Easy to understand
4. Efficiency: It allows writing code once and using many time,
this avoid code redundancy.
Writing function
In java script a function is defined or written using “function”
keyword.
Syntax:
function <function-name>([parameters])
{
Statement-1;
Statement2;
}
A function is defined,
1. Without parameters
2. With parameters
3. With return values
4. Without return values
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function sayHello()
{
console.log("JAVASCRIPT");
}
sayHello();
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function add()
{
console.log("ADD Function");
}
function sub()
{
console.log("SUB Function");
}
function multiply()
{
console.log("MULTIPLY function")
}
add();
sub();
multiply()
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function add(a,b)
{
let c=a+b;
console.log(c);
}
add(10,20);
add(1.5,1.6);
add("JS","CSS");
add(10,"JS");
add("JS",16.0);
</script>
</head>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function fun1(a)
{
console.log(a);
}
fun1(100);
console.log(a);
</script>
</head>
<body>
</body>
</html>
Global Variables
Variables declared outside the function are called global
variables.
These variables can be accessible within one or more than one
function.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=100;
function fun1()
{
console.log(a);
}
console.log(a);
fun1();
function fun2()
{
console.log(a);
}
fun2()
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=100; // Global Variable
function fun1()
{
let a=200; // Local Variable
console.log(a);
}
fun1();
console.log(a);
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function fun1(a,b,c)
{
console.log(a);
console.log(b);
console.log(c);
}
fun1();
fun1(10,20,30);
fun1(10,20);
fun1(10);
fun1(10,20,30,40,50);
</script>
</head>
<body>
</body>
</html>
Function with default parameters or parameters with
value
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function fun1(a=null,b=null,c=null)
{
console.log(a);
console.log(b);
console.log(c);
}
fun1();
fun1(10);
fun1(10,20);
fun1(10,20,30);
function fun2(a=0,b=0)
{
console.log(a);
console.log(b);
}
fun2();
fun2(100);
fun2(100,200);
function fun3(a,b=10)
{
console.log(a);
console.log(b);
}
fun3(100);
fun3(100,200);
function fun4(b=10,a)
{
console.log(a);
console.log(b);
}
fun4(100);
fun4(100,200);
</script>
</head>
<body>
</body>
</html>
return keyword
A function receives values, if it is defined with parameters.
A receives values and perform operation and return value to
caller using return keyword.
return keyword
A function receives values, if it is defined with parameters.
A receives values and perform operation and return value to
caller using return keyword.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function add(a,b)
{
let c=a+b;
return c;
}
function fun1()
{
let res=add(10,20);
document.write(res);
}
fun1()
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function fun1()
{
return 10,20,30;
}
let a=fun1()
document.write(a);
</script>
</head>
<body>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function fun1()
{
let a=[10,20,30]
return a;
}
let a=fun1()
document.write(a);
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function add()
{
let s=0;
for(let i=0;i<arguments.length;i++)
s+=arguments[i];
return s;
}
let res=add(10,20,30,40);
document.write(res);
let res1=add(10,20);
document.write(res1);
</script>
</head>
<body>
</body>
</html>
Callback functions
Syntax:
function function-name(received-function)
{
received-function();
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function calculator(a,b,calc)
{
let c=calc(a,b);
return c;
}
function add(a,b)
{
return a+b;
}
function sub(a,b)
{
return a-b;
}
let res1=calculator(10,20,add);
document.write(res1);
let res2=calculator(10,5,sub)
document.write(res2);
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=()=>document.write("Arrow Function<br>");
a();
a()
let b=(a,b)=>a+b;
let res=b(100,200);
document.write(res);
let c=()=>{
document.write("Statement-1<br>");
document.write("Statement-2<br>");
document.write("Statement-3<br>");
};
c();
let d=()=>{
let x=Number(prompt("First Number"));
let y=Number(prompt("Second Number"));
let z=x+y;
return z;
};
let res2=d();
document.write(res2);
</script>
</head>
<body>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
let a=[10,20,30,40,50];
a.forEach((element)=>{
document.write(element+"<br>");
});
let s=0;
a.forEach((element)=>s=s+element);
document.write(s);
</script>
</head>
<body>
</body>
</html>
DOM (Document Object Model)
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<script>
function display()
{
document.write("<h1>Dynamic Content</h1>");
</script>
</head>
<body>
<input type="button" value="display" onclick="display()">
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<input type="button" value="Change" onclick="change()">
<script>
function change()
{
const element=document.getElementById("intro");
element.innerHTML="This is modified content";
const ele1=document.getElementById("demo");
ele1.innerHTML="<h1>This is DEMO </h1>";
}
</script>
</body>
</html>
manipulate HTML elements.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const element = document.getElementById("intro");
document.getElementById("demo").innerHTML =
"The text from the intro paragraph is: " + element.innerHTML;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const element = document.getElementsByTagName("p");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="main">
<p>Finding HTML Elements by Tag Name</p>
<p>This example demonstrates the
<b>getElementsByTagName</b> method.</p>
</div>
<p id="demo"></p>
<script>
const x = document.getElementById("main");
const y = x.getElementsByTagName("p");
document.getElementById("demo").innerHTML =
'The first paragraph (index 0) inside "main" is: ' + y[0].innerHTML;
</script>
</body>
</html>
manipulate HTML elements.
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const element = document.getElementById("intro");
document.getElementById("demo").innerHTML =
"The text from the intro paragraph is: " + element.innerHTML;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const element = document.getElementsByTagName("p");
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="main">
<p>Finding HTML Elements by Tag Name</p>
<p>This example demonstrates the
<b>getElementsByTagName</b> method.</p>
</div>
<p id="demo"></p>
<script>
const x = document.getElementById("main");
const y = x.getElementsByTagName("p");
document.getElementById("demo").innerHTML =
'The first paragraph (index 0) inside "main" is: ' + y[0].innerHTML;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const x = document.getElementsByClassName("intro");
document.getElementById("demo").innerHTML =
'The first paragraph (index 0) with class="intro" is: ' +
x[0].innerHTML;
</script>
</body>
</html>
<p id="demo"></p>
<script>
const x = document.querySelectorAll("p.intro");
document.getElementById("demo").innerHTML =
'The first paragraph (index 0) with class="intro" is: ' +
x[0].innerHTML;
</script>
</body>
</html>
<p id="demo"></p>
<script>
const x = document.forms["frm1"];
let text = "";
for (let i = 0; i < x.length ;i++) {
text += x.elements[i].value + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
<script>
document.getElementById("p1").innerHTML = "New text!";
</script>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<body>
<p id="p1"></p>
<p id="p2"></p>
<p id="p3"></p>
<div id="d1"></div>
<script>
document.getElementById("p1").innerHTML="Paragraph1";
document.getElementById("p2").innerHTML="<h1>Topic1</h1>";
const s1=document.getElementById("p1").innerHTML;
const s2=document.getElementById("p2").innerHTML;
document.getElementById("p3").innerHTML=s1+s2;
document.getElementById("p3").innerHTML="<a
href=http://www.nareshit.com>NareshIt</a>";
document.getElementById("d1").innerHTML="<img
src=images/d.jpg>";
</script>
</body>
</html>
Changing the Value of an Attribute
<!DOCTYPE html>
<html>
<body>
<script>
document.getElementById("image").src = "landscape.jpg";
</script>
</body>
</html>
Example:
<!DOCTYPE html>
<html>
<body>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="container">
<h1>My Webpage</h1>
</div>
<script>
document.getElementById('addElement').addEventListener('click', function() {
newDiv.style.padding = '10px';
newDiv.style.marginTop = '10px';
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
#container {
margin-top: 20px;
padding: 10px;
max-width: 400px;
</style>
</head>
<body>
<div id="container"></div>
<script>
document.getElementById('addBox').addEventListener('click', function() {
constnewBox = document.createElement('div');
// Step 2: Set some styles directly using JavaScript
newBox.style.width = '100%';
newBox.style.height = '100px';
newBox.style.backgroundColor = 'lightblue';
newBox.style.borderRadius = '5px';
newBox.style.marginTop = '10px';
newBox.style.display = 'flex';
newBox.style.alignItems = 'center';
newBox.style.justifyContent = 'center';
newBox.style.fontSize = '20px';
newBox.style.color = '#333';
container.appendChild(newBox);
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
body {
margin: 20px;
#taskList {
margin-top: 20px;
list-style-type: none;
padding: 0;
li {
background: #f0f0f0;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
</style>
</head>
<body>
<ul id="taskList"></ul>
<script>
document.getElementById('addTaskButton').addEventListener('click', function() {
consttaskInput = document.getElementById('taskInput');
consttaskValue = taskInput.value.trim();
// Check if the input is not empty
if (taskValue) {
constnewTask = document.createElement('li');
newTask.textContent = taskValue;
consttaskList = document.getElementById('taskList');
taskList.appendChild(newTask);
taskInput.value = '';
} else {
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task List</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#taskList {
margin-top: 20px;
list-style-type: none;
padding: 0;
}
li {
background: #f0f0f0;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
}
</style>
</head>
<body>
<h1>My Task List</h1>
<input type="text" id="taskInput" placeholder="Enter a new task" />
<button id="addTaskButton">Add Task</button>
<ul id="taskList"></ul>
<script>
const b=document.getElementById("addTaskButton");
b.addEventListener("click",function(){
const intext=document.getElementById("taskInput");
const value=intext.value.trim();
if(value)
{
const listitem=document.createElement("li");
listitem.textContent=value;
const p=document.getElementById("taskList");
p.appendChild(listitem);
}
else
{
alert("Task is empty");
}
});
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task List</title>
<style>
body {
margin: 20px;
#taskList {
margin-top: 20px;
list-style-type: none;
padding: 0;
li {
background: #f0f0f0;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
button.remove {
background-color: red;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
button.remove:hover {
background-color: darkred;
</style>
</head>
<body>
<ul id="taskList"></ul>
<script>
document.getElementById('addTaskButton').addEventListener('click', function() {
consttaskInput = document.getElementById('taskInput');
consttaskValue = taskInput.value.trim();
if (taskValue) {
constnewTask = document.createElement('li');
newTask.textContent = taskValue;
constremoveButton = document.createElement('button');
removeButton.textContent = 'Remove';
removeButton.className = 'remove';
removeButton.addEventListener('click', function() {
newTask.remove();
});
newTask.appendChild(removeButton);
consttaskList = document.getElementById('taskList');
taskList.appendChild(newTask);
// Step 7: Clear the input field
taskInput.value = '';
} else {
});
</script>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task List</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#taskList {
margin-top: 20px;
list-style-type: none;
padding: 0;
}
li {
background: #f0f0f0;
margin: 5px 0;
padding: 10px;
border-radius: 5px;
display: flex;
justify-content: space-between;
align-items: center;
}
button.remove {
background-color: red;
color: white;
border: none;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
}
button.remove:hover {
background-color: darkred;
}
button.update {
background-color:blue;
color: white;
border: none;
border-radius: 5px;
padding: 5px 10px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>My Task List</h1>
<input type="text" id="taskInput" placeholder="Enter a new task" />
<button id="addTaskButton">Add Task</button>
<ul id="taskList"></ul>
<script>
document.getElementById('addTaskButton').addEventListener('click', function() {
// Get the task input value
const taskInput = document.getElementById('taskInput');
const taskValue = taskInput.value.trim();
});
Form Validations
codewithsatishgupta
Form Validations
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function login()
{
var uname=document.frm1.uname.value;
var pwd=document.frm1.pwd.value;
if(uname=='' || pwd=='')
alert("username or password should not be empty");
else
alert("valid input");
}
</script>
</head>
<body>
<form name="frm1">
UserName <input type="text" name="uname"><br>
Password <input type="password" name="pwd"><br>
<input type="button" value="Login" onclick="login()">
</form>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function findfee()
{
var course=document.frm1.course.value;
switch(course)
{
case "python":
document.write("Python Fee 3000 ");
break;
case "java":
document.write("Java Fee 2000");
break;
case "oracle":
document.write("Oracle Fee 1000");
break;
default:
alert("Invalid Course or Course is not selected");
}
}
</script>
</head>
<body>
<form name="frm1">
<h2>Courses</h2>
<input type="radio" name="course" value="java">Java<br>
<input type="radio" name="course" value="python">Python<br>
<input type="radio" name="course" value="oracle">Oracle<br>
<input type="button" value="find fee" onclick="findfee()">
<h2 name="fee"></h2>
</form>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function findfee()
{
var course=document.getElementsByName("course");
for(let i=0;i<course.length;i++)
alert(course[i].value);
}
</script>
</head>
<body>
<form name="frm1">
<h2>Courses</h2>
<input type="checkbox" name="course" value="java">Java<br>
<input type="checkbox" name="course" value="python">Python<br>
<input type="checkbox" name="course" value="oracle">Oracle<br>
<input type="button" value="find fee" onclick="findfee()">
<h2 name="fee"></h2>
</form>
</body>
</html>
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Calculator</title>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="buttons">
<button class="btn" value="7">7</button>
<button class="btn" value="8">8</button>
<button class="btn" value="9">9</button>
<button class="btn operator" value="/">÷</button>
<button class="btn" value="4">4</button>
<button class="btn" value="5">5</button>
<button class="btn" value="6">6</button>
<button class="btn operator" value="*">×</button>
<button class="btn" value="1">1</button>
<button class="btn" value="2">2</button>
<button class="btn" value="3">3</button>
<button class="btn operator" data-value="-">−</button>
<button class="btn" value="0">0</button>
<button class="btn operator" value="+">+</button>
<button class="btn operator" value="C">C</button>
<button class="btn operator" value="=">=</button>
</div>
</div>
<script src="/src/script.js"></script>
</body>
</html>
Styles.css
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.calculator {
max-width: 300px;
margin: auto;
background: white;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
padding: 20px;
}
#display {
width: 100%;
height: 40px;
font-size: 24px;
text-align: right;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
padding: 5px;
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
.btn {
padding: 20px;
font-size: 18px;
background-color: #00796b;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn:hover {
background-color: #004d40;
}
.operator {
background-color: #ff9800;
}
.operator:hover {
background-color: #e68a00;
}
Scripts.js
const display = document.getElementById('display');
const buttons = document.querySelectorAll('.btn');
buttons.forEach(button => {
button.addEventListener('click', () => {
const value = button.value;
function appendToDisplay(value) {
currentInput += value;
display.value = currentInput;
}
function setOperator(value) {
if (currentInput === '') return;
if (firstOperand === null) {
firstOperand = parseFloat(currentInput);
} else {
calculate();
}
operator = value;
currentInput = '';
}
function calculate() {
if (firstOperand === null || currentInput === '' || operator === '') return;
const secondOperand = parseFloat(currentInput);
let result;
switch (operator) {
case '+':
result = firstOperand + secondOperand;
break;
case '-':
result = firstOperand - secondOperand;
break;
case '*':
result = firstOperand * secondOperand;
break;
case '/':
result = firstOperand / secondOperand;
break;
}
display.value = result;
firstOperand = result; // Allow chaining
currentInput = '';
operator = '';
}
function clear() {
currentInput = '';
operator = '';
firstOperand = null;
display.value = '';
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Quiz App</title>
</head>
<body>
<div class="container">
<h1>Quiz App</h1>
<div id="quiz-container">
<div id="question"></div>
<div id="options"></div>
<button id="next-btn">Next</button>
</div>
<div id="result-container" class="hidden">
<h2>Your Score: <span id="score"></span></h2>
<button id="restart-btn">Restart Quiz</button>
</div>
</div>
<script src="/src/script.js"></script>
</body>
</html>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
}
h1 {
margin-bottom: 20px;
}
#options {
margin: 20px 0;
}
button {
padding: 10px 15px;
border: none;
background-color: #007bff;
color: white;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
.hidden {
display: none;
}
const questions = [
{
question: "What is the capital of France?",
options: ["Berlin", "Madrid", "Paris", "Lisbon"],
answer: "Paris"
},
{
question: "Which planet is known as the Red Planet?",
options: ["Earth", "Mars", "Jupiter", "Saturn"],
answer: "Mars"
},
{
question: "What is the largest ocean on Earth?",
options: ["Atlantic Ocean", "Indian Ocean", "Arctic Ocean", "Pacific Ocean"],
answer: "Pacific Ocean"
}
];
let currentQuestionIndex = 0;
let score = 0;
nextButton.addEventListener('click', () => {
const selectedOption = document.querySelector('input[name="option"]:checked');
if (selectedOption) {
const answer = selectedOption.nextElementSibling.textContent;
if (answer === questions[currentQuestionIndex].answer) {
score++;
}
currentQuestionIndex++;
loadQuestion();
}
});
restartButton.addEventListener('click', () => {
currentQuestionIndex = 0;
score = 0;
resultContainer.classList.add('hidden');
document.getElementById('quiz-container').classList.remove('hidden');
loadQuestion();
});
function loadQuestion() {
if (currentQuestionIndex<questions.length) {
const currentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;
optionsElement.innerHTML = '';
currentQuestion.options.forEach(option => {
optionsElement.innerHTML += `
<div>
<input type="radio" name="option" id="${option}" />
<label for="${option}">${option}</label>
</div>
`;
});
} else {
showResult();
}
}
function showResult() {
questionElement.textContent = '';
optionsElement.innerHTML = '';
resultContainer.classList.remove('hidden');
scoreElement.textContent = `${score} out of ${questions.length}`;
}
loadQuestion();
Project-1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>E-Commerce App</title>
</head>
<body>
<header>
<h1>E-Commerce Store</h1>
<div id="cart">
</div>
</header>
<main>
<section id="productList"></section>
<h2>Your Cart</h2>
<ul id="cartItems"></ul>
<button id="checkoutButton">Checkout</button>
</section>
</main>
<script src="script.js"></script>
</body>
</html>
body {
padding: 20px;
background-color: #f8f9fa;
header {
display: flex;
justify-content: space-between;
align-items: center;
background: #343a40;
color: white;
h1 {
margin: 0;
#cart {
font-size: 18px;
main {
margin-top: 20px;
#productList {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.product {
background: white;
border-radius: 5px;
padding: 10px;
width: 200px;
.productimg {
width: 100%;
button {
background: #007bff;
color: white;
border: none;
padding: 10px;
border-radius: 5px;
cursor: pointer;
button:hover {
background: #0056b3;
#cartSection {
margin-top: 20px;
#cartItems {
list-style-type: none;
padding: 0;
const products = [
];
function renderProducts() {
constproductList = document.getElementById('productList');
products.forEach(product => {
constproductDiv = document.createElement('div');
productDiv.className = 'product';
productDiv.innerHTML = `
<imgsrc="${product.img}" alt="${product.name}">
<h3>${product.name}</h3>
<p>Price: $${product.price.toFixed(2)}</p>
`;
productList.appendChild(productDiv);
});
function addToCart(productId) {
document.getElementById('cartCount').textContent = cart.length;
renderCart();
function renderCart() {
constcartSection = document.getElementById('cartSection');
constcartItems = document.getElementById('cartItems');
cartItems.innerHTML = '';
const li = document.createElement('li');
cartItems.appendChild(li);
});
if (cart.length> 0) {
cartSection.style.display = 'block';
} else {
cartSection.style.display = 'none';
document.getElementById('checkoutButton').addEventListener('click', function() {
cart = [];
document.getElementById('cartCount').textContent = '0';
renderCart();
});
renderProducts();
Project-2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="container">
<div class="balance-section">
</div>
<div class="form-section">
<button id="depositButton">Deposit</button>
<button id="withdrawButton">Withdraw</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
body {
background-color: #f4f4f4;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
.container {
background: white;
padding: 20px;
border-radius: 5px;
width: 300px;
h1 {
text-align: center;
.balance-section {
text-align: center;
margin-bottom: 20px;
.form-section {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
}
input {
padding: 10px;
width: 60%;
border-radius: 5px;
button {
padding: 10px;
border: none;
background: #007bff;
color: white;
border-radius: 5px;
cursor: pointer;
button:hover {
background: #0056b3;
.message {
text-align: center;
margin-top: 10px;
color: red;
let balance = 0;
document.getElementById('balance').textContent = balance.toFixed(2);
// Deposit function
function deposit() {
constamountInput = document.getElementById('amountInput');
if (amount > 0) {
balance += amount;
updateBalance();
} else {
amountInput.value = '';
// Withdraw function
function withdraw() {
constamountInput = document.getElementById('amountInput');
balance -= amount;
updateBalance();
amountInput.value = '';
// Display message
constmessageDiv = document.getElementById('message');
messageDiv.textContent = message;
// Event listeners
document.getElementById('depositButton').addEventListener('click', deposit);
document.getElementById('withdrawButton').addEventListener('click', withdraw);
updateBalance();
Project-3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Quiz App</title>
</head>
<body>
<div class="container">
<h1>Quiz App</h1>
<div id="quiz-container">
<div id="question"></div>
<div id="options"></div>
<button id="next-btn">Next</button>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
body {
background-color: #f4f4f4;
margin: 0;
padding: 20px;
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
h1 {
margin-bottom: 20px;
#options {
margin: 20px 0;
button {
border: none;
background-color: #007bff;
color: white;
border-radius: 4px;
cursor: pointer;
margin-top: 10px;
button:hover {
background-color: #0056b3;
.hidden {
display: none;
}
const questions = [
answer: "Paris"
},
answer: "Mars"
},
];
let currentQuestionIndex = 0;
let score = 0;
constquestionElement = document.getElementById('question');
constoptionsElement = document.getElementById('options');
constnextButton = document.getElementById('next-btn');
constresultContainer = document.getElementById('result-container');
constscoreElement = document.getElementById('score');
constrestartButton = document.getElementById('restart-btn');
nextButton.addEventListener('click', () => {
constselectedOption = document.querySelector('input[name="option"]:checked');
if (selectedOption) {
const answer = selectedOption.nextElementSibling.textContent;
score++;
currentQuestionIndex++;
loadQuestion();
});
restartButton.addEventListener('click', () => {
currentQuestionIndex = 0;
score = 0;
resultContainer.classList.add('hidden');
document.getElementById('quiz-container').classList.remove('hidden');
loadQuestion();
});
function loadQuestion() {
if (currentQuestionIndex<questions.length) {
constcurrentQuestion = questions[currentQuestionIndex];
questionElement.textContent = currentQuestion.question;
optionsElement.innerHTML = '';
currentQuestion.options.forEach(option => {
optionsElement.innerHTML += `
<div>
<label for="${option}">${option}</label>
</div>
`;
});
} else {
showResult();
function showResult() {
questionElement.textContent = '';
optionsElement.innerHTML = '';
resultContainer.classList.remove('hidden');
loadQuestion();
Project-4
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<header>
<h1>Your Name</h1>
<nav>
<ul>
<li><a href="#about">About</a></li>
<li><a href="#projects">Projects</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<section id="about">
<h2>About Me</h2>
</section>
<section id="projects">
<h2>Projects</h2>
<div class="project">
<h3>Project Title</h3>
</div>
</section>
<section id="contact">
<h2>Contact Me</h2>
<form id="contact-form">
<button type="submit">Send</button>
</form>
</section>
<footer>
<p>© 2024 Your Name</p>
</footer>
<script src="script.js"></script>
</body>
</html>
body {
margin: 0;
padding: 0;
background-color: #f4f4f4;
header {
background: #333;
color: white;
padding: 10px 0;
text-align: center;
header h1 {
margin: 0;
nav ul {
list-style: none;
padding: 0;
}
nav ul li {
display: inline;
margin: 0 15px;
nav ul li a {
color: white;
text-decoration: none;
section {
padding: 20px;
margin: 10px 0;
background: white;
border-radius: 8px;
h2 {
margin-top: 0;
.project {
margin: 20px 0;
footer {
text-align: center;
padding: 10px 0;
background: #333;
color: white;
position: relative;
bottom: 0;
width: 100%;
form {
display: flex;
flex-direction: column;
input, textarea {
margin: 10px 0;
padding: 10px;
border-radius: 4px;
button {
padding: 10px;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
button:hover {
background-color: #218838;
}
document.getElementById('contact-form').addEventListener('submit', function(e) {
// Here you can add functionality to send this data to your server or an email API
this.reset();
});
Project-5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
</head>
<body>
<div class="calculator">
<div class="buttons">
</div>
</div>
<script src="script.js"></script>
</body>
</html>
body {
background-color: #f4f4f4;
margin: 0;
padding: 20px;
.calculator {
max-width: 300px;
margin: auto;
background: white;
border-radius: 8px;
padding: 20px;
#display {
width: 100%;
height: 40px;
font-size: 24px;
text-align: right;
margin-bottom: 10px;
border-radius: 4px;
padding: 5px;
.buttons {
display: grid;
gap: 10px;
.btn {
padding: 20px;
font-size: 18px;
background-color: #00796b;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.btn:hover {
background-color: #004d40;
.operator {
background-color: #ff9800;
.operator:hover {
background-color: #e68a00;
buttons.forEach(button => {
button.addEventListener('click', () => {
clear();
calculate();
} else {
appendToDisplay(value);
});
});
function appendToDisplay(value) {
currentInput += value;
display.value = currentInput;
function setOperator(value) {
firstOperand = parseFloat(currentInput);
} else {
calculate();
operator = value;
currentInput = '';
function calculate() {
if (firstOperand === null || currentInput === '' || operator === '') return;
constsecondOperand = parseFloat(currentInput);
let result;
switch (operator) {
case '+':
case '-':
break;
case '*':
break;
case '/':
break;
display.value = result;
currentInput = '';
operator = '';
function clear() {
currentInput = '';
operator = '';
firstOperand = null;
display.value = '';