UNIT-1
UNIT-1
UNIT-1
0 7
Web Essentials: Clients, Servers and Communication – The Internet – World wide web –
HTTP Request Message – HTTP Response Message – Web Clients – Web Servers –
HTML5 – Tables – Lists – Image – HTML5 control elements – Drag and Drop – Audio –
Video controls - CSS3 – Inline, embedded and external style sheets – Rule cascading –
Inheritance – Backgrounds – Border Images – Colors – Shadows – Text – Transformations
– Transitions – Animations. Bootstrap Framework
Server:
The software that distributes the information and the machine where the
information and software reside is called the server.
provides requested service to client
e.g., Web server sends requested Web page
Client:
The software that resides on the remote machine, communicates with the
server, fetches the information, processes it, and then displays it on the
remote machine is called the client.
initiates contact with server (speaks first)
typically requests service from server
Web client is implemented in browser
Web server: Software that delivers Web pages and other documents to
browsers using the HTTP protocol.
Website: A collection of pages on the World Wide Web those are accessible
from the same URL and typically residing on the same server.
1
URL: Uniform Resource Locator, the unique address which identifies
aresource on the Internet for routing purposes.
CLIENT-SERVER PARADIGM
The Client-Server paradigm is the most prevalent model for distributed
computing protocols. It is the basis of all distributed computing paradigms at a
higher level of abstraction.
It is service-oriented, and employs a request-response protocol.
2
TYPES OF CLIENT-SERVER ARCHITECTURE
4
this, providing that the tiers are logically separated can be hosted
(e.g. development and testing) on the same computer.
Advantages:
Ease in Developing Applications:
User Satisfaction:
Applicable for Homogeneous Environment:
High Performance:
Limitations:
The two tier architecture proved to be a good solution when user population
work is usually small (up to about 100 concurrent users) but it rapidly proved to
have a number of limitations:
Performance: Performance begins to deteriorate as the population
grows.
Security: Each user must have their own individual access to the
database, and be granted whatever rights may be required in order to
run the application.
Capability: Independent of the type of client, much of the data
processing has to be located in database making it totally dependent
upon the capabilities and implementation provided by the database
manufacturer.
Portability: As the two-tier architecture is dependent upon the specific
database implementation, porting an existing application to a different
DBMS becomes a major issue.
1) Three-Tier Architecture
In the three-tier architecture the functional process logic, data access,
computer data storage and user interface are developed and maintained
as independent modules on separate platform.
(i) Presentation Tier: Occupies the top level and displays information related
to service available on a website. This tier communicates with other tiers by
sending results to the browser and other tiers in the network.
5
(ii) Application Tier: Also called the middle tier, logic tier or business logic, this tier
is pulled from the presentation tier. It controls application functionality by
performing detailed processing.
(iii) Data Tier: Houses database server where information is stored and
retrieved. Data in this tier is kept independent of application servers or business
logic.
Advantages:
Improved Data Integrity
Enhanced Security
Hidden Database Structure
Limitations:
Complexity of Communication: Usually more efforts should be ensured
when creating 3-tier applications as the communication points are
increased (client to middle tier to server) and the performance increased
by tools like Visual Basics, Power Builder etc.
2) N-Tier Architecture
N Tier Architecture often referred as Multitier Architecture. It is
client-server architecture in which presentation, application
processing, and data management functions are physically separated.
it is an expanded form of three-tierarchitecture.
6
Advantages:
It provides a model by which developers can create flexible and reusable
applications. By segregating an application into tiers, developer acquires
the option of modifying or adding a specific layer, instead of reworking
the application.
Limitations:
Difficult to Implement: Due to componentization of tiers, the
complex structure is difficult to implement or maintain.
INTERNET:
The Internet is a massive network of networks that connects
millions of computers together globally. It forms a network in which any
computer can communicate with any other computer with the help of
TCP/IP protocol as long as they are both connected to the Internet.
IP ADDRESSING:
Each host on a TCP/IP network is assigned a unique 32 bit logical
address and it is called as Internet Protocol Address (IP Address). IP
address is used to identify a particular host on the internet.
FIREWALLS:
The hardware and software that sits between the internet and the local
network, checking all the data that comes in and out to make sure that it is
legitimate is called a Firewall.
The most basic firewall is a packet filter that inspects each packet coming in
or out of a network and uses a set of rules to determine whether that traffic is
allowed.
PROXY SERVERS:
A proxy server is computer that functions as an intermediary between a web
browser (such as Internet Explorer) and the Internet. Proxy servers help improve web
performance by storing a copy of frequently used webpages. When a browser requests
a webpage stored in the proxy server's collection (its cache), it is provided by the
proxy server, which is faster than going to the web. Proxy servers also help improve
security by filtering out some web content and malicious software.
GATEWAYS:
Gateway is a machine used to route packets form one network to
another network. In internet gateways provide all interconnections
between physical networks.
Gateways have two responsibilities:
1. Route packets based on network id to a gateway connected to that
network.
2. If they are connected to destination network, make sure that the packet
gets delivered to correct machine on that network.
u1 u2 u3 tec
cse ece it
Uniquely traced with the help of domain name space (http://www.cse.tec.ac.in)
9
HOW INTERNET WORKS?
The internet is a world-wide network of computers linked together by
telephone wires, satellite links and other means.
All computers on the internet can be divided into two categories: servers
and browsers.
Servers are where most of the information on the internet "lives". These are
specialized computers which store information, share information with other
servers, and make this information availableto the general public.
Browsers are what people use to access the World Wide Web from any
standard computer. Chances are, the browser you’re using to view this page is
either Netscape Navigator/Communicator or Microsoft Internet Explorer.
These are by far the most popular browsers, but there are also a number of
others in common use.
When you connect your computer to the internet, you are connecting to a
special type of server which is provided and operated by your Internet
Service Provider (ISP). The job of this "ISP Server" is to provide the link
between your browser and the rest of the internet. A single ISP server
handles the internet connections ofmany individual browsers - there may
be thousands of other people connected to the same server that you are
connected to right now.
The following picture shows a small "slice" of the internet with several home
computers connected to a server:
10
To view a web page from your browser, the following sequence happens:
1. You either type an address (URL) into your "Address Bar" or click on a
hyperlink.
2. Your browser sends a request to your ISP server asking for the page.
3. Your ISP server looks in a huge database of internet addresses and finds the
exact host server which houses the website in question, then sends that
host server a request for the page.
4. The host server sends the requested page to your ISP server.
5. Your ISP sends the page to your browser and you see it displayed on your
screen.
11
BASIC INTERNET PROTOCOLS
Definition: Protocol
A protocol can be defined as the set of rules
governing the syntax, semantics and
synchronization of communication between
two end points.
Some common protocols used in Internet
Communications:
12
ends must establish a connection between each other.
Reliable Service – It uses the acknowledgement mechanism to ensure the safe
and sound arrival of data.
TCP Segment Format:
Header Data
The unit of data transfer between two devices using TCP is called as
Segment. The segment consists of 20 to 60 byte header followed by data from
the application program.
2. User Datagram Protocol (UDP):
13
UCP is convenient protocol for multimedia and multicasting applications.
UDP Header Format:
UDP packets, called user datagram, have a fixed size headerof 8 bytes.
Source Port Number: 16 bit port number used by the running process on the
source host.
Destination Port Number: 16 bit port number used by the process running
on the destination host.
Length: 16 bit field that defines the total length of the user datagram [header
+ data].
Checksum: This field is used to detect errors over the entire user datagram
[header+data]. This ensures that the fields have not changed from the source to
destination.
Applications:
14
DIFFERENCE BETWEEN TCP AND UDP:
TCP UDP
User Datagram Protocol
Transmission Control
Acronym for or Universal Datagram
Protocol
Protocol
TCP is a connection- UDP is a connectionless
Connection
oriented protocol. protocol.
UDP is suitable for
applications that need
TCP is suited for fast, efficient
applications that transmission, such as
Usage require high reliability, games. UDP's stateless
and transmission time nature is also useful for
is relatively less critical. servers that answer
small queries from huge
numbers of clients.
UDP has no order as all
packets are independent
TCP rearranges data
Ordering of data of each other. If
packets in the order
packets ordering is required, it
specified.
has to be managed by
the application layer.
The speed for TCP is UDP is faster because
Speed of transfer there is no error-
slower than UDP.
checking for packets.
15
TCP header size is 20 UDP Header size is 8
Header Size
bytes bytes.
Source port,
Common Header Source port, Destination
Destination port, Check
Fields port, Check Sum
Sum
TCP is heavy-weight.
TCP requires three UDP is lightweight.
packets to set up a There is no ordering of
socket connection, messages, no tracking
Weight
before any user data connections, etc. It is a
can be sent. TCP small transport layer
handles reliability and designed on top of IP.
Congestion control.
TCP does Flow Control.
TCP requires three
packets to set up a
socket connection, UDP does not have an
Data Flow Control
before any user data option for flow control
can be sent. TCP
handles reliability and
congestion control.
UDP does error
Error Checking TCP does error checking checking, but no
recovery options.
Acknowledgement
Acknowledgement No Acknowledgment
segments
No handshake
Handshake SYN, SYN-ACK, ACK (connectionless
protocol)
16
3. Internet Protocol(IP):
The Internet Protocol (IP) is the principal communications protocol in the
Internet protocol suite for relaying datagrams across network boundaries.
Its routing function enables internetworking, and essentially establishes
the Internet.
IP is the host-to-host network layer protocol for the internet.
IP is connection less and unreliable protocol. It is connection less in the
sense that no state related to IP datagrams is maintained either on
source or destination side
It is unreliable in the sense that it not guaranteed that an IP data gram
will get delivered to the destination or not.
If an IP datagram encounters some error at the destination or at some
intermediate host (while traveling from source to destination) then the IP
datagram is generally discarded and anICMP error message is sent back to
the source.
If reliability is important, it must be paired with a reliable protocol such
as TCP.
IP Header Format:
Protocol Version(4 bits) : This is the first field in the protocol header.
This field occupies 4 bits. This signifies the current IP protocol version being
used.
Header Length(4 bits) : This field provides the length of the IP header. The
length of the header is represented in 32 bit words.
17
Uses of IP Protocol:
Addressing
While sending datagrams, an addressing mechanism is needed to send the
datagrams accurately. In order to achieve this, IP uses a technique for host
addressing. The addressing of devices (to which the datagrams are delivered)
needs to be unique as this system needs to work across networks.
Routing
When a datagram is sent from one network to another, which aredistant and not
directly connected, the delivery is indirect. IPsupports this functionality
by routing the datagram through intermediate devices
(routers). It uses Internet Control MessageProtocol (ICMP) and routing protocols
like Routing Information Protocol (RIP) and Border Gateway Protocol (BGP) to
achieve this. DATA Encapsulation
IP provides security to networks by encapsulating the data into an IP
datagram. This makes sure it is received and interpreted by the intended
recipient.
Formatting/Packaging
IP uses a specific formatting and packaging prior to transmission. IP
accepts data from the transport layer protocols above it in the OSI layer --
UDP and TCP--and passes them to the data layers. This format and package
is only decipherable by the recipient.
Fragmentation
Since the frame size of each physical and data link network usingIP may be
different, IP fragments datagrams into pieces, so that they can each be
carried on the local network. This helps with network reliability.
Reassembly
IP reassembles the datagrams received into the full IP datagram (as they may
be fragmented) for the receiving device and passes it on to the higher layers
for interpretation.
18
FTP data is sent and received through computer port 21 and under the
TCP protocol.
The transfer is asynchronous, meaning not at the same time and
therefore faster than other protocols.
19
Standard port for HTTP to listen on is 80.
GET and POST are the two popular methods used by the HTTP protocol to
make requests to the server on WWW.
20
8. Internet Message Access Protocol:
The Internet Message Access Protocol (IMAP) is a mail protocol usedfor
accessing email on a remote web server from a local client.
IMAP and POP3 are the two most commonly used Internet mailprotocols
for retrieving emails.
IMAP allows the client program to manipulate the e-mail messageson
the server without downloading them on the local computer.
IMAP enables the user to search the e-mails.
This does not involve in transfer of mails. It allows users to access the
received mails.
It enables us to take any action such as download, delete the mail without
reading it.
Both protocols are supported by all modern email clients and web servers.
While the POP3 protocol assumes that your email is being accessed only
from one application, IMAP allows simultaneous access by multiple
clients. This is why IMAP is more suitable for you if you're going to access
your email from different locations or if your messages are managed by
multiple users.
Port 143 - this is the default IMAP port
Internet WWW
Internet is a massive WWW is a way of accessing
Definition network of networks, a information over the
networking infrastructure medium of the internet
It connects millions of
computers together
globally forming a network
It is an information sharing
in which any computer can
Purpose model that is built on the
communicate with any
top of internet.
other computer as long as
both are connected to
internet
Name of the
ARPANET NSFnet
first version
Network of computers,
Files, folders & documents
Comprises copper wires, fiber-optic
stored in various computers
cables 7 wireless networks
Governed Hyper Text Transfer
Internet Protocol
by Protocol
This is the base, It depends on internet to
Dependency
independent of the WWW work
Created by Tim Berners Lee
Creator No such creator
in 1992.
Nature Hardware Software
22
1.4 HTTP: Hyper Text Transfer Protocol
Start line
23
Header Field(s)
Blank line
Optionally, a message body
25
2. HTTP Response Message:
HTTP Response sent by a server to the client.The
response is used to provide the client with the
resource it requested.
It is also used to inform the client that the action
requested has been carried out.
It can also inform the client that an error
occurred in processing its request.
An HTTP response contains the following things:
(Structure of the response)
– status line
– header field(s)
– blank line
– optional Message body
Status Line
The Start line is generally split into three space-separated parts;
– HTTP version
– status code
– reason phrase (intended for human use)
1. HTTP Version: HTTP 1.0 / HTTP 1.1
2. Status Code:
o Status code is a three-digit number that indicates the result ofthe
request.
o First digit is class of the status code:
1=Informational
2=Success
3=Redirection (alternate URL is supplied)
4=Client Error
5=Server Error
o Other two digits provide additional information
3. Reason Phrase:
It is also known as the status text. It is a human-readable text that
summarizes the meaning of the status code.
An example of the response line is as follows:
HTTP/1.1 200 OK
Here,
o HTTP/1.1 is the HTTP version.
o 200 is the status code.
o OK is the reason phrase.
26
Some Commonly Encountered HTTP Response Status Codes
301 - Moved Permanently The resource has permanently moved to a different URI.
404 - Not Found The requested resource does not exist on the server.
408 - Request Timeout The client failed to send a request in the time allowed by
the server.
27
Example: HTTP Response Message
WEB SERVER:
A Web Server is basically a computer that is designed to
accept requests from remote computers and send on the
information requested over the internet. It is also used to host
website / web application.
28
Examples:
Apache
o Source: The Apache Software Foundation
o Operating System: Unix, Windows NT
o Current Version: 2.2.6
Internet Information Server
o Source: Microsoft
o Operating System: Windows Server 2003
o Current Version: 6.0
Sun Java System Web Server
o Source: Sun Microsystems
o Operating System: Solaris, Windows Server 2003,
2000, XP, Linux, HP-UX
o Current Version: 7.0
WEB CLIENT:
A Web client is the browser on the PC/Mac that makes the
requests to the remote server. It is an application (e.g.
Internet Explorer, Firefox, Chrome, Safari, and Opera) running on a local
device (desktop, notebook, cell phone) used to interact mainly with Web
servers. A PC/Mac that uses a web (Client) browser is referred to as a Client
Machine.
The primary function of a web client is to serve content.
A user agent, commonly a web browser or web crawler, initiates
communication by making a request for a specific resource using HTTP
and the server responds with the content of that resource or an error
message if unable to do so.
Functions of a Web Browser:
1. Reformat the URL and send a valid HTTP request.
2. When user gives the address of particular web site, the web browser
converts the DNS to corresponding ip address.
3. The web browser establishes a TCP connection with the web server while
processing the user’s request.
4. The web browser sends the HTTP request to the web server.
5. The web browser displays the response page returned by the server in
appropriate format on the client machine.
29
Examples:
Firefox
o Source: Mozilla Corporation
o Operating System: Mac OS X, Microsoft Windows, Linux
o Current Version:2.0.0.9
Internet Explorer
o Source: Microsoft
o Operating System: Windows, Vista
o Current Version: 7.0
Netscape
o Source: Netscape Corporation
o Operating System: Mac OS X, Microsoft Windows, Linux
o Current Version: 9.0.0.3
Opera
o Source: Opera Software
o Operating System: Microsoft Windows, Solaris, SolarisIntel, Sparc,
ONX, OS/2,
o MacOS, Linux sparc, Linux Power PC, Linux i386, Fress BSD i386, BeOS
o Current Version: 9.24
Safari
o Source: Apple Inc.
o Operating System: Mac OS X, Microsoft Windows, Linux
o Current Version: 3.0.4 (Beta version)
30
WEB PAGE:
A web page or webpage is a document commonly written in HyperText Markup
Language (HTML) that is accessible through the Internet or other network using a
browser. A web page is accessed by entering a URL address and may contain text,
graphics, and hyperlinks to other web pages and files.
31
WEB SITE:
A Web Site is a set of interconnected webpages on WWW that
includes a beginning file called homepage.
Web sites are accessed by using URLs provided by the authority of
the web site.
Web sites are generally located on the same server, and prepared
and maintained as a collection of information by a person, group, or
organization.
Example: http://www.w3schools.com
DIFFERENCE BETWEEN WEB SERVER AND WEB SITE:
WEB APPLICATION:
A web application or web app is any computer program that runs in a
web browser. It is created in a browser-supported programming language
(such as the combination of JavaScript, HTML and CSS) and relies on a
web browser to render the application.
It is usable only with an active Internet connection
It uses HTTP as its primary communications protocol.
Examples: Online ticket booking applications, Online games, google
docs, etc.,
32
1.6: HTML 5.0
Advantages of HTML:
1. It is plain text so is easy to edit.
2. It is also fast to download.
3. Is very easy to pick up\learn .
4. It is now a standard.
5. It is supported by most browsers.
6. Simple to edit only requires a text editor.
7. Can be easily edited with WYSIWYG editors (no coding required) .
8. Can be used to present just about any kind of data.
9. Tags can be used very loosely (i.e. used to be able to omit end tags
etc).
10. It is user friendly.
11. It is open technology.
Disadvantages of HTML:
1. It can create only static and plain pages so if we need dynamic
pages then HTML is not useful.
2. It is static needs to be manually updated or needs some
scripting support to change it in some way.
3. Need to write lot of code for making simple webpage.
4. Security features are not good in HTML.
5. If we need to write long code for making a webpage then it
produces some complexity.
33
BASIC STRUCTURE OF AN HTML DOCUMENT:
<!DOCTYPE html>
<html>
<head>
<title> title of the page </title> Head Section
</head>
<body>
Page design goes here Body Section
</body>
<html>
Common Declarations
HTML 4.01:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
XHTML 1.0:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
34
<html> tag: Every HTML document starts with <html> tag.
This tells browsers that it is the beginning of HTML
document. This tag does not have any properties.
</html> tag: This tag informs browsers that the end of the
HTML document has been reached.
An HTML page has basically two distinct logical sections:
1. Head Section
2. Body Section
1. Head Section:
- Head section contains the meta-information about the HTML
page.
- This section is processed but not displayed on the screen.
- Head section may contain the following inside it:
<title> tag – used to assign title to the web page which
appears on the title bar of the browser’s window.
JavaScript codes for creating dynamic web pages.
Cascading Style Sheets codes for styling the document.
2. Body Section:
The body section contains text and other tags which are
rendered on the screen.
HTML CONSTRUCTS:
There are two main constructs in HTML:
1. Elements (also called tags)
2. Entities.
1. Elements:
HTML tags are keywords (tag names) surrounded by angle
brackets. HTML element or tag is a signal to the browser that it
should do something other than just throwing text on the screen. Tags
are descriptions that are embedded directly into the informational text
of the document.
Syntax: <tagname>content</tagname>
35
The end tag is written like the start tag, but with a slash before the
tag name
2. Attributes:
HTML elements can have attributes
Attributes provide additional information about an element
Attributes are always specified in the start tag
Attributes come in name/value pairs like: name="value"
Syntax:
<tagname attributename=‖value‖>content</tagname>
Example: <applet width=‖100‖ height=‖100‖>
3. Entities:
Entities are character sequences that reproduce special
characters on the browser screen.
Reserved characters in HTML must be replaced with characterentities
(references).
If you use the less than (<) or greater than (>) signs in your text,the
browser might mix them with tags.
Character entities are used to display reserved characters inHTML.
A character entity looks like this:
&entity_name; OR &#entity_number;
3. <base> tag:
Type: Standalone tag
Function: Specifies the base URL of the document.
Syntax:
<base href=‖base-url‖> (or) <base target=‖frame_name‖>
Target – specifies the default frame name to which all the linked
documents should be loaded.
Related Tags: None.
4. <link> tag:
Type: Standalone tag
Function: Makes a link between an external source and this html
file.
Syntax: <link href=‖url-of-the-linked-file‖
title=‖title‖ rel=‖forward-relationaship‖ rev=‖reverse-
relationship‖>
Attributes:
Href – denotes the URL of the file to be linked.
Title – gives the link a descriptive title.
38
Example:
<head>
<link href=‖styles.css‖ rel=‖stylesheet‖>
</head>
5. <script> tag: Type:
container tag
Function: Contains script code such as JavaScript or VBScript
referenced in the body section of the document.
Syntax: <script language=‖scripting-language‖>
----- Script code ----
</script>
Attributes:
language – Scripting language used to write the script.
src – Specifies the URL of a file containing the script code, if
the code is not written between <script> and </script> tags.
type – MIME type of the script code.
Example:
<head>
<script src=‖external.js‖ type=‖text/javascript‖></script>
</head>
Example:
<body bgcolor=‖yellow‖ >
<body bgcolor=‖#0000FF‖ >
<body background=‖flower1.jpg‖>
40
FORMATING TAGS:
1. <b> tag:
Type: Container tag
Function: Makes the enclosed text bold.
Syntax: <b> text </b>
Attributes: None
Example:
<b> Welcome </b>
2. <i> tag:
Type: Container tag
Function: Makes the enclosed text italic.
Syntax: <i> text </i>
Attributes: None
Example:
<i> Welcome </i>
3. <u> tag:
Type: Container tag
Function: Makes the enclosed text underlined.
Syntax: <u> text </u>
Attributes: None
Example:
<u> Welcome </u>
4. <big> tag:
Type: Container tag
Function: Renders the text in the font size bigger than the default
font size.
Syntax: <big> text </big>
Attributes: None
Example: <big> Welcome </big>
5. <small> tag:
Type: Container tag
Function: Renders the text in the font size smaller than the
default font size.
Syntax: <small> text </small>
Attributes: None
Example:<small> Welcome </small>
41
6. <s> / <strike> tag:
Type: Container tag
Function: contains the text to be marked with strikethrough
character.
Syntax: <s> text </s> (or) <strike> text </strike>
Attributes: None
Example:
<s> Welcome </s> (or) <strike> welcome </strike>
7. <sub> tag:
Type: Container tag
Function: contains the text to be subscript to the text that
precedes it.
Syntax: <sub> text </sub>
Attributes: None
Example:
a<sub>1</sub>, a<sub>2</sub>
8. <sup> tag:
Type: Container tag
Function: contains the text to be super script to the text that precedes it.
Syntax: <sup> text </sup>
Attributes: None
Example:
a<sup>1</sup>, a<sup>2</sup>
9. <font> tag:
Type: Container tag
Function: contains the text whose font properties are to be
modified.
Syntax: <font size=‖size‖ color=‖color‖ face=‖font-face-type‖>
text </font>
Example:
<font face=‖Calibri‖ size=‖25pt‖ color=‖green‖> Welcome
</font>
10. <br> tag:
Type: Empty tag
Function: Inserts a line break in the document.
Syntax: <br/>
Example:<font face=‖Calibri‖ size=‖25pt‖color=‖green‖> Welcome
</font> <br/>
42
11. <center> tag:
Type: Container tag
Function: Centers all the text and other page components.
Syntax: <center> text </center>
Example:
<center> <font face=‖Calibri‖ size=‖25pt‖ color=‖green‖>
Welcome </font> </center>
44
Output:
This text is normal.
Output:
Heading 1
Heading 2
Heading 3
1. <p> tag:
Type: Container tag
Function: denotes a paragraph.
Syntax: <p align=‖ LEFT | RIGHT | CENTER‖> paragraph text
</p>
Attributes:
Align – LEFT | RIGHT | CENTER. Controls the alignment of
the text in the paragraph.
Example:
<p align=‖center‖ title=‖Greetings‖> Welcome</p>
47
Attributes:
Cols – specifies the maximum number of characters that fit ina line.
WRAP – turns on wrapping, so that all lines fit inside thebrowser.
Example:
<!DOCTYPE html>
<html>
<body>
<p>
Welcome
To
HTML
</p>
<pre>
Welcome
To
HTML
</pre>
</body>
</html>
Output:
Welcome To HTML
Welcome
To
HTML
18. <span> tag:
Type: Container tag
Function: Generic tag for defining document block. Used for
applying style information.
Syntax:
<span style=‖style-information‖ align=‖LEFT|RIGHT|CENTER‖>
Text
</span>
Example:
<span style=‖font-weight:bold; color:red;>
Welcome
To
HTML
</span>
48
Output:
Welcome to HTML
Tables are used for presenting data in tabular form i.e. to organizedata into
rows and columns.
The fundamental building blocks of a table are cells, which can
contain either a data element or a heading for a column of data.
Columns and rows will automatically size to contain their data.
Individual table cells can span multiple rows or columns.
Header and footer rows can be supplied.
HTML Table Tags:
Tag Name Meaning Tag Name Meaning
table Represents start of a tbody Defines the table
table body
caption Describes the table tr Represents a table
content row
thead Defines the header th Represents a column
section header
tfoot Defines the footer td Defines data in the
section cell
49
Attributes of Table Tag
Attribute Meaning
Align Specifies table alignment. An have values: left,
right, and center
Border Specifies the thickness of the table border in
number of pixels
Background Specifies the URL of the background image
Bordercolor Specifies the color of the table border. color
names or hexadecimal color codes are allowed
Bgcolor Specifies the background color of the table. color
names or hexadecimal color codes are allowed
Height Specifies the height of the table in pixels
Width Specifies the width of the table in pixels
Cols Specifies the number of columns to be created in
the table
Cellpadding Specifies the amount of space in number of
pixels between the cell border and its content
Cellspacing Specifies the amount of space in number of
pixels between table cells.
frame Specifies whether a frame around the table
should be created or not
50
th, tr and td elements:
1. <th> Element:
<th> (table heading) element is used to define columns in thehead
section of a table.
Most browsers center the text formatted by th element anddisplay
them in bold.
2. <tr> Element:
Each <tr> (table row) element defines an individual table row.
Synatx:
<tr align=‖LEFT|RIGHT|CENTER‖ bordercolor=‖color‖
bgcolor=‖color‖ height=‖pixels‖ width=‖pixels or %‖
valign=”TOP|BOTTOM|MIDDLE‖ >
------
</tr>
Attributes of tr tag:
Attribute Meaning
Align Specifies the horizontal alignment of the content of
all cells in this row. Can have values: left, right and
center. Default value is left.
Bordercolor Specifies the border color of all cells in this row. color
names or hexadecimal color codes are allowed
Bgcolor Specifies the background color of all cells in this row.
color names or hexadecimal color codes are allowed
Height Specifies height, in pixels, of all cells in this row
Width Specifies width, in pixels, of all cells in this row
valign Specifies the vertical alignment of the content of all
cells in this row. Can have values: top, bottom and
middle. Default value is middle.
51
3. <td> Element:
Attribute Meaning
Align Specifies the horizontal alignment of the content of
all cells in this row. Can have values: left, right and
center. Default value is left.
Bordercolor Specifies the border color of all cells in this row. color
names or hexadecimal color codes are allowed
Bgcolor Specifies the background color of all cells in this row.
color names or hexadecimal color codes are allowed
Height Specifies height, in pixels, of all cells in this row
Width Specifies width, in pixels, of all cells in this row
valign Specifies the vertical alignment of the content of all
cells in this row. Can have values: top, bottom and
middle. Default value is middle.
Colspan Specifies the number of columns this cell must span
rowspan Specifies the number of rows this cell must span
52
Example:
<!DOCTYPE html>
<html>
<head>
<title>Simple Table Demo</title>
</head>
<body>
<table border="1" width="20%">
<caption><strong>Price of Fruits</strong></caption>
<thead>
<tr>
<th>Fruit</th>
<th>Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<th>$3.75</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Orange</td>
<td>$0.50</td>
</tr>
<tr>
<td>Banana</td>
<td>$1.00</td>
</tr>
<tr>
<td>pineapple</td>
<td>$2.00</td>
</tr>
<tr>
<td>Apple</td>
53
<td>$0.25</td>
</tr>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Simple Table Demo</title>
</head>
<body>
<table border="1" width="20%">
<caption><strong>Price of Fruits</strong></caption>
<thead>
<tr>
<th>Fruit</th>
<th>Price</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Total</th>
<th>$3.75</th>
</tr>
</tfoot>
<tbody>
<tr>
<td>Orange</td>
<td>$0.50</td>
</tr>
<tr>
<td>Banana</td>
<td>$1.00</td>
</tr>
<tr>
<td>pineapple</td>
<td>$2.00</td>
</tr>
<tr>
<td>Apple</td>
54
<td>$0.25</td>
</tr>
</tbody>
</table>
</body>
</html>
Year Subjects
Name
Branch TOC IP
Rowspan Colspan
<td rowspan=‖2‖>Name</td>
<td colspan=‖2‖>Subjects</td>
<td>Year</td><td>Branch</td>
<td>TOC</td><td>IP</td>
Example:
<html>
<head>
<title>Complex Table</title>
</head>
<body>
<table border="1" bgcolor="#FF9900">
<caption> Comparison of districts in Tamil nadu</caption>
<thead>
<tr>
<th rowspan="2"><img src="tamil-nadu-map.jpg" width="150"
height="150"></th>
<th colspan="3"><h1> District comparison in Tamil
nadu</h1></th>
</tr>
<tr>
<th>District</th>
<th>Population</th>
55
<th>Growth</th>
</tr>
</thead>
<tbody align="center">
<tr>
<th>1</th>
<td>Chennai</td>
<td>464673</td>
<td>6.98 %</td>
</tr>
<tr>
<th>2</th>
<td>Coimbatore</td>
<td>3458045</td>
<td>18.56 %</td>
</tr>
<tr>
<th>3</th>
<td>Madurai</td>
<td>3038252</td>
<td>17.84 %</td>
</tr>
</tbody>
</table>
</body>
</html>
56
1.7: HTML IMAGES (<IMG> TAG)
<img> tag is used to insert an image in the document.
The <img> tag is empty, it contains attributes only, and does
not have a closing tag
Syntax:
<img src=‖image_url‖ width=‖pixels‖ height=‖pixels‖
alt=‖text_description‖
border=‖thickness_in_pixels‖
align=‖TOP|MIDDLE|LEFT|RIGHT|BOTTOM
hspace=‖horizontal_space‖ vspace=‖vertical_space
usemap=‖map_name />
Where,
Src= Specifies the URL (web address) of the image.
Alt= specifies an alternate text for an image, if the image cannot be
displayed. If a browser cannot find
an image, it will display the alt text.
Width & Height = Optional attributes used to specify the image’s
width & height. If these attributes are omitted, the browser uses the
image’s actual width and height. Images are measured as pixels.
Border= used to specify the width of the border to display around
the image.
Hspace & vspace= controls the amount of white space left around
the image.
Usemap= used to point to an image-map. Image-map is an image
with clickable areas.
57
</cetner>
</body>
</html>
58
Target – target frame into which the linked document should be
loaded.
INTERNAL LINKING:
Internal linking is a mechanism that enables the user to jump
between locations in the same document.
Internal linking is useful for long documents that contain many
sections.
59
Clicking an internal linking enables users to find a section
without scrolling through the entire document.
Syntax:
1. To create hyperlink: Use ―id‖ attribute in any tag to create this
section as linked section.
<any-tag id=”anchor_name”> content </any-tag>
60
3
4
5
6
7
8
9
10
</pre>
</font>
<center><a href="#top"> Go Up</a></center>
<hr color="orange">
<h1><a name="upper"><font color="yellow">UPPERCASE
ALPHABETS</font></a>
</h1>
<font size=5pt>
<pre>
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
61
U
V
W
X
Y
Z
</pre>
</font>
<center><a href="#top"> Go Up</a></center>
<hr color="orange">
<h1><a name="lower">
<font color="yellow">LOWERCASE ALPHABETS</font></a></h1>
<font size=5pt>
<pre>
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
62
x
y
z
</pre>
</font>
<center><a href="#top"> Go Up</a></center>
<hr color="orange">
</body>
</html>
Bullet Options:
Bullet Options Meaning Result
<ul> Default bullet shape is disc One
Two
<ul type=‖disc‖> Disc shaped bullets are used One
Two
<ul type=‖circle‖> Circle shaped bullets are used o One
63
o Two
<ul Square shaped bullets are used One
type=‖square‖> Two
2. Ordered Lists:
Numbering Options:
Numbering Numbering
Meaning Result Meaning Result
options options
Use
Use default
1. One <ol lowercase a. One
<ol> number
2. Two type=‖a‖> letters for b. Two
type
numbering
Use
Use default <ol lowercase
<ol 1. One d. One
number type=‖a‖ letters
type=‖1‖> 2. Two e. Two
type start=‖4‖> stating
from d
Use
Use small
<ol uppercase A. One <ol i. One
roman
type=‖A‖> letter for B. Two type=‖i‖> ii. Two
numbers
numbering
<ol Use default 3. One <ol type=‖i‖ Use small ii. One
type=‖3‖> number 4. Two start=‖2‖> roman iii. Two
64
starting numbers
form 3 starting
from ii
Use
Use
<ol uppercase
D. One <ol capital I. One
type=‖A‖ letters
E. Two type=‖I‖> roman II. Two
start=‖4‖> starting
numbers
from D
3. Definition List:
A definition list is the one where list items consist of two parts:
o a term
o its description
Definition List is created using <dl> tag.
The term part and the definition part of each item are created
using <dt> (definition term) and <dd> (definition description)
tags respectively.
Example:
<dl>
<dt> dl tag </dt>
<dd> it is the outermost tag of definition list</dd>
<dt> dt tag </dt>
<dd> Contains the item to be described</dd>
<dt> dd tag </dt>
<dd> Contains description of the item</dd>
<dd> Each term may have multiple descriptions</dd>
</dl>
dl tag
it is the outermost tag of definition
list
dt tag
Contains the item to be described
dd tag
Contains description of the item
Each term may have multiple
descriptions
65
NESTED LISTS:
Lists may be nested to represent hierarchical relationships.
A web browser indents each nested list to indicate a hierarchical
relationship.
Any of the three types of lists may be nested in another.
Arbitrary levels of nesting is possible
<!DOCTYPE html>
<html>
<head>
<title> List Example</title>
</head>
<body bgcolor="violet">
<center>
<h1> ABC ENGINEERING COLLEGE</h1>
</center>
<hr color="blue">
<ul>
<li> U.G Courses
<ol>
<li> B.E - CSE </li> Inner List
<li> B.E - ECE </li>
</ol>
</li>
<li> P.G Courses
<ol>
Outer List
<li> M.E - CSE </li>
<li> M.E - SE </li>
<li> MBA </li> Inner List
<li> MCA </li>
</ol>
</li>
</ul>
<hr color="red">
66
<ul type="square">
<li>
<dl>
<dt> CSE </dt>
<dd> Computer Science and Engineering</dd>
</dl>
</li>
<li>
<dl>
<dt> ECE</dt>
<dd> Electronics and Communication
Engineering</dd>
</dl>
</li>
<li>
<dl>
<dt> SE </dt>
<dd> Software Engineering</dd>
</dl>
</li>
</ul>
</body>
</html>
Output:
67
1.10: HTML 5 CONTROL ELEMENTS
HTML Forms
<form> ELEMENT:
The <form> element is used to create a form.
Syntax:
<form name=‖form_name‖ accept=‖MIME _type‖
action=‖URL_of_the_Script‖
Method=‖GET|POST‖ target=‖frame_name‖ >
- Form elements --
</form>
Attributes:
Attribute Description
accept- Specifies the charset used in the submitted form (default:
charset the page charset).
Specifies an address (url) where to submit the form
action
(default: the submitting page).
Specifies if the browser should autocomplete the form
autocomplete
(default: on).
Specifies the encoding of the submitted data (default: is
enctype
url-encoded).
68
Specifies the HTTP method used when submitting the
method
form (default: GET).
Specifies a name used to identify the form (for DOM
name
usage: document.forms.name).
novalidate Specifies that the browser should not validate the form.
Specifies the target of the address in the action attribute
target
(default: _self).
Example:
<form name=‖form1‖ method=‖get‖
action="action_page.php">
----- form elements ----
</form>
<input> ELEMENT:
The <input> element is the most important form element.
The <input> element has many variations, depending on the type
attribute.
<html>
<body>
<form action="">
User name:<br>
<input type="text" name="userid">
<br>
User password:<br>
<input type="password" name="psw">
</form>
<p>The characters in a password field are masked (shown as
asterisks or circles).</p>
</body>
</html>
TEXTAREA ELEMENT:
This control allows the user to enter multiple lines of data.
It is generated on the web page using <textarea> and </textarea>
tag pair.
Size of the textarea is specified usingthe two attributes rows and
cols.
72
Syntax: <textarea name=”text1” rows=”5” cols=”60”>
Please enter the text here
</textarea>
SELECT ELEMENT:
A menu is defined using ―select‖ element. It defines the drop-down
list.
It is used to produce scrollable option menus.
Syntax:
<select name=”Name” [size=”size”] [MULTIPLE] >
<option value=”value” [selected] > Option1
</option>
<option value=”value” [selected] > Option2
</option>
</select>
Option element is used to define the options to select.
[selected] attribute is used to specify which option should be
selected by default (predefined option).
Example:
<form action="action_page.php">
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<br><br>
<input type="submit">
</form>
<label> Gender:
<input type="radio" name="gender" />Male
<input type="radio" name="gender" />Female </label><br />
<label> D.O.B: <input type="date" name="bday" /> </label>
<br />
<label> Qualification:
<select>
<option value="be">B.E</option>
<option value="ba">B.A</option>
<option value="bcom">B.COM</option>
<option value="bba">B.B.A</option>
</select></label>
<br />
<label> Hobbies:
<input type="checkbox" name="c1" />Playing
<input type="checkbox" name="c2" />Singing
<input type="checkbox" name="c3" />Dancing </label> <br />
80
<label> Describe about Yourself:
<textarea> </textarea> </label><br /> <br/>
<input type="submit" value="Submit Data" />
</form>
</center>
</body>
</html>
Output
81
HTML5 FORM ELEMENTS
HTML5 added the following form elements:
<datalist>
<keygen>
<output>
1. <datalist> Element:
The <datalist> element specifies a list of pre-defined options for an
<input> element.
Users will see a drop-down list of pre-defined options as they input
data.
The list attribute of the <input> element, must refer to the id
attribute of the <datalist> element.
Example
An <input> element with pre-defined values in a <datalist>:
<form action="action_page.php">
<input list="browsers">
<datalist id="browsers">
<option value="Internet
Explorer">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
</form>
2. <keygen> Element:
The purpose of the <keygen> element is to provide a secure way to
authenticate users.
The <keygen> element specifies a key-pair generator field in a form.
When the form is submitted, two keys are generated, one private
and one public.
The private key is stored locally, and the public key is sent to the
server.
The public key could be used to generate a client certificate to
authenticate the user in the future.
Example:
<form action="action_page.php">
Username:
<br>
<input type="text" name="user">
<br><br>
Encryption:
<br>
<keygen name="security">
<br><br>
<input type="submit"> </form>
3. <output> Element:
The <output> element represents the result of a calculation (like
one performed by a script).
Example:
<form action="action_page.asp"
oninput="x.value=parseInt(a.value)+parseInt(b.value)">
0
<input type="range" id="a" name="a" value="50">
100 +
<input type="number" id="b" name="b" value="50">
=
<output name="x" for="a b"></output>
<br><br>
<input type="submit">
</form>
HTML5 INPUT TYPES
HTML5 added several new input types:
color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week
Input Restrictions:
Here is a list of some common input restrictions (some are new in
HTML5):
Attribute Description
disabled Specifies that an input field should be disabled
max Specifies the maximum value for an input field
Specifies the maximum number of character for an input
maxlength
field
min Specifies the minimum value for an input field
Specifies a regular expression to check the input value
pattern
against
Specifies that an input field is read only (cannot be
readonly
changed)
required Specifies that an input field is required (must be filled out)
size Specifies the width (in characters) of an input field
step Specifies the legal number intervals for an input field
value Specifies the default value for an input field
Example:
<form>
Quantity:
<input type="number" name="points" min="0" max="100" step="10"
value="30">
</form>
<details> Defines additional details that the user can view or hide
<html>
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<header role="banner">
<h1>HTML5 Document Structure Example</h1>
<p>This page should be tried in safari, chrome or Mozila.</p>
</header>
<nav>
<ul>
<li><a href="http://www.tutorialspoint.com/html">HTML
Tutorial</a></li>
<li><a href="http://www.tutorialspoint.com/css">CSS
Tutorial</a></li>
<li><a
href="http://www.tutorialspoint.com/javascript">JavaScript
Tutorial</a></li>
</ul>
</nav>
<article>
<section>
<p>Once article can have multiple sections</p>
</section>
</article>
<aside>
<p>This is aside part of the web page</p>
</aside>
<footer>
<p>Created by <a href="http://tutorialspoint.com/">Tutorials
Point</a></p>
</footer>
</body>
</html>
Dragover
This event is fired as the mouse is moved over an element when a
3
drag is occurring. Much of the time, the operation that occurs
during a listener will be the same as the dragenter event.
Dragleave
This event is fired when the mouse leaves an element while a drag
4
is occurring. Listeners should remove any highlighting or insertion
markers used for drop feedback.
Drag
5 Fires every time the mouse is moved while the object is being
dragged.
Drop
The drop event is fired on the element where the drop was
6 occurred at the end of the drag operation. A listener would be
responsible for retrieving the data being dragged and inserting it at
the drop location.
Dragend
7 Fires when the user releases the mouse button while dragging an
object.
The DataTransfer Object
The event listener methods for all the drag and drop events
accept Event object which has a readonly attribute
called dataTransfer.
The event.dataTransfer returns DataTransfer object associated with
the event as follows −
function EnterHandler(event) {
DataTransfer dt = event.dataTransfer;
.............
}
The DataTransfer object holds data about the drag and drop
operation. This data can be retrieved and set in terms of various
attributes associated with DataTransfer object as explained below –
S.No DataTransfer attributes and their description
1 dataTransfer.dropEffect [ = value ]
Returns the kind of operation that is currently selected.
This attribute can be set, to change the selected operation.
The possible values are none, copy, link, and move.
2 dataTransfer.effectAllowed [ = value
Returns the kinds of operations that are to be allowed.
This attribute can be set, to change the allowed operations.
The possible values are none, copy, copyLink, copyMove, link, linkMove,
move, all and uninitialized.
3 dataTransfer.types
Returns a DOMStringList listing the formats that were set in the
dragstart event. In addition, if any files are being dragged, then one of
the types will be the string "Files".
4 dataTransfer.clearData ( [ format ] )
Removes the data of the specified formats. Removes all data if the
argument is omitted.
5 dataTransfer.setData(format, data)
Adds the specified data.
6 data = dataTransfer.getData(format)
Returns the specified data. If there is no such data, returns the empty
string.
7 dataTransfer.files
Returns a FileList of the files being dragged, if any.
The example below is a simple drag and drop example:
<!DOCTYPE HTML>
<html>
<head>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
</body>
</html>
Do the Drop - ondrop
When the dragged data is dropped, a drop event occurs.
In the example above, the ondrop attribute calls a function,
drop(event):
function drop(ev)
{
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
Code explained:
Call preventDefault() to prevent the browser default handling of the
data (default is open as link on drop)
Get the dragged data with the dataTransfer.getData() method. This
method will return any data that was set to the same type in the
setData() method
The dragged data is the id of the dragged element ("drag1")
Append the dragged element into the drop element
<audio> element:
The HTML5 <audio> element specifies a standard way to embed audio in
a web page. To play an audio file in HTML, use the <audio> element:
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
The controls attribute adds audio controls, like play, pause, and
volume.
Text between the <audio> and </audio> tags will display in
browsers that do not support the <audio> element.
Multiple <source> elements can link to different audio files. The
browser will use the first recognized format.
<video> element:
The HTML5 <video> element specifies a standard way to embed a video in
a web page. To show a video in HTML, use the <video> element:
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
</body>
</html>
The controls attribute adds video controls, like play, pause, and
volume.
It is a good idea to always include width and height attributes.
If height and width are not set, the browser does not know the size
of the video. The effect will be that the page will change (or flicker)
while the video loads.
Text between the <video> and </video> tags will only display in
browsers that do not support the <video> element.
Multiple <source> elements can link to different video files. The
browser will use the first recognized format.
Definition:
Cascading Style Sheet (CSS) is a W3C technology that allows document
authors to specify the presentation of elements on a web page (e.g fonts, spacing,
colors) separately from the structure of the document (section headers, body, links).
This separation ofstructure from presentation simplifies maintaining and modifying
a web page.
1. CSS allows separation between the information contained in the document and its
presentation. Hence any change in the presentation can be made without disturbing
the information of the document.
2. Style Sheets allow users to decide the style of presentation. This presentation style
can be defined in a separate file. Thus the presentation can be made persistent.
3. CSS allows the developer to give the consistent appearance to all the elements of
the web page.
4. CSS allows us to improve the consistent look and feel of a web site.
5. CSS provides precise control over font size, color, background color and so on.
CSS CORE SYNTAX:
A CSS style sheet consists of one or more style rules (called statements). The collection
of all such rules is called Ruleset.
Each ruleset consists of two parts: 1. Selector string 2. Declaration block
Declaration Block contains a list of declarations separated by semicolon (;)
Selector String indicates the elements to which the rule should apply and each declaration
within the declaration block specifies a value for one style property of those elements.
Syntax:
<style type=”text/css”>
</style>
TYPES OF SELECTOR STRING:
1. Type Selector:
It is the simplest form of selector string which consists of the name of a single element.
A rule can also apply to multiple elements types separating the elements by using comma (,)
Example:
h1, p {background-color:purple}
2. Universal Selector:
It is denoted by an asterisk (*).
A rule denoted by universal selector can be applied for every possible element in the
document.
Example:
* {background-color:purple; font-weight:bold}
3. Id Selector:
A selector preceded by a number sign (#) is called an ID selector.
It represents an id value rather than an element type name.
A rule defined by the ID selector can be applied to the element that matches with the id
attribute value with the ID selector string.
Example:
<style type=”text/css”>
#myid {background-color:green}
</style>
<p id=”myid”>
This is an ID selector
</p>
4. Class Selector:
A selector preceded by a period or dot (.) is called an Class selector.
It represents a generic value rather than an element type name.
A rule defined by the class selector can be applied to the element that matches with the class
attribute value with the Class selector string.
Example:
<style type=”text/css”>
.myclass {background-color:red}
</style>
<p class=”myclass”>
This is an class selector
</p>
Note: Class selectors can also be prefixed by an element name which restricts the selector
toelements of the specified type.
5. Pseudo classes:
Using pseudo-classes we can specify special effects on the selectors.
There are some pseudo classes which are more commonly used and those are:
Focus
Hover
hyperlink
General form of pseudo class and pseudo element:
Selector:pseudo-class { declaration
This rule will first read the rules form the specified file “filename.css” before continuing
with the other rule in the style sheet.
@import rule must appear at the beginning of the style sheet before any ruleset statements
and it must end with semicolon (;).
Links.css
a:hover {font-size:200%}
a:active {color:yellow}
a:visited {color:green}
mystyle.css
@import url("links.css");
li { font-size: 14pt; line-height: 25pt }
* { font-family: verdana }
.unorder { background-color:yellow }
#order { background-color:violet }
dl dd {color:blue}
lists.html
<!DOCTYPE html>
<html>
<head>
<title> List Example</title>
</head>
<link href="mystyle.css" rel="stylesheet" type="text/css">
<body >
<center>
<h1 color="green"> ABC ENGINEERING COLLEGE</h1>
</center>
<hr color="blue">
<ul id="order">
<li> U.G Courses
<ol class="unorder">
<li> B.E - CSE </li>
<li> B.E - ECE </li>
</ol>
</li>
<li> P.G Courses
<ol class="unorder">
<li> M.E - CSE </li>
<li> M.E - SE </li>
<li> MBA </li>
<li> MCA </li>
</ol>
</li>
</ul>
<hr color="red">
<ul type="square">
<li>
<dl>
<dt> <a href="">CSE </a></dt>
<dl>
</dl>
</li>
</dl>
<li> </li>
<dl> </ul>
</body>
</html>
</dl>
</li>
<li> <dd> Software Engineering</dd>
1.15: TYPES OF STYLE SHEETS
To add CSS styles to our website, we can use three different ways to insert the CSS.
Different types of style sheets:
1. Internal / Embedded Stylesheet
2. External Stylesheet
3. Inline Stylesheet
</head>
Example:
Style1.css
.heading
{
font-family: Arial, Helvetica, sans-serif;
background-color:violet;
color:blue;
}
Style_types.html
<!DOCTYPE html>
<html>
<head>
<title>Types of Style Sheets</title>
<style type="text/css">
h1 { font-weight:bold; font-size:12px; color:red }
</style>
<link href="style1.css" type="text/css" rel="stylesheet">
</head>
<body bgcolor="pink">
<center>
<h2>TYPES OF STYLE SHEETS</h2>
<hr>
<p style="background-color:yellow;text-decoration:underline">
This is Inline Style Sheet
</p>
<hr>
<h1> This is Embedded / Internal Style Sheet</h1>
<hr>
<h1 class="heading">This is External Style Sheet</h1>
<hr>
</center>
</body>
</html>
Output:
1.16: Conflicting Styles: Rule cascading and Style Inheritance
RULE CASCADING:
Consider the following declarations:
* { font-weight: bold } – this rule applies to every element of te HTML document.
#p1, #p3 { background-color:aqua } - both the rules are applied to to an element with id
attribute value p3 and p1.
If multiple rules apply to an element and these rules provide declarations for different properties,
then all of the declarations are applied to the element.
What will happen if multiple declarations that all apply to a single property of a single
element are available?
In order to choose between multiple declarations, the browser applies Rule Cascading. It
is a multi-stage sorting process that selects a single declaration that will supply the property
value.
Mypage.html
<html>
<head>
<style type=”text/css”>
P {color:red }
</style>
<link rel=”stylesheet” type=”text/css” href=”style1.css”>
<style type=”text/css”>
P {color: yellow}
</style>
</head>
In the above example, we find multiple declarations for the same property that all apply to the
same element.
Apply Rule Cascading to choose the declaration. Since all the declarations are having same
weight-origin and specificity, the style rule sets are ordered as follows,
p {color:red }
p {color:blue }
p {color:green }
p {color: yellow} This declaration is selected and the text will be
displayed in yellow color.
STYLE INHERITANCE:
Rule Cascading is based on the structure of the style sheets.
Inheritance is based on the tree structure of the document.
If a value for a style option has not been specified for an element, the element will inherit
the style property form its parent.
If the parent element does not specify the style rule, it inherits from the grand parent and
so on up to the top-level element (either <html> tag or the element with style property).
Inherited style can be overridden by declaring specific style to the child.
Example:
CSS background properties are used to define the background effects of an element.
Example:
<!DOCTYPE html>
<html>
<head>
<title>CSS Backgound</title>
<style type="text/css">
p{
background-color:#99FF99;
background-attachment:fixed;
background-image:url(flower2.jpg);
background-position:right;
background-repeat:repeat-y;
height:200px }
div {
background:#FFFF99 url(flower1.jpg) center repeat-x scroll;
height:150px;
}
</style>
</head>
<body>
<center> <h1> CSS Backgorund Property</h1>
<p> This paragraph contains a beatiful background image. </p>
<div>ABCD EFG.... HIJK LMNOP... QRSTUVW .... UVW XYZ.</div>
</center>
</body>
</html>
1.18: CSS Borders and Border Images
CSS BORDER PROPERTIES:
The CSS border properties allow you to specify the style, size, and color of an element's
border.
The top, right, bottom, and left margin can be changed independently using separate
properties.
Border Style: The border-style property specifies what kind of border to display.
Border-style values:
none: Defines no border
dotted: Defines a dotted border
dashed: Defines a dashed border
solid: Defines a solid border
double: Defines two borders. The width of the two borders are the same as the border-
width value
groove: Defines a 3D grooved border. The effect depends on the border-color value
ridge: Defines a 3D ridged border. The effect depends on the border-color value
inset: Defines a 3D inset border. The effect depends on the border-color value
outset: Defines a 3D outset border. The effect depends on the border-color value
Border Width: The border-width property is used to set the width of the border.
The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or thick.
Border Color:
The border-color property is used to set the color of the border. The color can be set by:
name - specify a color name, like "red"
RGB - specify a RGB value, like "rgb(255,0,0)"
Hex - specify a hex value, like "#ff0000"
border-style: dotted;
o all four borders are dotted
Example:
p{
border: 5px solid red;
}
<!DOCTYPE html>
<html>
<head>
<style>
p.normal {
border: 2px solid red;
}
p.round1 {
border: 2px solid red;
border-radius: 5px;
}
p.round2 {
border: 2px solid red;
border-radius: 8px;
}
p.round3 {
border: 2px solid red;
border-radius: 12px;
}
</style>
</head>
<body>
Tip: The border-image property is actually a shorthand property for the following
properties:
o border-image-source,
o border-image-slice,
o border-image-width,
o border-image-outset and
o border-image-repeat
border-image-outset Specifies the amount by which the border image area extends
beyond the border box
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#borderimg1 {
border: 10px solid transparent;
padding: 15px;
border-image: url(grid.png) 20% repeat;
background-color:yellow
}
#borderimg2 {
border: 50px solid transparent;
padding: 15px;
border-image: url(rose.jpg) 20% repeat;
color:blue;
font-size:25px
}
#borderimg3 {
border: 10px solid transparent;
padding: 15px;
border-image: url(rose.jpg) 30% round;
}
</style>
</head>
<body>
</body>
</html>
1.19: CSS Colors
Colors are specified using predefined color names, or RGB, HEX, HSL, RGBA, HSLA values.
2) HEX Colors
A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and
BB (blue) hexadecimal integers specify the components of the color.
HEX Value
In CSS, a color can be specified using a hexadecimal value in the form:
#rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff
(same as decimal 0-255).
For example, #ff0000 is displayed as red, because red is set to its highest value (ff) and
the others are set to the lowest value (00).
3) HSL Colors
HSL stands for hue, saturation, and lightness.
HSL Value
In CSS, a color can be specified using hue, saturation, and lightness (HSL) in the form:
hsl(hue, saturation, lightness)
Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color.
Lightness is also a percentage, 0% is black, 50% is neither light or dark, 100% is white
Saturation
Saturation can be described as the intensity of a color.
100% is pure color, no shades of gray
50% is 50% gray, but you can still see the color.
0% is completely gray, you can no longer see the color.
Lightness
The lightness of a color can be described as how much light you want to give the color,
where 0% means no light (black), 50% means 50% light (neither dark nor light) 100%
means full lightness (white).
With CSS you can add shadow to text and to elements with the help of the following properties:
1. text-shadow
2. box-shadow
1. Text Shadow
The CSS text-shadow property applies shadow to text.
In its simplest use, you only specify the horizontal shadow (2px) and the
vertical shadow (2px).
Multiple Shadows
To add more than one shadow to the text, you can add a comma-separated list of
shadows.
The following example shows a red and blue neon glow shadow:
2. box-shadow
The CSS box-shadow property applies shadow to elements.
In its simplest use, you only specify the horizontal shadow and the vertical
shadow.
1.21: CSS Text and Font Properties
Example:
<!DOCTYPE html>
<html>
<head>
<title> CSS Text Properties</title>
<style type="text/css">
p.test1 {
color:green;
text-align:center;
text-decoration:underline;
text-indent::10pt;
text-shadow:red;
text-transform:capitalize;
direction:rtl;
letter-spacing:5px;
}
</style>
</head>
<body>
<center><h1>CSS Text Properties</h1></center>
<p class="test1">abcd efgh ijkl mnop qrst uvw xyz</p>
</body>
</html>
Text Overflow:
The CSS3 text-overflow property specifies how overflowed content that is not displayed
should be signaled to the user.
Word Wrapping:
The CSS3 word-wrap property allows long words to be able to be broken and wrap onto
the next line. If a word is too long to fit within an area, it expands outside.
Word Breaking:
The CSS3 word-break property specifies line breaking rules.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
width: 140px;
border: 1px solid #ff00ff;
word-break: keep-all;
p.test2 {
width: 140px;
border: 1px solid #00ff00;
word-break: break-all;
p.test3 {
white-space:nowrap;
width: 140px;
border: 1px solid #0000ff;
overflow:hidden;
text-overflow:clip;
}
p.test4 {
width: 140px;
border: 1px solid #f0f0f0;
word-wrap:break-word;
}
</style>
</head>
<body>
</body>
</html>
generic family - a group of font families with a similar look (like "Serif" or
"Monospace")
font family - a specific font family (like "Times New Roman" or "Arial")
Example:
<html>
<head>
<title>CSS Font Properties</title>
<style type="text/css">
p{
font-size:50px;
font-variant:small-caps;
font-family:Arial;
font-weight:bold;
font-style:italic;
color:green;
}
In the CSS3 @font-face rule you must first define a name for the font (e.g. myFirstFont),
and then point to the font file.
To use the font for an HTML element, refer to the name of the font (myFirstFont)
through the font-family property:
Example:
@font-face {
font-family: myFirstFont;
src: url(sansation_light.woff);
}
div {
font-family: myFirstFont;
}
<div>
This is an example for web fonts
</div>
CSS3 supports transform property. This transform property facilitates you to translate, rotate,
scale, and skews elements.
Transformation is an effect that is used to change shape, size and position.
There are two type of transformation i.e. 2D and 3D transformation supported in CSS3.
transform-origin Allows you to change the position on transformed elements. It allows you
to specify the location origin of the transform. By default, the origin is in
the center of the element.
For example, if you are using the transform: rotate property but want it to
CSS 2D Transforms
The CSS 2D transforms are used to re-change the structure of the element
as translate, rotate, scale and skew etc.
Function Description
translate(x,y) Defines a 2D translation, moving the element along the X- and the Y-
axis
<!DOCTYPE html>
<html>
<head>
<style>
.square {
background: darkturquoise;
border-radius: 5px;
height: 100px;
margin: 100px;
width: 100px;
}
.square:hover {
transform: scale(2);
}
</style>
</head>
<body>
<div class="square">
</div>
</body>
</html>
2. rotate
With the rotate value, the element rotates clockwise or counterclockwise
by a specified number of degrees.
A positive value, such as 90deg, rotates the element clockwise, while a
negative value, such as -90deg, rotates it counterclockwise.
You can rotate more than a full rotation with numbers over than 360, such as
1080deg, for three full rotations.
<!DOCTYPE html>
<html>
<head>
<style>
.square {
background: red;
transition: all 3s;
height: 100px;
margin: 100px;
width: 100px;
}
.square:hover{
transform: rotate(180deg);
}
</style>
</head>
<body>
<div class="square">
</div>
</body>
</html>
3. Translate
The translate value moves an element left/right and up/down. The
movement is based on the parameters given for the X (horizontal) Y
(vertical) axes.
A positive X value moves the element to the right, while a negative X moves
the element to the left. A positive Y value moves the element downwards and a
negative Y value, upwards.
In this example, the element will move 20 pixels to the right and 20 pixels
down.
<!DOCTYPE html>
<html>
<head>
<style>
.square2 {
background: #FA54DE;
transition: 2s;
height: 100px;
margin: 100px;
width: 100px;
position:absolute;
.square2:hover{
transform: translate(100px,100px);
}
</style>
</head>
<body>
<div class="square2">
</div>
</body>
</html>
4. Skew
With the skew value, the element skews (or tilts) one direction or the other
based on the values given for the X and Y axes.
A positive X value tilts the element left, while a negative X value tilts it right.
A positive Y value tilts the element down, and a negative Y value tilts is up. Or
use a shorthand to include both X and Y properties:
div {
transform: skewX(25deg);
transform: skewY(10deg);
transform: skew(25deg, 10deg);
}
div {
transition: transform 1s;
}
div:hover {
transform: skewX(-20px);
}
5. Matrix
The matrix() method combines all the 2D transform methods into one.
The matrix() method take six parameters, containing mathematic functions,
which allows you to rotate, scale, move (translate), and skew elements.
The parameters are as follow:
matrix(scaleX(),skewY(),skewX(),scaleY(),translateX(),translateY())
Example
div {
transform: matrix(1,2,3,4,5,6);
}
CSS 3D Transforms
Transform Properties
The following table lists all the 3D transform properties:
Property Description
backface-visibility Defines whether or not an element should be visible when not facing the
screen
3D Transform Methods
Function Description
translateX(x) Defines a 3D translation, using only the value for the X-axis
translateY(y) Defines a 3D translation, using only the value for the Y-axis
translateZ(z) Defines a 3D translation, using only the value for the Z-axis
CSS transitions allows you to change property values smoothly, over a given duration.
Transition properties:
transition
transition-delay
transition-duration
transition-property
transition-timing-function
transition- transition-timing-function:
timing- linear|ease|ease-in|ease-out|ease-
Specifies the speed curve of the
function in-out|step-start|step-
transition effect
end|steps(int,start|end)|cubic-
bezier(n,n,n,n)|initial|inherit;
How to Use CSS Transitions?
To create a transition effect, you must specify two things:
Note: If the duration part is not specified, the transition will have no effect, because the default
value is 0.
The following example shows a 100px * 100px red <div> element. The <div> element has also
specified a transition effect for the width property, with duration of 2 seconds:
Example
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
The transition effect will start when the specified CSS property (width) changes value.
Now, let us specify a new value for the width property when a user mouses over the <div>
element:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
}
</style>
</head>
<body>
<h1>The transition Property</h1>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
Notice that when the cursor mouses out of the element, it will gradually change
back to its original style.
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
<p>Hover over the div elements below, to see the different speed curves:</p>
<div id="div1">linear</div><br>
<div id="div2">ease</div><br>
<div id="div3">ease-in</div><br>
<div id="div4">ease-out</div><br>
<div id="div5">ease-in-out</div><br>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier
versions.</p>
</body>
</html>
The transition-delay property specifies a delay (in seconds) for the transition effect.
The following example has a 1 second delay before starting:
Example
div {
transition-delay: 1s;
}
Transition + Transformation
Example
div {
transition: width 2s, height 2s, transform 2s;
}
The CSS transition properties can be specified one by one, like this:
Example
div {
transition-property: width;
transition-duration: 2s;
transition-timing-function: linear;
transition-delay: 1s;
}
Example
div {
transition: width 2s linear 1s;
}
CSS animations make it possible to animate transitions from one CSS style configuration to
another.
There are three key advantages to CSS animations over traditional script-driven animation
techniques:
They’re easy to use for simple animations; you can create them without even having to
know JavaScript.
The animations run well, even under moderate system load. Simple animations can often
perform poorly in JavaScript. The rendering engine can use frame-skipping and other
techniques to keep the performance as smooth as possible.
Letting the browser control the animation sequence lets the browser optimize
performance and efficiency by, for example, reducing the update frequency of animations
running in tabs that aren't currently visible.
To create a CSS animation sequence, you style the element you want to animate with the
animation property or its sub-properties.
This lets you configure the timing, duration, and other details of how the animation
sequence should progress.
This does not configure the actual appearance of the animation, which is done using the
@keyframes at-rule as described in Defining the animation sequence using keyframes
below.
1. animation-name
2. animation-duration
3. animation-timing-function
4. animation-delay
5. animation-iteration-count
6. animation-direction
7. animation-fill-mode
8. animation-play-state
animation- animation-iteration-count:
Specifies how many times an animation
iteration- number|infinite|initial|inherit;
should be played
count
animation- animation-direction:
Specifies whether or not the animation
direction normal|reverse|alternate|alternate-
should play in reverse on alternate cycles
reverse|initial|inherit;
Once you’ve configured the animation’s timing, you need to define the appearance of the
animation. This is done by establishing two or more keyframes using the @keyframes
at-rule.
o Each keyframe describes how the animated element should render at a given time
during the animation sequence.
Since the timing of the animation is defined in the CSS style that configures the
animation, keyframes use a <percentage> to indicate the time during the animation
sequence at which they take place.
o 0% indicates the first moment of the animation sequence, while 100% indicates
the final state of the animation.
Because these two times are so important, they have special aliases: from and to. Both are
optional.
o If from/0% or to/100% is not specified, the browser starts or finishes the
animation using the computed values of all attributes.
You can optionally include additional keyframes that describe intermediate steps between
the start and end of the animation.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-iteration-count:infinite;
}
@keyframes example {
0% {background-color:red; left:0px; top:0px;}
25% {background-color:yellow; left:200px; top:0px;}
50% {background-color:blue; left:200px; top:200px;}
75% {background-color:green; left:0px; top:200px;}
100% {background-color:red; left:0px; top:0px;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>
*********************