Wad 3 Units PDF
Wad 3 Units PDF
Wad 3 Units PDF
ARPANET switched from using an earlier protocol to TCP/IP during 1982 for
allowing computers on outside networks such as CSNET to communicate via
TCP/IP with computers on the ARPANET.
A “connection” from CSNET to the ARPA Internet often meant that a modem
connection was made from one computer to another for the purpose of
sending an e-mail messages asynchronouly.
At first, many institutions connected through the so-called PhoneNet
(modem) approach for passing e-mail messages. This generally involved
long distance calls, and the expense of these calls could be a problem. Other
options, such as leasing telephone lines for dedicated use, could be even
more expensive.
Beginning in 1985, the NSF began work on a new network based on TCP/IP,
called NSFNET. One of the primary goals of this network was to connect the
NSF’s new regional supercomputing centers. So that the NSFNET would
provide a backbone through which other networks could interconnect
synchronously.
There are six supercomputer centers across America connected by the early
NSFNET backbone. Regional networks connecting to the backbone included
o SURAnet
o NYSERNet
o JvNCnet
o SDSCnet
1.2.1 TCP/IP
It is a set of networking protocols that allows two or more computers to
communicate with each others.TCP and IP are actually two different
protocols, but often treated as one because most of the services in the
Internet such as e-mail, Web browsing, file downloads, accessing remote
databases—are built on top of both the TCP and IP protocols.
Internet Protocol(IP):
A key element of IP is the IP address, which is a 32-bit number. Each device
on the Internet has one or more IP addresses associated with it
IP addresses are normally written as a sequence of four decimal numbers
separated by periods (called “dots”), as in 192.0.34.166. Each decimal
number represents one byte of the IP address.
The function of IP software is to transfer data from one computer (the
source) to another computer (the destination). When an application on the
source computer wants to send information to a destination, the application
calls IP software on the source machine and provides it with data to be
transferred along with an IP address of both source and destination
computers.
The IP software running on the source split the message into one or more
packets with sequence numbers and attach header information such as
IP address of source and destination machines, .length of data, and so
on. Then transfer those packets along path from the source and destination
machines.
If the destination computer is on the same local network as the source, then
the IP software will send the packet to the destination directly via this network
If the destination is on another network, the IP software will send the packet
to a gateway, which is a device that is connected to the source computer’s
network as well as to at least one other network.
The gateway pass the packets to the destination computer, if both gateway
and destination machines in the same network,. Otherwise gateway will pass
the packet to the next gateway it is directly connected. This process will
continue until the packet reaches the destination computer.
IP software on that destination computer will receive the packet and pass its
data up to an application that is waiting for the data.
The sequence of computers that a packet travels through from source to
destination is known as its route. A separate protocol (BGP-4, the Border
Gateway Protocol) is used to pass network connectivity information between
gateways so that each can choose a best next hop for each packet it
receives.
IP software also adds some error detection information (a checksum) to
each packet it creates, so that if a packet is corrupted during transmission,
this can usually be detected by the recipient and discard any corrupted
packets and ask the source machine to resend the corrupted packet
Thus, IP-based communication is unreliable: packets can be lost. Obviously,
IP alone is not a particularly good form of communication for many Internet
applications
For example, a machine connected to the Internet may run a mail server for
users on its local network, a file download server, and also a server that
allows users to log in to the machine and execute commands from remote
locations. As illustrated in the following Figure:
Figur
IN the above figure , a mail server conforming with SMTP will typically ask
TCP to listen for requests to port 25. If at a later time an IP message is
received by the machine running the mail server
server application and that IP
message contains a TCP message with port 25 indicated in its header, then
the data contained within the TCP message will be returned to the mail server
application. Such an IP message could be generated by a mail client calling
onn TCP software on another system(he
system right side of the figure).
TCP and IP provide many other functions, such as splitting long messages
into shorter ones for transport over the Internet
Interne and reassembling them
on the receiving side.
The top-level domain names are assigned by the Internet Corporation for
Assigned Names and Numbers (ICANN), a private nonprofit organization
that was originally funded by the U.S. government.
Each top-level domain is divided into subdomains (second-level domains),
which may in turn be further divided, and so on.
The owner of a second-level domain can then further divide that domain
into subdomains, and so on. Ultimately, the subdomains of a domain are
individual computers. Such a subdomain, consisting of a local host name
Some tools are available that allow you to query the Internet DNS.
D For
example, the nslookup command can be typed at a command prompt in
order to find the IP address given a fully qualified domain name or vice
versa.
Typical usage of nslookup is illustrated by the following (user input is
italicized):
C:¥>nslookup
nslookup www.example.org
Server: slave9.dns.stargate.net
Address: 209.166.161.121
Name: www.example.org
PANIMALAR ENGINEERING COLLEGE, DEPT. OF CSE PAGE - 7 -
CS8651- INTERNET PROGRAMMING UNIT- I: WEBSITE BASICS
Address: 192.0.34.166
The output of first two lines identify the qualified name and IP address of
the DNS server that is providing the domain name information in the last two
line of the output
Also notice that a single IP address can be associated with multiple
domain names. In this example, both www.example.org and
www.example.com are associated with the IP address 192.0.34.166
Reverse lookup
A lookup that specifies an IP address to find corresponding qualified name
(URL address) is referred to as a reverse lookup. If multiple qualified names
are associated with an IP address, only one of the names will be returned by
a reverse lookup. This is known as the canonical name for the host; all
other names are considered aliases. In the following reverse lookup
indicates that www.example.com is the canonical name for the host with IP
address 192.0.34.166
C:¥>nslookup 192.0.34.166
Server: slave9.dns.stargate.net
Address: 209.166.161.121
Name: www.example.com
Address: 192.0.34.166
that are globally connected via IP, where as World Wide Web can be defined
as the collection of machines (web servers) on the Internet that provide
p
information via HTTP, and provide HTML documents on request by
client(usually browser)
web web
$ telnet www.example.org 80
Trying 192.0.34.166...
Connected to www.example.com (192.0.34.166).
GET / HTTP/1.1
Host: www.example.org Request message
HTTP/1.1 200 OK
The request consists of the three lines beginning with the GET and ending
with a blank line,
The response message in this case begins with the line
HTTP/1.1 200 OK
- is status line of the response,.
<HTML>
…
</HTML>
- is the body of the response and is written using the HTML language,
- Example:
PANIMALAR ENGINEERING COLLEGE, DEPT. OF CSE PAGE - 12 -
CS8651- INTERNET PROGRAMMING UNIT- I: WEBSITE BASICS
GET / HTTP/1.1
1.4.2.2. Request-URI
The second part of the start line is known as the Request-URI.
Request-URI (/ in this example) forms a string known as a Uniform Resource
Identifier(URI) by concatenating the string http:// with the value
alue of
o the Host header field (www.example.org, in this example), and
o the Request-URI
URI (/
( in this example)
In out example, the URI is http://www.example.org/
URI
A URI is an identifier that is to
o be associated with a particular resource such
as a web page or graphics image on the World Wide Web.
Every URI consists of two parts:
o the scheme, which appears before the colon (:), and
o another part that depends on the scheme.
Web addresses, use the http scheme or https scheme.. In this scheme, the
URI represents the location of a resource on the Web. A URI of this type is
said to be a Uniform Resource Locator (URL).
Some other URI schemes that mark the URI as a URL are shown in the
following Table: Some Non-http
Non URL Schemes
HTTP/1.1 also defines a number of other header fields, several of which are
commonly used by modern browsers.
Each header field:
begins with a field name, such as Host,
followed by a colon and then
a field value.
The following is an example of an actual HTTP request sent by a browser
consists of a start line, followed by ten header fields, and ends with short
message body:
doit=Click+me
Example:
HTTP/1.1 200 OK
<HTML>
<HEAD>
<TITLE>Example Web Page</TITLE>
</HEAD>
<BODY>
…
</BODY>
</HTML>
The first line of a response message is the status line,, which consists of
three fields:
The HTTP version used by the server software
A numeric status code indicating the type of response and
text string (the reason phrase)) that presents the information
represented by the numeric status code in human-readable
human readable form.
In this above example, the status code is 200 and the reason phrase is
OK., which indicates that no errors were detected by the server. The body of
a response having this status code should contain the resource requested by
the client.
Status code
All status codes are three-digit decimal numbers.. The first digit
represents the general class of status code.. The five classes of HTTP/1.1
first digit of status codes are given in the following Table:
The last two digits of a status code define the specific status within the
specified class. A few of the more common status codes are shown in the
following Table: Some Common HTTP/1.1 Status Codes
Some other common response header fields are shown in the following Table
1.5 Some Common HTTP/1.1 Response Header Fields
In the first approach the client ask the server whether or not the client’s
copy is valid. This can be done with very little communication by
sending an HTTP request for the resource using the HEAD method,
which returns only the status line and header portion of the response. If
Last-Modified time in the response message precedes the value of the
Date header field returned with the cached resource, then the cached
copy is still valid and can be used. Otherwise, the cached copy is
invalid and the browser should send a normal GET request for the
resource.
In a second approach, if the server returns an ETag with the resource.
The client can then simply compare the ETag returned by a HEAD
request with the ETag stored with the cached resource. If the ETag
values match, then the cached copy is valid
Finally, if the server can determine in advance the earliest time at which
a resource will change, the server can return that time in an Expires
header. In this case, as long as the Expires time has not been reached,
the client may use the cached copy of the resource without the need to
validate with the server.
SafariTM
Google Chrome
Task of browser:
A primary task of any browser is to make HTTP requests on behalf of the
user.. If a user types an URL in Location bar, the browser must perform a
number of tasks:
Reformat the URL entered as a valid HTTP request message.
If the server is specified using a host name use DNS to convert this
name to the appropriate IP address
Establish a TCP connection using the IP address of the specified web
server.
Send the HTTP request over the TCP connection and wait for the
server’s response.
Display the document contained in the response. If the document is not
a plain-text document but instead is written in a language such as
HTML, this involves rendering the document: positioning text and
graphics appropriately within the browser window, creating table
borders, using appropriate fonts and colors, etc.
1.6.2 URLs
An http-scheme URL consists of a number of parts. Let’s consider the
following example URL:
http://www.example.org:56789/a/b/c.txt?t=win&s=chess#para5
In that
o www.example.org:56789
It is known as the authority of the URL.
It could be either a fully qualified domain name or IP address of
web server
o 56789
It is known as port number, which is separated from IP
address/ domain name using color(:)
It is an optional. If it is ignored port number 80 is assumed
o /a/b/c.txt
It is called as path of the URL
o t=win&s=chess
It is called as query string of URL
These are the names and values of HTML form fields sent
server page
t and s are name of form fields, where as win and chess are
values of corresponding field respectively
o /a/b/c.txt?t=win&s=chess
It is called as request URI of URL address
o #para5
It is known as the fragment of the URL
o para5
It is known as the fragment Identifier.
Fragment identifiers are used by browsers to scroll particular
part of HTML documents
o Style definition: The user can define default font sizes, background
and foreground colors, etc for HTML pages that are displayed in the
web browser
o Document meta-information: it is used to set web document’s MIME
type, character encoding, size, etc
The Tomcat server you have installed than you can use a web interface for
setting most of these parameters. To do this, simple open a browser on the
machine that running the server, then typing following URL address in the
address bar:
http://localhost:8080
On n the left side of the browser window, Java Web Services Developer Pack (JWSDP)
Service entry is listed. First, click on the handle icon next to the JWSDP Service entry
in order to reveal its associated server components
This Service has five components: Connector, Host, Logger, Realm, and Valve.
A Connector is a Coyote component that handles HTTP communications directed to
a particular port.
The panel on the right in this figure is is typical of the panels displayed for creating and
editing Tomcat components.
Some of the key fields for the Connector component type are listed in the following
Table:
Field name Description
Accept Count Define maximum number of TCP connection allowed to wait
in the queue
Connection Its value indicates how many milliseconds the server s has to
Timeout wait for client request without closing connection,
connection if client is
idle
IP Address It this field is blank, then server will accept request from any
machine. It there are IP addresses mentioned then sever will
only accept request from clients having IP address listed in
this field
Port Number Port number on which server listen for TCP connection
requests
Min Spare Determine initially, how many number of threads kept ready
Threads in thread pool to receive request from client
Max Threads Determine maximum number of thread allowed
simultaneously to process multiple clients request
Max Spare Maximum number of idle threads allowed to exist at any one
Threads time
Several of the fields listed in the above Table are associated with web applications. A
web application is a collection of files and programs that work together to provide a
particular function to web users.
For example, a Web site might run two web applications: one for use by
administrators of the site that provides maintenance functionality, and another for
use by external clients that provides customer functionality
In Tomcat, a web application is represented by a Context component. If you open
the localhost Host, you will find that it has several contexts predefined
Each Host and Context is associated with a directory in the server’s file system. The
directory associated with a Host is specified by the value of the Application Base
field.
The directory associated with a Context is specified by the value of the Document
Base field
Context has the following properties:
o Cookies=True|False – indicates whether application support cookies or not
o documentBase - determine the physical path associated with current context
or virtual directory
o debug level: 0|1|2 determine how error message to be displayed to end user
when error encountered
1.7.5 Logging
Through logging, Web server record information about server activity.
An access log is a file that records information about every HTTP request
processed by the server.
A web server may also maintain message logs which stores a variety of
debugging and other information generated by web applications, and
errors encountered by web server itself.
Access logging in Tomcat is performed by adding a Valve component to
a Service. The primary fields for an Access Log Valve are shown in the
following Table:
Field name Description
Directory Determine the directory where log file will be written
Pattern Information to be written to the log
Prefix String that will be used to begin log file name
Resolve Hosts It its value is false then IP addresses should be written to the
log file, otherwise host names should be written to the log
file
Rotatable Whether or not date should be added to file name and file
should be automatically rotated each day
Suffix String that will be used to end log file name
The combination of values for the Directory, Prefix, Rotatable, and Suffix
fields determine the file system path to the access log
For example JWSDP access log name might be access_log.2005-07-20.txt
The Tomcat server writes one line of information per HTTP request processed
to the access log, with the information to be output and its format specified by
the Pattern field.
The Pattern for the JWSDP Service access log Valve is
%h %u %t "%r" %s %b
This corresponds to what is often called the common access log format. The
following is an example access log line in common format (this example is
split into two lines for readability):
www.example.org - admin [20/Jul/2005:08:03:22 -0500]
"GET /admin/frameset.jsp HTTP/1.1" 200 920
In general, any machine other than the sender or receiver that extracts
information from network messages is known as an eavesdropper.
To prevent eavesdroppers from obtaining sensitive information, such as credit
card numbers, all such sensitive information should be encrypted before being
transmitted over any public communication network.
We can use the https scheme on the URL to indicate a browser that it should
encrypt an HTTP request before it sent to the public network
For example, entering the URL
https://www.example.org
This will cause the browser to attempt to send an encrypted HTTP GET
request to www.example.org.
Many browsers and servers support one or more versions of the Secure
Socket Layer (SSL) protocol as well as the newer Transport Layer
Security (TLS) protocol, which is based on SSL 3.0.
The following description of HTTP encryption is derived from the TLS 1.0
specification, but the same general ideas apply to the earlier SSL protocols as
well.
o A client browser that wishes to communicate securely with a server
begins by initiating a TLS Handshake with the server.
o During the Handshake process, the server and client agree on
various parameters that will be used to encrypt messages sent
between them.
o The server also sends a certificate to the client. The certificate
enables the client to be sure that the machine it is communicating with
is the one the client intends..
o Certificates are necessary to avoid so-called man-in-the-middle
attacks, in which some machine intercepts a message intended for
another machine (the target), prevents the message from further
forwarding, and returns an HTTP reply to the sender pretending to be
from the target.
o Such an interception could occur at a rogue Internet bridge device on
the route between client and server, or through unauthorized alteration
the DNS system,
At the conclusion of the TLS Handshake, the client uses the cryptographic
parameter information obtained to encrypt its HTTP request message before
sending it to the server over TCP/IP. The server’s TLS software decrypts this
request before any other server processing is performed.
The server similarly encrypts its response before sending it to the client, and
the client immediately decrypts the received message.
Tomcat supports the TLS 1.0 and earlier protocols. To enable the secure
server Tomcat features, you must do two things:
1. Obtain and install a certificate.
2. Configure the server to listen for TLS connections on some port.
For test purposes, you can generate your own “self-signed” certificates using
the keytool program distributed with Sun JavaTM JDKTM development
software. by entering the following at a command prompt:
This says that you want to generate a self-signed certificate that can be
referenced by the name tomcat and that the encryption/decryption keys
generated for use with this certificate should be compatible with the RSA
encryption/decryption algorithm
You will be prompted to enter several pieces of information. Enter fully
qualified domain name of your machine
enter your first and last name when asked. Also, I suggest using the password
changeit when asked, which will allow you to use defaults when you configure
the server to use this certificate
Configuring the server to listen for TLS connections simply involves adding a
second Connector to a Service The Type field of the new Connector must be
set to HTTPS.
On the resulting Connector panel, make sure that the Secure field is set to
True, and fill in the port number (say 8443) to be used for this connection.
Other fields can retain their default values
Now restart your Tomcat server, close and reopen your browser, and then
browse to https://localhost:8443, If you created a self-signed certificate. you
should see a message asking you whether or not you wish to accept the
certificate. After accepting it, you should see the default JWSDP web page
produced by your server
The word GET is an HTTP method indicating that the client wishes to obtain
a resource from the server. The remainder of the request provides
provide the path
name of the resource (e.g., an HTML5 document) and the protocol’s name
and version number (HTTP/1.1). The client’s request also contains some
required and optional headers.
Any server that understands HTTP (version 1.1) can translate this request
reques
and respond appropriately. Figure 1.9 shows the web server responding to a
request.
The server first sends a line of text that indicates the HTTP version, followed
by a numeric code and a phrase describing the status of the transaction. For
example,
HTTP/1.1 200 OK
informs the client that the web server could not locate the requested resource.
HTTP Headers
Next, the server sends one or more HTTP headers, which provide additional
information about the data that will be sent. In this case, the server is sending
an HTML5 text document, so one HTTP header for this example would read:
Content-type: text/html
Data tier
The bottom tier (also called the data tier or the information tier) maintains
the application’s data. This tier typically stores data in a relational database
management system (RDBMS). Amazon might have an inventory information
database containing product descriptions, prices and quantities in stock.
Another database might contain customer information, such as user names,
billing addresses and credit card numbers. These may reside on one or more
computers, which together comprise the application’s data.
Middle tier
The middle tier implements business logic, controller logic and
presentation logic to control interactions between the application’s clients
and its data. The middle tier acts as an intermediary between data in the
information tier and the application’s clients. The middle-tier controller logic
processes client requests and retrieves data from the database. The middle-
tier presentation logic then processes data from the information tier and
presents the content to the client. Web applications typically present data to
clients as HTML documents.
Business logic in the middle tier enforces business rules and ensures that
data is reliable before the application updates a database or presents data to
users. Business rules dictate how clients access data and how applications
process data. For example, a business rule in the middle tier of a retail store’s
web-based
based application might ensure that all product quantities remain
positive. A client request to set a negative quantity in the bottom tier’s product
information database would be rejected by the middle
middle tier’s business logic.
1.10. Client-Side
Side Scripting versus Server-Side
Server Scripting
Client-side scripting with JavaScript can be used to validate user input, to
interact with the browser, to enhance web pages, and to add client/server
communication
ication between a browser and a web server.
Client-side
side scripting does have limitations, such as browser dependency;
o the browser or scripting host must support the scripting language and
capabilities.
o Scripts are restricted from arbitrarily accessing the local hardware and
file system for security reasons.
o Another issue is that client-side
client side scripts can be viewed by the client by
using the browser’s source-viewing
source capability. So Sensitive information,
such as passwords or other personally identifiable data,
data, should not be
on the client
o Also, placing certain operations in JavaScript on the client can open
web applications to security issues.
server-side scripts
Programmers have more flexibility with server-side scripts, which often
generate custom responses for clients. For example, a client might connect to
an airline’s web server and request a list of flights from Boston to San
Francisco between April 19 and May 5. The server queries the database,
dynamically generates an HTML document containing the flight list and sends
the document to the client. This technology allows clients to obtain the most
current flight information from the database by connecting to an airline’s web
server.
Server-side scripting languages have a wider range of programmatic
capabilities than their client-side equivalents. Server-side scripts also have
access to server-side software that extends server functionality—Microsoft
web servers use ISAPI (Internet Server Application Program Interface)
extensions and Apache HTTP Servers use modules.
Attributes
<style type="text/css”>
…<!- css code placed here ->
</style>
<script language="javascript”>
//javascript code placed here
</script>
</head>
<body>
<!- content that to be displayed in the browser placed here ->
</body>
</html>
<Head> Section
Head section enclosed between <head> and </head> tag.
The head section of the webpage includes all the stuff that does not displayed
directly on the client area of browse.
<title> Element
This is called a nested element, because it’s enclosed in the head element’s start and
end tags.
The <title> and </title> tags encapsulate the title of your web page. Its content
is displayed in the title bar of the browser.
<meta> Element
Another component in the head section is Meta tags. Meta tags are used to
give information about author of the page, software used to create current
page. An example given below:
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
It also includes keywords for search engine to list your web page during
searches.This helps to improve the rankings in search engines.
An example given below:
<meta name="keywords" content="HTML, XHTML, CSS, tutorials " />
It is also used to provides an instruction to browser about how often the page
should refreshed automatically, what character set should be used to interpret
current document, redirection information, etc
<meta http-equiv="refresh" content="10;url=http://www.tizag.com"/>
<meta charset="UTF-8">
<script> tags
Quite often the head section contains Scripts like Javascript or VBScript
which are programming languages for more complex HTML pages. Javascript
and VBScript are used either to validate HTML form input controls, or to
generate animation and change content of the HTML page dynamically
<style> tag
Finally, more and more pages contain codes for cascading style sheets
(CSS). CSS is a rather new technique for optimizing the layout of major
websites. CSS are used to format content of the HTML in programmer friendly
mannere
<Body> Section
The body of the document contains all that can be seen when the user loads
the page. It may consist of text, images, tables, forms, list items, special
characters etc related tags.
It may also contain user interface controls such as textbox, list box, drop down
list, text area, password field, video, audio controls, etc
Body section always will begin with <body> and end with </body> tags.
<body> tag has the following attributes:
o bgcolor – define background color of the document
o text – define foreground color of the entire document
o background – bring the background image instead of background color
o alink – define active link color
o vlink – define visited link color
o link – define not yet visited link color or new link color
o leftmargin, topmargin, rightmargin, bottommargin – define
corresponding margin of the page. The values should given in pixel
o bgproperties=fixed/scroll. It determines whether background image
should be placed multiple time or not. If fixed is given as value, when
the content of the web document grow more than one page the
background image will not be pasted multiple time
Example::
<body bgcolor="black" text="red"
link="yellow" alink="orange"
vlink="white" background="image.gif">
1.11.5. Heading
Some text in web document may be more important than other text. HTML5
provides six heading elements (h1 through h6) for specifying the relative
importance of information.
Attribute Description
Src URL address of an image file,
Width It determines the width of the image in pixel
height It determines the height of the image in pixel
Align It determine alignment of the text along with image. The
possible values are top, bottom, middle, absmiddle,
absbottom, abstop, left, right
Alt This information useful for the user those who viewing
your web page with CUI based browser such as LYNX.
Since CUI browser does not have capability to show
image, in that place the text assigned to alt will be
displayed. In the GUI browse, this will be shown as tool
tip, when user moves mouse over the image
Example:
<!DOCTYPE html>
<body>
<p>
<img src = "fish.jpg" width = "160" height = "140"
border=10 alt = "fishes in the river" />
<img src = "flow11.jpg" height = "150"
border=5 alt = "marigold flower" />
</p>
</body>
</html>
Output:
The possible values for type attribute is disc (),circle (o),square (■)
Example: output in the browser:
<ul>
<li>Coffee</li>
<li>Milk</li>
</ul>
Each term in the list is identified by the <dt> tag. Description of each term is
identified by <dd> tag must follow the <dt> tag to provide the definition of the
preceding term.
o <dl> - definition list
o <dt>- definition term
o <dd>- definition description
Syntax: Output:
<dl>
<dt>…</dt>
<dd>…</dd>
<dt>…</dt>
<dd>…</dd>
…
</dl>
Example:
<dl>
<dt>Java</dt>
<dd>A programming language</dd>
<dt>HTTP</dt>
<dd>Hyper Text Transfer Protocol</dd>
</dl>
1.11.7.4. <dir> Element
This tag will work in the same way as <ul> except. It will move the content one tab
towards right side. List items are represented using <li>
</ul> Output:
<li>Dosai
<ul>
<li>Rava Dosai
<li>ghee Dosai
</ul>
<li>chapatti
</ol>
<li>lunch
<ol type="i">
<li>Meals
<ul>
<li>Ordinary
<li>Spl. Meals
</ul>
<li>Mini Meals
<ul>
<li>lemon rice
<li>sambar rice
</ul>
</ol>
</ul>
</body>
</html>
1.11.8.Tables
Tables are frequently used to organize data into rows and columns. To
construct table the following HTML elements are used:
<table> - is the outer most tag that encapsulates all other following tag. Its
attributes includes:
o border=integer - define the border of the table
o bgcolor=#rrggbb – define background color of the table
o background=url – define background picture of the table
o align = left|right|center- define alignment of table within the page
o cellpadding =integer – define space allowed within the cell in pixel
o cellspacing =integer – define gap or space between cells in pixels
Example 1
<!DOCTYPE html>
<html>
<body>
<table border = "5" bgcolor=pink>
<caption><strong>Table of Fruits (1st column) and
Their Prices (2nd column)</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>Apple</td>
<td>$0.25</td>
</tr>
<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>
</tbody> </table> </body> </html>
Output:
<!DOCTYPE html>
<html>
<body>
<table border = "10">
<tbody>
<tr>
<th colspan=3>Price List of seeds(per Kg)</th>
</tr>
<tr>
<th rowspan=2>Paddy</th>
<td>Ponni</td>
<td>Rs. 150</td>
</tr>
<tr>
<td>Sorna</td>
<td>Rs. 90</td>
</tr>
<tr>
<th rowspan=3>Millet</th>
<td>Co-1</td> Outpiut:
<td>Rs. 80</td>
</tr>
<tr>
<td>Co-2</td>
<td>Rs. 110</td>
</tr>
<tr>
<td>ADT-95</td>
<td>Rs. 90</td>
</tr>
</tbody>
</table>
</body>
</html>
o navigate to a URL
o open an e-mail client
o download executable file to client machine
in web page, Any displayed element can act as a hyperlink.such as text,
image, etc
Web browsers typically underline text hyperlinks and color their text blue by
default
We use =Anchor Element (<A>) to define hyperlink with href attributes
Linking can be of two types:
o Internal linking: linking different part of the same web document
o External linking: linking external resources
Example::INTERNAL.HTML
<!DOCTYPE html>
<html>
<body>
<a name="top"> <hr color="red" /> </a>
<h2 align="center">
<a href="#favorite">Click here to see my favorite</a>
</h2>
<hr color="red" />
<pre>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 output, after clicking link
18
19
20
21
22
23
24
25
26
</pre>
<hr color="red" />
<a name="favorite">My Favorites</a>
<hr color="red" />
<ul>
<li> listening music
<li> swimming in the sea
<li> Reading News paper
<li> Watching TV
</ul>
<hr color="red" />
<a href="#top">back
"#top">back to top</a>
<hr color="red" />
</body>
</html>
1.11.9.2.
2. EXTERNAL LINKING / EXTERNAL DOCUMENT REFERENCE
External linking— is a mechanism that enables the user create a hyperlink in
the current web document to any external resources such as another web
documents, image, link to client email software etc
Example:
<!DOCTYPE html>
<html>
<body>
The img element’s src attribute value specifies that this image (contact.jpg)
(
resides
des in a directory named images. The image directory and the the current
HTML document are in the same directory
Within the <form> element, you can include the following html elements to
define various UI controls including the following:
• <input> - it is used to define text field, password filed, check box, radio
button, push button, hidden field, submit and reset buttons
• <textarea> - it is used to define multiline text box
• <select> & <option> - it is used to define dropdown list
• <fieldset> and <legand> - it is used is used to group form controls into
logical, related “chunks.” with title caption
o submit This control creates the familiar "submit" button, which appears
as a raised button with a push-button look. The word on the control can
be customized using the value attribute.
o reset The same in appearance and customization features as submit,
this control will clear the form so the sire visitor can re-enter his or her
answers.
o file This creates a file selection control. The site visitor can then select
a file to upload.
o hidden Hidden controls are those that don't render in the browser.
They are used to insert information for the recipient of the form data.
o image Allows for the insertion of a custom image. This gives the
designer the ability to use a graphic for submit and reset instead of the
default option.
o button Creates a push button. These must be associated with a script
in order to work, since there is no built-in action for them
Example:
<form method="get" action = "http://www.xyz.com/validate.php">
User Name:
<input type = "text" autofocus name="username"/>
<p>
Password :
<input type = "password" name="passwd"/>
</p> <p>
<input type = "submit" value = "Login" />
<input type = "reset" value = "Clear" />
</form>
Output:
Output:
1.11.10.3.
3. <select> and <option> Element
Example of Creating combo box:
box
District:
<select name="district">
<option
option value="Chennai">Chennai</option>
<option value="CGL">Chengalpet</option>
<option value="VPM" selected>villupuram</option>
</select>
Output:
1.11.10.4. <textarea>
> Element : creating multiline textbox
Example:
your suggestion:<br/>
<textarea name="suggestion" rows=10 cols=25>
</textarea>
Output:
url The url type is used for input fields that should contain a URL
address. The value of the url field is automatically validated when
the form is submitted
week The week type allows the user to select a week and year
Example:
<!DOCTYPE html>
<body>
<h2>New HTML5 Form Controls Demo</h2>
<form method = "post" action = "http://www.xyz.com">
<p>Text Color:
<input type = "color" autofocus/> Hexadecimal code such as #ADD8E6)
</p>
<p>Date of Joining:
<input type = "date" required"/>(yyyy-mm-dd)
</p>
<p>Time of present at office:
<input type = "datetime-local" /> (yyyy-mm-ddThh:mm)
</p>
<p>Email:
<input type = "email" placeholder = "name@domain.com" required />
</p>
<p>Year and Month you got promotion:
<input type = "month" />(yyyy-mm)
</p>
<p>Font Size:
<input type = "number" min = "1"
max = "7" step = "1" value = "4""/>
(Enter a number between 1 and 7)
</p>
<p>Your Age:
<input type = "range" min = "17"
max = "55" value = "17"/>(valid between 17 and 55)
</p>
<p>Residence Telephone Number:
<input type = "tel" placeholder = "(###) ###-####"
pattern = "\(\d{3}\) +\d{3}-\d{4}" required />
</p>
<p>Time at which left office:
<input type = "time" placeholder = "hh:mm"/>
</p>
<p>URL address:
<input type = "url"
url" placeholder = "http://www.domainname.com" />
</p>
<p>Week:
<input type = "week" />(yyyy-Wnn,
/>(yyyy such as 2012-W01)
</p>
<p>
<input type = "submit" value = "Submit" />
<input type = "reset" value = "Clear"
"Clear />
</p> </form> </body></html>
Output generated in google Chrome:
placeholder Attribute
The placeholder attribute allows you to place temporary text in a text field.
field
Generally, placeholder text is light gray and provides an example of the text
and/or text format the user should enter
When the focus is placed in the text field, the placeholder text disappears—it’s
disappears
not “submitted” when the user clicks the Submit button
required Attribute
The required attribute forces the user to enter a value before submitting the
form. You can add required to any of the input types. For example, if the user
fails to enter value in the required filed and clicks the Submit button,, then
system will transfer focus to corresponding filed with error message and
asking the user to enter the information
A semantic element clearly describes its meaning to both the browser and the
developer.
Examples of non-semantic
semantic elements: <div> and <span> - Tells nothing about
its content.
Examples of semantic elements: <form>, <table>, and <img> mg> - Clearly
defines its content.
HTML5 offers new semantic elements to clearly define different parts of a web
page:
<header>
<nav>
<section>
<article>
<aside>
<figcaption>
<figure>
<footer>
<section id = "3">
<h2>Results from our Facebook Survey</h2>
<p>If you were a nonprogrammer about to learn Java for the first
time, would you prefer a course that taught Java in the
context of Android app development?
development? Here are the results from
our survey:</p>
Output:
The <mark> element highlights the text that’s enclosed in the element.
We use the <wbr> element to prevent a word from breaking in an awkward
place.
Example
<html><body>
<p> this is sample paragraph to demonstrate mark. <mark>This is marked
text</mark>.. This is outside marked text</p>
text
<h6>© 2018 by Krishnan & <wbr>Associates</wbr>,, Inc<h6>
</body></html>
Output:
<p>
<input type = "submit" value = "Submit" />
<input type = "reset" value = "Clear" />
</p>
</form>
</body>
</html>
Output:
Name with autocomplete:
1. To make an element draggable, the element must use draggable attribute, and
set an event listener for dragstart that stores the data being dragged.
2. In the even handler you needs to store data into the DataTransfer object and
set the allowed effects such as copy, move, link, or some combination
To accept a drop, the drop target has to listen to the following events:
1. The dragenter event handler reports whether or not the drop target is
potentially willing to accept the drop, by canceling the event. This event
handling is optional
2. The dragover event handler specifies what feedback will be shown to the
user, by setting the dropEffect attribute of the DataTransfer associated with
the event. This event also needs to be canceled.
3. The drop event handler has a final chance to accept or reject the drop. If the
drop is accepted, the event handler must perform the drop operation on the
target.Otherwise, the drop operation is rejected.
[NOTE:If drop is accepted, this event needs to be canceled, so that the
dropEffect attribute's value can be used by the source]
Output:
Before drop: after drop:
Example 2:
<!DOCTYPE html>
<head>
<script>
function dragStartHandler(event) {
event.dataTransfer.setData("Text",event.target.id);
event.dataTransfer.effectAllowed = 'move'; // only allow moves
}
function dragOverHandler(event)
{
event.preventDefault();
}
function dropHandler(eventent)
{
event.preventDefault();
.preventDefault();
var data=event.dataTransfer.getData("Text");
.dataTransfer.getData("Text");
event.target.appendChild(document.getElementById(data));
.target.appendChild(document.getElementById(data));
}
</script>
<body>
<p>What fruits do you like?</p><hr/>
<ol ><li draggable="true" data-value="apples"
value="apples" id="a">Apples</li>
<li draggable="true" data-value="oranges"
value="oranges" id="b">Oranges</li>
<li draggable="true" data-value="pears"
value="pears" id="c">Pears</li>
</ol>
The control attribute adds audio controls like play, pause, and volume.
volume
You should also insert text content between the <audio> and </audio> Element
for displaying in the browsers that does not support the <audio> element.
The <audio> element allows multiple <source> elements.
elements
<source> elements can link to different audio files. The browser will use the
first recognized format. Currently, there are 3 supported file formats for the
<audio> element: MP3, Wav, and Ogg
MIME Types for Audio Formats are for mp3 - audio/mpeg, Ogg - audio/ogg,
wav- audio/wav
The control attribute adds video controls, like play, pause, and volume.
It is also a good idea to always include width and height attributes. If height and
width are set, the space required for the video is reserved when the page is
loaded. However, without these attributes, the browser does not know the size
of the video, and cannot reserve the appropriate space to it. The effect will be
that the page layout will change during loading (while the video loads).
You should also insert text content between the <video> and </video> tags for
displaying in the browsers that do not support the <video> element. The
<video> element allows multiple <source> elements.
<source> elements can link to different video files. The browser will use the
first recognized format.
Currently, there are 3 supported video formats for the <video> element: MP4,
WebM, and Ogg
MIME Types for Video Formats
Format MIME-type
MP4 video/mp4
WebM video/webm
Ogg video/ogg
<html>
<body>
<canvas id="myCanvas" width="200" height="100"
style="border:1px solid
so #0000FF;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="#FF0000";
/*The fillStyle property can be a CSS color, a gradient, or a pattern
pattern The default
fillStyle is #000000 (black) */
ctx.fillRect(0,0,150,75);
</script> Its output shown in the browser is given below:
</body>
</html>
Canvas Coordinates
The canvas is a two-dimensional
dimensional grid.
The upper-left
left corner of the canvas has coordinate (0,0)
So, the fillRect() method above had the parameters (0,0,150,75).
This means: Start at the upper-left
upper left corner (0,0) and draw a 150x75 pixels
rectangle.
Canvas - Paths
To draw straight lines on a canvas, we will use the following two methods:
ctx.beginPath();
ctx.arc(95,50,40,0,2*Math.PI);
ctx.stroke();
The output will look like the following:
Using strokeText():
In the previous example replace fillText( ) with the following code:
ctx.strokeText("Hello World",10,50);
Then you would get out put similar to the following:
Canvas - Gradients
Gradients can be used to fill rectangles, circles, text, etc. Shapes on the canvas
are not limited to solid colors.There are two different types of gradients:
The selector is normally the HTML element you want to apply style. Each
declaration consists of a property and a value. The property is the style attribute
you want to change. Each property has a value.
Declaration block
A declaration block consists of a list of declarations in braces. Each
declaration itself consists of a property, followed by a colon (:), and a value.
If there are multiple declarations in a block, a semi-colon (;) must be inserted
to separate each declaration
CSS coding could be either written within the html file or written in external
file and linked within html file.
i. To write CCS code within html file, you have to use the following tag
and syntax:
<html>
<head>
<style type="text/css">
<!--
ii. To write CCS code in the external file, the file must be saved with .css
extension and from within the html file you have to link this external
CSS file using following syntax:
<link rel=stylesheet type="text/css" href="style.css">
@import url(“url-address
address-of-external-css-file”);
additional css style code go here
</style>
Example:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
@import url("mystyle.css");
UL
{
list-style-image:url("bullet.gif");
image:url("bullet.gif");
}
a:hover{color: "red";} OUTPUT
<style>
</head>
<body>
<h1>Course offered</h1>
<ul>
<li>MBA
<li>MCA
</ul>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
Output:
p { text-transform:lowercase;
transform:lowercase; }
</style>
</head>
<body>
<H1>this
>this is header </H1>
<p> THIS IS PARAGRAPH</a>
<H1>this is another header </H1>
<p> THIS IS ANOTHER PARAGRAPH</a>
</body>
</html>
Output:
(ii) Id selector
The id selector is used to specify a style for a single, unique element.
The ID selector uses the ID attribute of the HTML element to define CSS, and
in the style definition, value of the ID attribute is prefixed with #.
The style rule is applied to only Elements that having corresponding ID
attribute
In the following example, the style rule will be applied to only element having
id="mystyle":
Example:
<html>
<head>
<style type=text/css>
#mystyle
{
text-align:center;
background:pink;
text-transform:uppercase;
}
</style>
</head>
<body>
<H1 id=”mystyle”>this is header with id=mystyle </H1>
<p> this is paragraph</a>
<H1>this is header </H1>
</body>
</html>
Its output shown below:
You can also specify that only specific HTML elements should be affected by a
class.
Consider the following css style:
p.center {text-align:center;}
The above css style all <p> elements with class="center", it cannot be applied
for other<p> elements having different class name or other tags (except <p> tag)
having same class name :
<p class=’center’> This is paragraph having class=’center’ </p>
<H1 class=’center’>This is header </H1>
< p> this is paragraph without class </p>
So the style is applied only to the first <p> tag, it is neither applied to <H1>
not applied to second <p> tag
Example:
body {background-color:yellow;}
h1{background-color:#00ff00;}
p{background-color:rgb(255,0,255);}
dd{background-color:transparent;}
li{background-color:inherit;}
Example:
body { background-image : url('paper.gif'); }
Value Description
Repeat The background image will be repeated both vertically and
horizontally. This is default
repeat-x The background image will be repeated only horizontally
repeat-y The background image will be repeated only vertically
no-repeat The background-image will not be repeated
Inherit Specifies that the setting of the background-repeat property should
be inherited from the parent element
Example:
<!DOCTYPE html>
<head>
<style type='text/css'>
body {
background-image:url('rose.jpg');
background-repeat:repeat-y;
}
</style>
</head>
<body>
</body>
</html>
If background-repeat:repeat-x; is used then
the output similar to shown in the bottom
image is obtained
If the following style is used instead of above
one then only one copy of the background image is kept in the right-bottom of the
browser.
body{
background-image:url('rose.jpg');
background-position: bottom right;
background-repeat: no-repeat;
background-attachment: fixed;
background-color: white;
}
Even you scroll the web page down, the background image remain kept in the
right-bottom corner of browser as shown in the following figure:
Rule cascading
Consider the following style sheet rule in a html file:
* { font-weight:bold }
#p3 { background-color:aqua }
Where * applies to every element of the HTML document.
For element having id=p3 both selectors * and #p3 will be applied , because
both define different properties
Consider the following style sheet rule in a html file:
* { font-weight:bold }
#p3 { font-weight:normal }
Where * applies to every element of the HTML document.
For element having id=p3 only selector #p3 will be applied , because both
define same properties. #p3 given priority then *
In order to choose between multiple declarations that all apply to a single
property of a single element, the browser (or user agent) applies rule
cascading, a multistage sorting process that selects a single declaration that will
supply the property value
The very first step of this process involves deciding which external and
embedded style sheets apply to the document
For example, if alternate external style sheets are available, only one will apply,
and rules in the other alternate style sheets will be ignored
If a media type is specified for an embedded or external style sheet is not
supported by the user agent, then that style sheet’s rules will be ignored
Once the appropriate external and embedded style sheets have been identified,
the next stage of the sorting process involves associating an origin and weight
with every declaration that applies to a given property of a given element
In addition to an origin, every author and user style declaration has one of two
weight values: normal and important
A declaration has important weight if it ends with an exclamation mark (!)
followed by the word important as shown in the following rule:
p { text-indent:3em; font-size:larger !important }
In the above example property font-size has important weight, whereas
property text-indent has normal weight
All user-agent declarations can also be considered to have normal weight
Once the origin and weight of all declarations to an element property have been
established, they are prioritized (from high to low) as follows:
1. Important declaration with user origin
2. Important declaration with author origin
3. Normal declaration with author origin
4. Normal declaration with user origin
5. Any declaration with user agent origin
So each declaration falling in to one of five priority bins
Example
We begin by treating a ruleset with a comma-separated selector string as if it
were multiple rule sets each with a single selector; that is, a rule set such as
h1, #head5, .big { font-size:x-large }
is treated as the equivalent three rule sets
h1 { font-size:x-large }
#head5 { font-size:x-large }
.big { font-size:x-large }
Author: an author who create web document can define style sheet as part
of an external or embedded style sheet with in the html file itself
User agent: A browser or user agent may define default style property values
for HTML elements.
User: Most modern browsers allow users to provide a style sheet or style
preferences that are treated as style rules
Consider an example
imp1.css contains the following statement:
p { color:blue }
imp2.css contains the following statements:
@import url("imp1.css");
p { color:green }
index.html contains the following statement:
<link rel="stylesheet" type="text/css"
href="imp2.css" />
<style type="text/css">
p { color:yellow }
</style>
• Then the style rulesets are arranged order in the index.html file is:
p { color:blue }
p { color:green }
p { color:yellow }
• Elements <p> will be displayed with yellow text
The style cascade is summarized in the Figure:
Rule Inheritance:
• If no style rule defined for any element then it inherits Style rules from its
parent elements
• If the same property with different value defined in both parent and child
element selectors then for that property value defined in the child element
selector will be given priority
• Consider the following example:
exam
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { font-weight:bold;color:red;}
weight:bold;color:red;}
li { font-style:italic;color:black;
style:italic;color:black; }
span { font-weight:normal
weight:normal }
</style>
</head>
<body>
<p> Text outside LI,within paragraph and,
<span>inside a span</span></p>
<ul>
<li> embedded List item outside and
<span>inside a span</span>.
</li>
</ul>
</body>
</html>
Output:
1.12.7. 1. Borders
Border consist of three properties:
properties border-width, border-style,border
style,border-color.
Their features are explained below:
Border-width property
This determines thickness of the border.
border This property may be set to any valid
CSS length (e.g., em, ex, px)
px or to the predefined value of thin, medium or
thick
Possible values for border
der-width property includes the following:
following
o thin o thick
o medium o integer value in pixel
Example
o border-width:10;
Border-style property
It determines how the border line to be displayed.
displayed Possible values for border-
style property includes the following:
following
Border-color property
determine the color in which border line to be displayed
Example
o border-color : red
Border property
this property is used to combine features of border-style,
style, border-size
border and
border-color or you could use one or two features
syntax
o border : width style color;
Example
o border : 1px solid #0000FF;
complete example given below:
<!DOCTYPE html>
<html>
<head>
<style type = "text/css">
div { text-align: center;
width: 50%;
position: relative;
left: 25%;
border-width:
width: 6px;
border-style:solid;
border-color:red;
}
</style>
</head> OUTPUT:
<body>
<div>Solid border</div><hr>
</body>
</html>
In the above example, if change the CSS code similar to the following:
following
img { float:right;
border:thick double red;
margin: 1em .8em 1em 1em;
padding:20px 20px 20px 20px;
}
Then you would get following output:
}
#stretch {
border-image:
image: url(border.png) 80 80 80 80 stretch;
}
#repeat {
border-image:
image: url(border.png) 34% 34% repeat;
}
</style>
</head>
<body>
<h2>Image Borders</h2>
<p><div id = "stretch">Stretching
"stretch">Stretching the image border</div></p>
<p><div id = "repeat">Repeating the image border</div></p>
</body>
</html>
Output:
1.12.12. Color
CSS3 allows you to express color in several ways.
ways They are:
o standard color names (such as Aqua,Cyan,Pink). There here are over 140
HTML color names.
names. The following code define text color to purple:
color:purple
background-color:#00FFFF;
o RGB (Red, Green, Blue). The following code define background color
to RED using RGB:
background-color:RGB(255,0,0);
o RGBA (Red, Green, Blue, Alpha) gives you greater control over the
exact colors in your web pages. The value for each color—red, green
and blue—can range from 0 to 255. The alpha value—which represents
opacity—can be any value in the range 0.0 (fully transparent) through
1.0 (fully opaque)
The browser attempts to use the fonts in the order in in which they appear in the
list. If particular font is not available in the list, it tries to use the next font
It’s advisable to end a font list with a generic font family: name in case the
other fonts are not installed on the user’s computer.
computer. An example is given below:
h1 { font-family: tahoma, helvetica, sans-serif;
sans }
In this example, if the tahoma font is not found on the system, the browser will
look for the helvetica font. If neither is found, the browser will display its
default sans-serif font.
</h1>
output: (box-shadow: -20px -20px
px 15px dimgrey)
dimgrey
Transitions allow you to specify only the starting and ending values of the CSS
properties being changed
Transform property
Consider example of transform property declaration:
img:hover ( transform: rotate(360deg) scale(2, 2);}
This transform property specifies that the image will rotate 360deg and will
scale to twice its original width and height when the mouse hovers over the
image
The transform property uses transformation functions, such as
rotate(Ndeg) and scale(width,height), to perform the
transformations.
The rotate transformation function receives the number of degrees. Negative
values cause the element to rotate left. A value of 720deg would cause the
element to rotate clockwise twice.
The scale transformation function specifies how to scale the width and
height. The value 1 represents the original width or original height, so values
greater than 1 increase the size and values less than 1 decrease the size
Example
In the following example, we use the transition and transform properties to
scale and rotate an image 360 degrees when the cursor hovers over it.
<!DOCTYPE html>
<html>
<head>
<style type = "text/css">
img {
margin: 80px;
transition: transform 4s opacity 4s;
opacity:.5;
}
img:hover {
transform: rotate(360deg) scale(2, 2); opacity:1;
}
</style>
</head>
<body>
<img src = "sunflower.jpg" width = "150" / >
</body> </html>
Output from initial to final when mouse hover around image:
1.12.16. Animation
animation Property
The animation property allows you to represent several animation
properties in a shorthand notation, rather than specifying each separately, as
shown below:
animation: movingImage linear 10s 2 1s alternate;
property for each values in the animation property from left to right listed
below:
animation-name: movingImage;
animation-timing-function: linear;
animation-duration: 10s;
animation-delay: 1s;
animation-iteration-count: 2;
animation-direction: alternate;
In the shorthand notation, the values are listed in the following order:
animation-name - represents the name of the animation
(movingImage). This name associates the animation with the keyframes that
define various properties of the element being animated at different stages of
the animation
animation-timing-function - determines how the animation
progresses in one cycle of its duration. Possible values include linear, ease,
ease-in, ease-out, ease-in-out, cubic-bezier.
• Linear:animation will move at the same speed from start to finish.
• Ease: animation starts slowly, increases speed, then ends slowly.
• ease-in: animation starts slowly, then speeds up
• ease-out: animation starts faster, then slows down
• ease-in-out: animation starts and ends slowly
• cubic-bezier value allows you to customize the timing function with
four values between 0 and 1, such as cubic-bezier(1,0,0,1).
animation-duration - specifies the time in seconds (s) or milliseconds
(ms) that the animation takes to complete one iteration. The default duration is
0.
animation-delay - specifies the number of seconds or milliseconds after
the page loads before the animation begins. The default value is 0.
animation-iteration-count - specifies the number of times the
animation will run. The default is 1. You may use the value infinite to
repeat the animation continuously.
Example
In the following example, we create a simple animation of an image that moves
in a diamond pattern as it changes opacity. The @keyframes rule includes
five selectors to represent the points-in-time for our animation.
Recall that our animation will take 10 seconds to complete. In that context, 0%
indicates the beginning of a single animation cycle, 25% represents 2.5 seconds
into the animation, 50% represents 5 seconds into the animation, 75%
represents 7.5 seconds into the animation and 100% represents the end of a
single animation cycle. You can break down the animation into as many points
as you like. At each point, we specify the opacity of the image and the image
position in pixels from the left and from the top. We begin and end the
animation at the same point—left: 50px; top: 0px; creating a
diamond pattern along which the image moves
Example:
<!DOCTYPE html>
<html>
<head>
<style type = "text/css">
Img {
position: relative;
animation: movingimage linear 10s 1s 2 alternate;
}
@keyframes movingimage {
0% {opacity: 0; left: 50px; top: 0px;}
25% {opacity: 1; left: 0px; top: 50px;}
50% {opacity: 0; left: 50px; top: 100px;}
75% {opacity: 1; left: 100px; top: 50px;}
100% {opacity: 0; left: 50px; top: 0px;}
}
</style>
</head>
<body>
<img src = "sunflower.jpg" width = "138" height = "180"
alt = "sun flower">
</body>
</html>