Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

310252 Web Technology

310252 Web Technology


Prerequisites Courses:

Database Management Systems (310341), Computer Networks and Security (310244)

Companion Course:

Web Technology Laboratory (310257)

Course Objectives:

• To learn the fundamentals of web essentials and markup languages


• To use the Client side technologies in web development
• To use the Server side technologies in web development
• To understand the web services and frameworks

Course Outcomes:

On completion of the course, learners should be able to:

CO1: Implement and analyze behavior of web pages using HTML and CSS
CO2: Apply the client side technologies for web development
CO3: Analyze the concepts of Servlet and JSP
CO4: Analyze the Web services and frameworks
CO5: Apply the server side technologies for web development
CO6: Create the effective web applications for business functionalities using latest web development platforms

Unit 1 Page 1 of 44
310252 Web Technology

Unit I

Web Essentials and Mark-up language - HTML 07 Hours


The Internet, basic internet protocols, the world wide web, HTTP Request message, HTTP response message,
web clients, web servers. HTML: Introduction, history and versions. HTML elements: headings, paragraphs,
line break, colors and fonts, links, frames, lists, tables, images and forms, Difference between HTML and
HTML5. CSS: Introduction to Style Sheet, CSS features, CSS core syntax, Style sheets and HTML, Style rule
cascading and inheritance, text properties. Bootstrap.

1.1 The Internet


The Internet is a vast network that connects computers all over the world. Through the Internet, people can
share information and communicate from anywhere with an Internet connection.

The Internet traces its roots to a project of the U.S. Department of Defense’s then- named Advanced Research
Projects Agency, or ARPA. The ARPANET project was intended to support DoD research on computer
networking. As this project began in the late 1960s, there had been only a few small experimental networks
providing communication between geographically dispersed computers from different manufacturers running
different operating systems.

Several of the most widely used Internet protocols— including the File Transfer Protocol (FTP) and Simple
Mail Transfer Protocol (SMTP), which underlie many of the Internet’s file transfer and e-mail operations,
respectively— were initially developed under ARPANET.

ARPANET switched from using an earlier protocol to TCP/IP during 1982. At around the same time, an ARPA
Internet was created, allowing computers on some outside networks such as CSNET to communicate via TCP/
IP with computers on the ARPANET.

Access to the ARPANET was expanded in 1981 when the National Science Foundation (NSF) funded the
Computer Science Network (CSNET). In 1982, the Internet Protocol Suite (TCP/IP) was standardized, which
permitted worldwide proliferation of interconnected networks. TCP/IP network access expanded again in 1986
when the National Science Foundation Network (NSFNet) provided access to supercomputer sites in the
United States for researchers, first at speeds of 56 kbit/s and later at 1.5 Mbit/s and 45 Mbit/s.

The NSFNet expanded into academic and research organizations in Europe, Australia, New Zealand and
Japan in 1988–89. Although other network protocols such as UUCP had global reach well before this time, this
marked the beginning of the Internet as an intercontinental network. Commercial Internet service providers
(ISPs) emerged in 1989 in the United States and Australia. The ARPANET was decommissioned in 1990.

In summary, the Internet is the collection of computers that can communicate with one another using TCP/IP
over an open, global communications network.

Unit 1 Page 2 of 44
310252 Web Technology

1.2 Basic Internet Protocols


A computer communication protocol is a detailed specification of how communication between two computers
will be carried out in order to serve some purpose.

1.2.1 TCP/IP
TCP is a connection oriented protocol and offers end-to-end packet delivery. It acts as back bone for
connection.It exhibits the following key features:
• Transmission Control Protocol (TCP) corresponds to the Transport Layer of OSI Model.
• TCP is a reliable and connection oriented protocol.
• TCP offers:
• Stream Data Transfer.
• Reliability.
• Efficient Flow Control
• Full-duplex operation.
• Multiplexing.
• TCP offers connection oriented end-to-end packet delivery.
• TCP ensures reliability by sequencing bytes with a forwarding acknowledgement number that indicates to
the destination the next byte the source expect to receive.
• It retransmits the bytes not acknowledged with in specified time period.

IP address

A key element of IP is the IP address, which is simply a 32-bit number. At any given moment, each device on
the Internet has one or more IP addresses associated with it (although the device associated with a given
address may change over time). IP ad- dresses 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).

Packet

In telecommunications and computer networking, a network packet is a formatted unit of data carried by a
packet-switched network. A packet consists of control information and user data; the latter is also known as the
payload. Control information provides data for delivering the payload (e.g., source and destination network
addresses, error detection codes, or sequencing information). Typically, control information is found in packet
headers and trailers.

Gateway

A gateway is a piece of networking hardware or software used in telecommunications networks that allows
data to flow from one discrete network to another. Wikipedia

Unit 1 Page 3 of 44
310252 Web Technology

Hops
In wired computer networking, including the Internet, a hop occurs when a packet is passed from one network
segment to the next. Data packets pass through routers as they travel between source and destination. The
hop count refers to the number of network devices through which data passes from source to destination.

Route

The sequence of computers that a packet travels through from source to destination is known as its route.

Checksum

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. The IP standard calls for
IP software to simply discard any corrupted packets.

Acknowledgement

Once a connection has been established, TCP provides reliable data transmission by demanding an
acknowledgment for each packet it sends via IP. Essentially, the software sets a timer after sending each
packet. The TCP software on the receiving side sends a packet containing an acknowledgment for every TCP-
based packet it receives that passes the checksum test. If the TCP software sending a packet does not
receive an acknowledgment packet before its timer expires, then it resends the packet and restarts the timer.

Port

The port concept allows TCP to be used to communicate with many different applications on a machine. For

1.2.2 UDP, DNS and Domain Names

UDP - User Datagram Protocol


User Datagram Protocol (UDP) is a Transport Layer protocol. UDP is a part of the Internet Protocol suite,
referred to as UDP/IP suite. Unlike TCP, it is an unreliable and connectionless protocol. So, there is no need to
establish a connection prior to data transfer.

Though Transmission Control Protocol (TCP) is the dominant transport layer protocol used with most of the
Internet services; provides assured delivery, reliability, and much more but all these services cost us additional
overhead and latency. Here, UDP comes into the picture. For real-time services like computer gaming, voice or
video communication, live conferences; we need UDP. Since high performance is needed, UDP permits
packets to be dropped instead of processing delayed packets. There is no error checking in UDP, so it also
saves bandwidth.

User Datagram Protocol (UDP) is more efficient in terms of both latency and bandwidth.

Unit 1 Page 4 of 44
310252 Web Technology

UDP Header
UDP header is an 8-bytes fixed and simple header, while for TCP it may vary from 20 bytes to 60 bytes. The
first 8 Bytes contains all necessary header information and the remaining part consist of data. UDP port
number fields are each 16 bits long, therefore the range for port numbers is defined from 0 to 65535; port
number 0 is reserved. Port numbers help to distinguish different user requests or processes.

1. Source Port: Source Port is a 2 Byte long field used to identify the port number of the source.
2. Destination Port: It is a 2 Byte long field, used to identify the port of the destined packet.
3. Length: Length is the length of UDP including the header and the data. It is a 16-bits field.
4. Checksum: Checksum is 2 Bytes long field. It is the 16-bit one’s complement of the one’s complement
sum of the UDP header, the pseudo-header of information from the IP header, and the data, padded
with zero octets at the end (if necessary) to make a multiple of two octets.

Domain Name System

The Domain Name System (DNS) is the hierarchical and decentralized naming system used to identify
computers, services, and other resources reachable through the Internet or other Internet Protocol (IP)
networks. The resource records contained in the DNS associate domain names with other forms of
information. These are most commonly used to map human-friendly domain names to the numerical IP
addresses computers need to locate services and devices using the underlying network protocols, but have
been extended over time to perform many other functions as well. The Domain Name System has been an
essential component of the functionality of the Internet since 1985.

Domain Names

A domain name is an identification string that defines a realm of administrative autonomy, authority or control
within the Internet. Domain names are used in various networking contexts and for application-specific naming
and addressing purposes.

1.3 World Wide Web


The World Wide Web (WWW), commonly known as the Web, is an information system where documents and
other web resources are identified by Uniform Resource Locators (URLs, such as https://example.com/), which
may be interlinked by hyperlinks, and are accessible over the Internet. The resources of the Web are
Unit 1 Page 5 of 44
310252 Web Technology

transferred via the Hypertext Transfer Protocol (HTTP), may be accessed by users by a software application
called a web browser, and are published by a software application called a web server. The World Wide Web
is not synonymous with the Internet, which pre-dated the Web in some form by over two decades and upon the
technologies of which the Web is built.

1.3.1 Hypertext Transport Protocol


The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for
distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for
the World Wide Web, where hypertext documents include hyperlinks to other resources that the user can
easily access, for example by a mouse click or by tapping the screen in a web browser.

1.4 HTTP Request Message

1.4.1 OverallStructure
Every HTTP request message has the same basic structure:

Start line
Header field(s) (one or more)
Blank line
Message body (optional)

1.4.2 HTTP Version


HTTP/1.0 a separate connection to the same server is made for every resource request

HTTP/1.1 instead a TCP connection can be reused to make multiple resource requests (i.e. of HTML pages,
frames, images, scripts, stylesheets, etc.)

HTTP/2 is a revision of previous HTTP/1.1 in order to maintain the same client-server model and the same
protocol methods but with these differences in order: to use a compressed binary representation of metadata
(HTTP headers) instead of a textual one, so that headers require much less space;

HTTP/3 is a revision of previous HTTP/2 in order to use QUIC + UDP transport protocols instead of TCP/IP
connections also to slightly improve the average speed of communications and to avoid the occasional (very
rare) problem of TCP/IP connection congestion that can temporarily block or slow down the data flow of all its
streams (another form of "head of line blocking”).

1.4.3 Request-URI
The second part of the start line is known as the Request-URI. The concatenation of the string http://, the value
of the Host header field (www.example.org, in this example), and the Request-URI (/ in this example) forms a
string known as a Uniform Resource Identifier (URI). A URI is an identifier that is intended to be associated
with a particular resource (such as a web page or graphics image) on the World Wide Web. Every URI
Unit 1 Page 6 of 44
310252 Web Technology

consists of two parts: the scheme, which appears before the colon (:), and another part that depends on the
scheme. Web addresses, for the most part, use the http scheme (the scheme name in URIs is case
insensitive, but is generally written in lowercase letters). 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). Therefore, URIs
using the http scheme are both URIs and URLs.

1.4.4 RequestMethod
1. GET
The GET method is used to retrieve information from the given server using a given URI. Requests using GET
should only retrieve data and should have no other effect on the data.

2. HEAD
Same as GET, but transfers the status line and header section only.

3. POST
A POST request is used to send data to the server, for example, customer information, file upload, etc. using
HTML forms.

4. PUT
Replaces all current representations of the target resource with the uploaded content.

5. DELETE
Removes all current representations of the target resource given by a URI.

6. CONNECT
Establishes a tunnel to the server identified by a given URI.

7. OPTIONS
Describes the communication options for the target resource.

8. TRACE
Performs a message loop-back test along the path to the target resource.

Unit 1 Page 7 of 44
310252 Web Technology

1.4.5 Header Fields and MIME Types


The Host header field is required in every HTTP/1.1 request message. 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.

POST /servlet/EchoHttpRequest HTTP/1.1


host: www.example.org:56789
user-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
Gecko/20030624
accept: text/xml,application/xml,application/xhtml+xml,
text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,
image/gif;q=0.2,*/*;q=0.1
accept-language: en-us,en;q=0.5
accept-encoding: gzip,deflate
accept-charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
connection: keep-alive
keep-alive: 300
content-type: application/x-www-form-urlencoded
content-length: 13

A next common feature is the use of so-called MIME types in several header field values. MIME is an acronym
standing for Multipurpose Internet Mail Extensions, and refers to a standard that can be used to pass a variety
of types of information, including graphics and applications, through e-mail as well as through other Internet
message protocols.

1.5 HTTP Response Message


HTTP response message consists of a status line, header fields, and the body of the response, in the following
format:

Status line
Header field(s) (one or more)
Blank line
Message body (optional)

Unit 1 Page 8 of 44
310252 Web Technology

1.5.1 Response Status Line


This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are issued by a
server in response to a client's request made to the server. It includes codes from IETF Request for Comments
(RFCs), other specifications, and some additional codes used in some common applications of the HTTP. The
first digit of the status code specifies one of five standard classes of responses.

All HTTP response status codes are separated into five classes or categories. The first digit of the status code
defines the class of response, while the last two digits do not have any classifying or categorization role. There
are five classes defined by the standard:

• 1xx informational response – the request was received, continuing process


• 2xx successful – the request was successfully received, understood, and accepted
• 3xx redirection – further action needs to be taken in order to complete the request
• 4xx client error – the request contains bad syntax or cannot be fulfilled
• 5xx server error – the server failed to fulfil an apparently valid request

1.5.2 Response Header Fields

1.5.3 Cache Control


Cache-control is an HTTP header used to specify browser caching policies in both client requests and server
responses. Policies include how a resource is cached, where it’s cached and its maximum age before expiring

Unit 1 Page 9 of 44
310252 Web Technology

1.5.4 Character Sets


A character set defines the mapping between these integers, or code points, and characters. For example,
US-ASCII [RFC-1345] is the character set used to represent the characters used in HTTP header field names,
and is also used in key portions of many other Internet protocols.

1.6 Web Clients


A web client is software that accesses a web server by sending an HTTP request message
and processing the resulting HTTP response. Web browsers running on desktop or laptop
computers are the most common form of web client software,

User Agent

In general, any web client that is designed to directly support user access to web servers is
known as a user agent.

1.6.1 Basic Browser Functions


Bars

The window of a typical modern browser is split into several rectangular regions, most of which are known as
bars.

Client Area

The primary region is the client area, which displays a document.

Title Bar

The title bar displays a title assigned by the document author to the document currently displayed within the
client area.
Unit 1 Page 10 of 44
310252 Web Technology

Menu Bar

The menu bar contains a set of dropdown menus, much like most other applications that incorporate a
graphical user interface (GUI).

Location Bar

The Navigation toolbar also contains a text box, known as the Location bar, where a user can enter a URL and
press the Enter key in order to request the browser to display the document located at the specified URL.

1.6.2 URLs
An http-scheme URL consists of a number of pieces. In order to show the main possibilities, let’s consider the
following example URL:

http://www.example.org:56789/a/b/c.txt?t=win&s=chess#para5

The portion of an http URL following the :// string and before the next slash (/) (or through the completion of the
URL, if there is no trailing slash) is known as the authority of the URL.

1.6.3 User-Controllable Features


Graphical browsers also provide many user-controllable features, including:
1. File|Save Page As
2. Edit|Find in This Page
3. Edit|Save Form Info and Edit|Fill in Form
4. Edit| Preferences
5. Navigator|Languages - Languages for Web Pages
6. Navigator|Languages - Character Coding
7. Advanced| Cache in the Set Cache Options box
8. Advanced|HTTP Networking in the Direct Connection Options
9. Style definition: View|Use Style
Unit 1 Page 11 of 44
310252 Web Technology

10. View|Page Source


11. View|Page Info
12. View|Apply Theme.
13. Go|History
14. Bookmarks

1.6.4 Additional Functionality


1. Automatic URL completion:
2. Script execution
3. Event handling
4. Management of form GUI
5. Secure communication
6. Plug-in execution

1.7 Web Servers


A web server is computer software and underlying hardware that accepts requests via HTTP or its secure
variant HTTPS.

1.7.1 Server Features


• Receive HTTP request via TCP
• Map Host header to specific virtual host (one of many host names sharing an IP address)
• Map Request-URI to specific resource associated with the virtual host
• File: Return file in HTTP response
• Program: Run program and return output in HTTP response
• Map type of resource to appropriate MIME type and use to set Content-Type header in HTTP response
• Log information about the request and response

1.7.2 Server History


• httpd: UIUC, primary Web server c. 1995
• Apache: “A patchy” version of httpd, now the most popular server (esp. on Linux platforms)
• IIS: Microsoft Internet Information Server
• Tomcat:
• Java-based
• Provides container (Catalina) for running Java servlets (HTML-generating programs) as back-end to
Apache or IIS
• Can run stand-alone using Coyote HTTP front-end

Unit 1 Page 12 of 44
310252 Web Technology

Man in the middle Attack


A man-in-the-middle or person-in-the-middle (PITM) attack is a cyberattack where the attacker secretly relays
and possibly alters the communications between two parties who believe that they are directly communicating
with each other, as the attacker has inserted themselves between the two parties.
Having a strong encryption mechanism on wireless access points prevents unwanted users from
joining your network just by being nearby. A weak encryption mechanism can allow an attacker to brute-force
his way into a network and begin man-in-the-middle attacking.

1.8 HTML
HTML stands for Hyper Text Markup Language, which is the most widely used language on Web to develop
web pages. HTML was created by Berners-Lee in late 1991 but "HTML 2.0" was the first standard HTML
specification which was published in 1995. HTML 4.01 was a major version of HTML and it was published in
late 1999. Though HTML 4.01 version is widely used but currently we are having HTML-5 version which is an
extension to HTML 4.01, and this version was published in 2012.

1.8.1 HTML Introduction


HTML is the standard markup language for creating Web pages.

Code Output

<!DOCTYPE html>
<html>
<head>
This is a heading
<title>This is document title</ Hello World!
title>
</head>
<body>
<h1>This is a heading</h1>
<p>Hello World!</p>
</body>
</html>

Applications of HTML

As mentioned before, HTML is one of the most widely used language over the web. I'm going to list few of
them here:
• Web pages development - HTML is used to create pages which are rendered over the web. Almost every
page of web is having html tags in it to render its details in browser.
• Internet Navigation - HTML provides tags which are used to navigate from one page to another and is
heavily used in internet navigation.
• Responsive UI - HTML pages now-a-days works well on all platform, mobile, tabs, desktop or laptops
owing to responsive design strategy.
• Offline support HTML pages once loaded can be made available offline on the machine without any need
of internet.

Unit 1 Page 13 of 44
310252 Web Technology

1.8.2 HTML History


HTML was created by Sir Tim Berners-Lee in late 1991 but was not released officially, published in 1995 as
HTML 2.0. HTML 4.01 was published in late 1999 and was a major version of HTML.

1.8.3 HTML Versions.


• HTML 1.0 was released in 1993 with the intention of sharing information that can be readable and
accessible via web browsers. But not many of the developers were involved in creating websites. So the
language was also not growing.
• Then comes the HTML 2.0, published in 1995, which contains all the features of HTML 1.0 along with that
few additional features, which remained as the standard markup language for designing and creating
websites until January 1997 and refined various core features of HTML.
• Then comes the HTML 3.0, where Dave Raggett who introduced a fresh paper or draft on HTML. It included
improved new features of HTML, giving more powerful characteristics for webmasters in designing web
pages. But these powerful features of new HTML slowed down the browser in applying further
improvements.
• Then comes HTML 4.01, which is widely used and was a successful version of HTML before HTML 5.0,
which is currently released and used worldwide. HTML 5 can be said for an extended version of HTML 4.01,
which was published in the year 2012.

1.9 HTML Elements


An HTML element is defined by a start tag, some content, and an end tag.
The HTML element is everything from the start tag to the end tag:
<tagname>Content goes here...</tagname>
<h1>My First Heading</h1>
<p>My first paragraph.</p>

Start tag Element content End tag


<h1> My First Heading </h1>
<p> My first paragraph. </p>
<br> none none

Nested HTML Elements


<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

</body>
</html>

Unit 1 Page 14 of 44
310252 Web Technology

1.9.1 HTML Headings


HTML headings are titles or subtitles that you want to display on a webpage.

Code Output
<!DOCTYPE html>
<html>
<body>
Heading 1
<h1>Heading 1</h1>
<h2>Heading 2</h2> Heading 2
<h3>Heading 3</h3>
<h4>Heading 4</h4> Heading 3
<h5>Heading 5</h5>
<h6>Heading 6</h6> Heading 4
</body>
</html>
Heading 5

Heading 6

1.9.2 Paragraphs
A paragraph always starts on a new line, and is usually a block of text.
The HTML <p> element defines a paragraph.
A paragraph always starts on a new line, and browsers automatically add some white space (a margin) before
and after a paragraph.

Code Output
<!DOCTYPE html> This is a paragraph.
<html>
<body> This is a paragraph.
This is a paragraph.
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

</body>
</html>

1.9.3 Line Break


Insert single line breaks in a text:

Code Output

Unit 1 Page 15 of 44
310252 Web Technology
<!DOCTYPE html>
<html>
<body>
The br element
To force
<h1>The br element</h1>
line breaks
<p>To force<br> line breaks<br> in in a text,
a text,<br> use the br<br>
element.</p> use the br
element.
</body>
</html>

1.9.4 Colors
HTML colors are specified with predefined color names, or with RGB, HEX, HSL, RGBA, or HSLA values.

There are following three different methods to set colors in your web page −
• Color names − You can specify color names directly like green, blue or red.
• Hex codes − A six-digit code representing the amount of red, green, and blue that makes up the color.
• Color decimal or percentage values − This value is specified using the rgb( ) property.

Code Output
<!DOCTYPE html>
<html>

<head>
<title>HTML Colors by Name</
title>
</head>

<body text = "blue" bgcolor =


"green">
<p>Use different color names
for for body and table and see the
result.</p>

<table bgcolor = "black">


<tr>
<td>
<font color =
"white">This text will appear
white on black background.</font>
</td>
</tr>
</table>
</body>

</html>

1.9.5 Fonts
The <font> tag was used in HTML 4 to specify the font face, font size, and color of text.
Unit 1 Page 16 of 44
310252 Web Technology

Code Output
<!DOCTYPE html>
<html>
This is a paragraph.
<body> This is another
<p style="font paragraph.
family:verdana">This is a
Font size = "-1"
paragraph.</p>
<p style="font-family:'Courier Font size = "+1"
New'">This is another paragraph.</
p>
<font size = "-1">Font size =
Font size = "+2"
"-1"</font><br />
<font size = "+1">Font size = Font size = "+3"
"+1"</font><br />

Font size =
<font size = "+2">Font size
= "+2"</font><br />
<font size = "+3">Font size
= "+3"</font><br />

"+4"
<font size = "+4">Font size
= "+4"</font>
</body>
</html>

1.9.6 Links
The HTML <a> tag defines a hyperlink. It has the following syntax:
<a href="url">link text</a>
The most important attribute of the <a> element is the href attribute, which indicates the link's destination.
The link text is the part that will be visible to the reader.
Clicking on the link text, will send the reader to the specified URL address.

Code Output
<!DOCTYPE html>
<html>
<body>
HTML Links
Visit Google website!
<h1>HTML Links</h1>

<p><a href="https://
www.google.com
website!</a></p>

</body>
</html>

1.9.7 Frames
The <frame> tag was used in HTML 4 to define one particular window (frame) within a <frameset>.

Unit 1 Page 17 of 44
310252 Web Technology
<!DOCTYPE html>
<html>
<body>

<h1>The iframe element</h1>

<iframe src="
title="
</iframe>

</body>
</html>

1.9.8 List
HTML lists allow web developers to group a set of related items in lists.

Code Output
<!DOCTYPE html> An Unordered HTML List
<html>
<body> • Coffee
<h2>An Unordered HTML List</h2>
<ul> • Tea
<li>Coffee</li>
<li>Tea</li> • Milk
<li>Milk</li>
</ul>
<h2>An Ordered HTML List</h2> An Ordered HTML List
<ol>
<li>Coffee</li>
1. Coffee
<li>Tea</li> 2. Tea
<li>Milk</li>
</ol> 3. Milk
</body>
</html>

1.9.9 Tables
Unit 1 Page 18 of 44
310252 Web Technology

HTML tables allow web developers to arrange data into rows and columns.

Code Output
<!DOCTYPE html>
<html>

<head>
<title>HTML Table Header</
title>
</head>

<body>
<table border = "1">
<tr>
<th>Name</th>
<th>Salary</th>
</tr>
<tr>
<td>Ramesh Raman</td>
<td>5000</td>
</tr>

<tr>
<td>Shabbir Hussein</
td>
<td>7000</td>
</tr>
</table>
</body>

</html>

1.9.10 Images
The HTML <img> tag is used to embed an image in a web page.
Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates
a holding space for the referenced image.
The <img> tag is empty, it contains attributes only, and does not have a closing tag.
The <img> tag has two required attributes:
• src - Specifies the path to the image
• alt - Specifies an alternate text for the image

Code Output

Unit 1 Page 19 of 44
310252 Web Technology
<!DOCTYPE html>
<html>
<body>

<h2>Alternative text</h2>

<p>The alt attribute should


reflect the image content, so
users who cannot see the image
gets an understanding of what the
image contains:</p>

<img src="img_chania.jpg"
alt="Flowers in Chania"
width="460" height="345">

</body>
</html>

1.9.11 Forms
An HTML form is used to collect user input. The user input is most often sent to a server for processing.

Code Output
<!DOCTYPE html>
<html>
<body>

<h2>HTML Forms</h2>

<form action="/action_page.php">
<label for="fname">First
name:</label><br>
<input type="text" id="fname"
name="fname" value="John"><br>
<label for="lname">Last
name:</label><br>
<input type="text" id="lname"
name="lname"
value="Blesswin"><br><br>
<input type="submit"
value="Submit">
</form>
</body>
</html>

Unit 1 Page 20 of 44
310252 Web Technology

1.10 CSS
Cascading Style Sheets, fondly referred to as CSS, is a simple design language intended to simplify the
process of making web pages presentable.

1.10.1 Introduction to Style Sheet


CSS handles the look and feel part of a web page. Using CSS, you can control the color of the text, the
style of fonts, the spacing between paragraphs, how columns are sized and laid out, what background
images or colors are used, layout designs, variations in display for different devices and screen sizes as
well as a variety of other effects.
CSS is easy to learn and understand but it provides powerful control over the presentation of an HTML
document. Most commonly, CSS is combined with the markup languages HTML or XHTML.
CSS is designed to make style sheets for the web. It is independent of HTML and can be used with any
XML-based markup language.
Now let’s try to break the acronym:
Cascading: Falling of Styles
Style: Adding designs/Styling our HTML tags
Sheets: Writing our style in different documents

1.10.2 CSS History


1994: First Proposed by Hakon Wium Lie on 10th October
1996: CSS was published on 17th November with influencer Bert Bos
Later he became co-author of CSS
1996: CSS became official with CSS was published in December
1997: Created CSS level 2 on 4th November
1998: Published on 12th May

1.10.3 CSS Editors


Some of the popular editors that are best suited to wire CSS code are as following:
•Atom
•Visual Studio Code
•Brackets
•Espresso(For Mac OS User)
•Notepad++(Great for HTML & CSS)

Unit 1 Page 21 of 44
310252 Web Technology
•Komodo Edit (Simple)
•Sublime Text (Best Editor)

1.10.4 Advantages of CSS


●CSS saves time − You can write CSS once and then reuse same sheet in multiple HTML pages. You
can define a style for each HTML element and apply it to as many Web pages as you want.
●Pages load faster − If you are using CSS, you do not need to write HTML tag attributes every time.
Just write one CSS rule of a tag and apply it to all the occurrences of that tag. So less code means
faster download times.
●Easy maintenance − To make a global change, simply change the style, and all elements in all the
web pages will be updated automatically.
●Superior styles to HTML − CSS has a much wider array of attributes than HTML, so you can give a
far better look to your HTML page in comparison to HTML attributes.
●Multiple Device Compatibility − Style sheets allow content to be optimized for more than one type
of device. By using the same HTML document, different versions of a website can be presented for
handheld devices such as PDAs and cell phones or for printing.
●Global web standards − Now HTML attributes are being deprecated and it is being recommended to
use CSS. So its a good idea to start using CSS in all the HTML pages to make them compatible to
future browsers.

1.10.5 Disadvantages
•Cross-browser related issues
•Vulnerable
•Issues due to multiple levels
•Lack of security
•Fragmentation

1.11 CSS core syntax

1.11.1 import
Perhaps the most commonly used of the at-rules, @import, is used to import an external style sheet into a
document. It can be used to replace the LINK element, and serves the same function, except that imported
style sheets have a lower weight (due to having less proximity) than linked style sheets.

Unit 1 Page 22 of 44
310252 Web Technology
<style type="text/css" media="screen">
@import url(imported.css);
</style>
import url(addonstyles.css);
@import "addonstyles.css";
Relative and absolute URLs are allowed, but only one is allowed per instance of import. One or more
comma-separated target media may be used here.

1.11.2 charset
charset is used to specify the character encoding of a document, and must appear no more than once. It
must be the very first declaration in the external style sheet, and cannot appear in embedded style sheets.

charset is used by XML documents to define a character set. charset "utf-8";

1.11.3 namespace
The namespace rule allows the declaration of a namespace prefix to be used by selectors in a style sheet.
If the optional namespace prefix is omitted, then the URL provided becomes the default namespace. Any
namespace rules in a style sheet must come after all import and charset at-rules, and come before all CSS
rule-sets.

namespace foo url("http://www.example.com/");

namespace can be used together with the new CSS3 selectors (see below). It defines which XML
namespace to use in the CSS. If the XML document doesn't have matching XML namespace information,
the CSS is ignored.

1.11.4 font-face
This was removed from the CSS2.1 specification, but is still used to describe a font face for a document..

font-face
{
font-family: "Scarborough Light";
src: url("http://www.font.com/scarborough-lt");
}

font-face
{
font-family: Santiago;
src: local ("Santiago"), url("http://www.font.com/santiago.tt"),
format("truetype");
unicode-range: U+??,U+100-220;
font-size: all;
font-family: sans-serif;
}

Unit 1 Page 23 of 44
310252 Web Technology

1.11.5 media
This at-rule is used within a style sheet to target specific media. For example, after defining how an element
is to be displayed (in this example for the screen), the declaration can be overwritten for print, in which case
we often want to hide navigation.

p {font-size: 0.8em;} /* for the screen */


@media print { p {font-size: 10pt;} #nav, #footer {display: none;} }
@media screen, handheld { p {font-size: 14px; text-align:
justify;} }

The media types are as follows.

all
aural (for speech synthesisers) handheld
print projection screen braille
embossed tty tv

1.11.6 page
This at-rules declaration is used to define rules for page sizing and orientation rules for printing.

page {size: 15cm 20cm; margin: 3cm; marks: cross;}

You may specify how pages will format if they are first, on the left-hand side, or on the right.

page :first {margin-top: 12cm;} @page :left {margin-left: 4.5cm;}


@page :right {margin-right: 7cm;}

1.11.7 Type Selector


The type selector is the simplest selector of all, and matches all occurrences of an element. In this
example, all <p> tags throughout the document will have the following style applied, unless overridden.

p {color: #666;}

1. Universal Selector

The universal selector, used alone, matches all elements in the document tree, and thus will apply styles to
all elements. It is in effect a wildcard.

* {margin: 0; padding: 0;}

Unit 1 Page 24 of 44
310252 Web Technology

In this example, all tags are reset to have no padding or margin. This, by the way, is a practice to gain
control over all the default padding and margin inherent in the way User Agents (UAs) display HTML.

2. Class Selector

The class selector matches a classname.

.largeFont {font-size: 1.5em;} h3.cartHeader {text-align: center;}

The "largeFont" class will apply to all elements into which it is called. The "cartHeader" class will only
function as styled if called into an H3 element. This is useful if you have another "cartHeader" declaration
that you wish to override in the context of an H3 element, or if you wish to enforce the placement of this
class.

3. ID Selector

The ID selector matches an ID. IDs are identifiers unique to a page. They bear a resemblance to classes,
but are used a bit differently. IDs will be treated more fully below. The first two ID examples below refer to
sections of a web page, while the last refers to a specific occurrence of an item, say, an image in a DHTML
menu. IDs have a higher specificity than classes.

#header {height: 100px;} #footer {color: #F00;} #xyz123 {font-size: 9px;}

4. Descendant Selector

A selector can itself be a chain of one or more selectors, and is thus sometimes called a compound
selector. The descendant selector is the only compound selector in CSS1, and consists of two or more
selectors and one or more white space combinators. In the example below, the white space between the
H1 and EM elements is the descendant combinator. In other words, white space conveys a hierarchy. (If a
comma were to have intervened instead, it would mean that we were styling H1 and EM elements alike.)
Selectors using combinators are used for more precise drill-down to specific points within the document
tree. In this example <em> tags will have the color red applied to them if they are within an <h1> tag.

h1 em {color: #F00;}

Other combinators convey greater precision. They include the direct adjacent sibling combinator (+), the
indirect adjacent sibling (or general) combinator (~), and the child combinator (>).

Example :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<head>
<style type="text/css">

Unit 1 Page 25 of 44
310252 Web Technology
div.ex
{
width:220px;
padding:10px; border:5px solid gray; margin:0px;
}
</style>
</head>

1.12 Characteristics or features of CSS


The major characteristics of CSS include styling rules which are interpreted by the client browser and
applied to various elements in your document. Major characteristics include:

1. A style rule consists of a selector component and a declaration block component.

2. The selector is used to point to the HTML component which you want to get styled.

3. Inside the declaration block, one or more declarations are contained along with semicolons.

4. Every declaration which is put has a CSS property name, a semicolon, and a value. For example,
color is the property, and the value is red in color. Font size is the property, and the 15px is the
value.

5. CSS declaration ends with a semicolon, and these blocks are surrounded by curly braces.

6. CSS selectors are the ones that are used to find HTML elements that are based on the element
name, id, attribute, class, and more.

7. One unique element will be selected by the ID of an element.

8. If you wish to select the particular element with a specific id, the # function along with the id
attribute should be used.

9. If you wish to select the elements with a specific class, the period character along with the name
class should be written.

10. Universal selector: If you are not interested in choosing the elements of a certain type, the
universal selector simply matches the element name.

11. Element selector: These selectors choose the element based on the element name.

12. Descendent selector: When a particular element lies inside another element, then it is called as
the descendent selector.

Unit 1 Page 26 of 44
310252 Web Technology

13. ID selector: This selector uses the id of the HTML element so that a specific element could be
selected.

14. Class selectors: It selects the element with a specific class attribute.

15. Grouping selectors: It will be a good option to group the selectors so as to minimize the code.
Each selector, along with a comma, should be used to group the selectors.

1.13 Style Sheets and Html Style Rule


To apply a style, CSS uses the HTML document tree to match an element, attribute, or value in an HTML
file. For an HTML page to properly use CSS, it should be well-formed and valid, and possess a valid
doctype. If these conditions are not met the CSS match may not yield the desired results.

There are two types of CSS statements:

•rule-sets

•at-rules.

A rule set, also known simply as a rule, is the more common statement, and consists of a selector and a
declaration block, sometimes simply called a block. The selector can be an element, class, or ID, and may
include combinators, pseudo-elements, or pseudo-classes.

Cascading Style Sheets (CSS) describe how documents are presented on screens, in print, or perhaps
how they are pronounced. W3C has actively promoted the use of style sheets on the Web since the
consortium was founded in 1994.

Cascading Style Sheets (CSS) provide easy and effective alternatives to specify various attributes for the
HTML tags. Using CSS, you can specify a number of style properties for a given HTML element. Each
property has a name and a value, separated by a colon (:). Each property declaration is separated by a
semi-colon (;).

Example

First let's consider an example of HTML document which makes use of <font> tag and associated attributes
to specify text color and font size −

<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>

Unit 1 Page 27 of 44
Dr. D. Y. Patil Institute of Technology 310252 Web Technology
</head>
<body>
<p><font color = "green" size = "5">Hello, World! </font></p>
</body>
</html>

We can re-write above example with the help of Style Sheet as follows −

<!DOCTYPE html>
<html>
<head>
<title>HTML CSS</title>
</head>
<body>
<p style = "color:green; font-size:24px;" >Hello, World!</p>
</body>
</html>

This will produce the following result −

Hello, World!
Three ways of CSS in HTML document

1.External Style Sheet − Define style sheet rules in a separate .css file and then include that file in your
HTML document using HTML <link> tag.

2.Internal Style Sheet − Define style sheet rules in header section of the HTML document using <style>
tag.

3.Inline Style Sheet − Define style sheet rules directly along-with the HTML elements using style
attribute.

Let's see all the three cases one by one with the help of suitable examples.

1.13.1 External Style Sheet


If you need to use your style sheet to various pages, then its always recommended to define a common
style sheet in a separate file. A cascading style sheet file will have extension as .css and it will be included
in HTML files using <link> tag.

Example

Consider we define a style sheet file style.css which has following rules −
Unit 1 Page 28 of 44
310252 Web Technology

.red {
color: red;
}
.thick {
font-size:20px;
}
.green {
color:green;
}

Here we defined three CSS rules which will be applicable to three different classes defined for the HTML
tags. I suggest you should not bother about how these rules are being defined because you will learn them
while studying CSS. Now let's make use of the above external CSS file in our following HTML document −

<!DOCTYPE html>
<html>
<head>
<title>HTML External CSS</title>
<link rel = "stylesheet" type = "text/css" href = "/html/
style.css">
</head>
<body>
<p class = "red">This is red</p>
<p class = "thick">This is thick</p>
<p class = "green">This is green</p>
<p class = "thick green">This is thick and green</p>
</body>
</html>

This will produce the following result −

This is red

This is thick
This is green

This is thick and green

Unit 1 Page 29 of 44
310252 Web Technology

1.13.2 Internal Style Sheet


If you want to apply Style Sheet rules to a single document only, then you can include those rules in header
section of the HTML document using <style> tag.

Rules defined in internal style sheet overrides the rules defined in an external CSS file.

Example

Let's re-write above example once again, but here we will write style sheet rules in the same HTML
document using <style> tag −

<!DOCTYPE html>
<html>
<head>
<title>HTML Internal CSS</title>
<style type = "text/css">
.red {
color: red;
}
.thick{
font-size:20px;
}
.green {
color:green;
}
</style>
</head>
<body>
<p class = "red">This is red</p>
<p class = "thick">This is thick</p>
<p class = "green">This is green</p>
<p class = "thick green">This is thick and green</p>
</body>
</html>

This will produce the following result −

This is red
This is thick

Unit 1 Page 30 of 44
310252 Web Technology

This is green
This is thick and green

1.13.3 Inline Style Sheet


You can apply style sheet rules directly to any HTML element using style attribute of the relevant tag. This
should be done only when you are interested to make a particular change in any HTML element only.

Rules defined inline with the element overrides the rules defined in an external CSS file as well as the rules
defined in <style> element.

Example

Let's re-write above example once again, but here we will write style sheet rules along with the HTML
elements using style attribute of those elements.

<!DOCTYPE html>
<html>
<head>
<title>HTML Inline CSS</title>
</head>
<body>
<p style = "color:red;">This is red</p>
<p style = "font-size:20px;">This is thick</p>
<p style = "color:green;">This is green</p>
<p style = "color:green;font-size:20px;">This is thick and
green</p>
</body>
</html>

This will produce the following result −

This is red
This is thick
This is green
This is thick and green

Unit 1 Page 31 of 44
310252 Web Technology

1.14 Style rule cascading and inheritance


CSS are probably wondering what exactly cascades about cascading style sheets. In this section we look
at the idea of cascading, and a related idea, that of inheritance. Both are important underlying concepts that
you will need to grasp, and understand the difference between, in order to work properly with style sheets.

1.14.1 Rule Cascade


A single style sheet associated with one or more web pages is valuable, but in quite a limited way. For
small sites, the single style sheet is sufficient, but for larger sites, especially sites managed by more than
one person (perhaps several teams who may never communicate) single style sheets don't provide the
ability to share common styles, and extend these styles where necessary. This can be a significant
limitation. Cascading style sheets are unlike the style sheets you might have worked with using word
processors, because they can be linked together to create a hierarchy of related style sheets.

1.Font Family

The font family of a text is set with the font-family property. The font-family property should hold several font
names as a "fallback" system. If the browser does not support the first font, it tries the next font. Start with
the font you want, and end with a generic family, to let the browser pick a similar font in the generic family, if
no other fonts are available.

Example

p{font-family:"Times New Roman", Times, serif;}

1.Font Style

The font-style property is mostly used to specify italic text. This property has three values:

a.normal - The text is shown normally

b.italic - The text is shown in italics

c.oblique - The text is "leaning" (oblique is very similar to italic, but less supported)

d.Font Size

The font-size property sets the size of the text. Being able to manage the text size is important in web
design. However, you should not use font size adjustments to make paragraphs look like headings, or
headings look like paragraphs. Always use the proper HTML tags, like <h1> - <h6> for headings and <p>
for paragraphs. The font-size value can be an absolute, or relative size.

1.Absolute size:
Unit 1 Page 32 of 44
310252 Web Technology

◊Sets the text to a specified size


◊Does not allow a user to change the text size in all browsers (bad for accessibility
reasons)

◊Absolute size is useful when the physical size of the output is known

1.Relative size:

◊Sets the size relative to surrounding elements

◊Allows a user to change the text size in browsers

a.The CSS Box Model

All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about
design and layout.

The CSS box model is essentially a box that wraps around HTML elements, and it consists of:

oMargin - Clears an area around the border. The margin does not have a background color, it is
completely transparent

oBorder - A border that goes around the padding and content. The border is affected by the
background color of the box

oPadding - Clears an area around the content. The padding is affected by the background color of
the box

oContent - The content of the box, where text and images appear

In order to set the width and height of an element correctly in all browsers, you need to know how the box
model works.

a.CSS Background

CSS background properties are used to define the background effects of an element. CSS properties used
for background effects:

oBackground Color

The background-color property specifies the background color of an element. The background color of a
page is defined in the body selector:

Unit 1 Page 33 of 44
310252 Web Technology

Example
body {background-color:#b0c4de;}

The background color can be specified by:

name - a color name, like "red"

RGB - an RGB value, like "rgb(255,0,0)" Hex - a hex value, like "#ff0000"\

oBackground Image

The background-image property specifies an image to use as the background of an element. By default,the
image is repeated so it covers the entire element. The background image for a page can be set likethis:
Example

body {background-image:url('paper.gif');}

By default, the background-image property repeats an image both horizontally and vertically. Some images
should be repeated only horizontally or vertically, or they will look strange, like this: Example

Body {background-image:url('gradient2.png');}

If the image is repeated only horizontally (repeat-x), the background will look better: Example

body{background-image:url('gradient2.png'); background
repeat:repeat-x;}

1.15 Text properties


CSS has a lot of properties for formatting text.

oText Color

oText Alignment

oText Decoration

oText Transformation

oText Spacing

oText Shadow

1.15.1 Text Color


1. color: The color property is used to set the color of the text. The color is specified by:

a color name - like "red"

Unit 1 Page 34 of 44
310252 Web Technology

a HEX value - like "#ff0000"

an RGB value - like "rgb(255,0,0)"

Look at CSS Color Values for a complete list of possible color values. The default text color for a page is
defined in the body selector.

Example

body {
color: blue;
}
h1 {
color: green;
}

2. background-color:

In this example, we define both the background-color property and the color property:

Example

body {
background-color: lightgrey;
color: blue;
}
h1 {
background-color: black;
color: white;
}
div {
background-color: blue;
color: white;
}

Important: High contrast is very important for people with vision problems. So, always ensure that the
contrast between the text color and the background color (or background image) is good!

1.15.2 Text Alignment


The text-align property is used to set the horizontal alignment of a text. A text can be left or right aligned,
centered, or justified. The following example shows center aligned, and left and right aligned text (left

Unit 1 Page 35 of 44
310252 Web Technology

alignment is default if text direction is left-to-right, and right alignment is default if text direction is right-to-
left):

Example

h1 {
text-align: center;
}

h2 {
text-align: left;
}

h3 {
text-align: right;
}

When the text-align property is set to "justify", each line is stretched so that every line has equal width, and
the left and right margins are straight (like in magazines and newspapers):

Example

div {
text-align: justify;
}

Text Align Last

The text-align-last property specifies how to align the last line of a text.

Example

Align the last line of text in three <p> elements:

p.a {
text-align-last: right;
}
p.b {
text-align-last: center;
}
p.c {
text-align-last: justify;
}
Unit 1 Page 36 of 44
310252 Web Technology

Text Direction
The direction and unicode-bidi properties can be used to change the text direction of an element:

Example

p {
direction: rtl;
unicode-bidi: bidi-override;
}

Vertical Alignment

The vertical-align property sets the vertical alignment of an element.

Example

img.a {
vertical-align: baseline;
}
img.b {
vertical-align: text-top;
}
img.c {
vertical-align: text-bottom;
}
img.d {
vertical-align: sub;
}
img.e {
vertical-align: super;
}

1.15.3 Text Decoration


The text-decoration property is used to set or remove decorations from text.

The value text-decoration: none; is often used to remove underlines from links:

Example

a {
text-decoration: none;
Unit 1 Page 37 of 44
310252 Web Technology
}

The other text-decoration values are used to decorate text:

Example

h2 {
text-decoration: overline;
}
h3 {
text-decoration: line-through;
}
h4 {
text-decoration: underline;
}

Note: It is not recommended to underline text that is not a link, as this often confuses the reader.

1.15.4 Text Transformation


The text-transform property is used to specify uppercase and lowercase letters in a text. It can be used to
turn everything into uppercase or lowercase letters, or capitalize the first letter of each word:

Example

p.uppercase {
text-transform: uppercase;
}
p.lowercase {
text-transform: lowercase;
}
p.capitalize {
text-transform: capitalize;
}

1.15.5 Text Spacing


1. Text Indentation

The text-indent property is used to specify the indentation of the first line of a text:

Example

p {

Unit 1 Page 38 of 44
310252 Web Technology
text-indent: 50px;
}

2. Letter Spacing

The letter-spacing property is used to specify the space between the characters in a text.

The following example demonstrates how to increase or decrease the space between characters:

Example

h1 {
letter-spacing: 5px;
}
h2 {
letter-spacing: -2px;
}

3. Line Height

The line-height property is used to specify the space between lines:

Example

p.small {
line-height: 0.8;
}
p.big {
line-height: 1.8;
}

4. Word Spacing

The word-spacing property is used to specify the space between the words in a text. The following example
demonstrates how to increase or decrease the space between words:

Example

p.one {
word-spacing: 10px;
}
p.two {
word-spacing: -2px;
}

5. White Space
Unit 1 Page 39 of 44
310252 Web Technology

The white-space property specifies how white-space inside an element is handled. This example
demonstrates how to disable text wrapping inside an element:

Example

p {
white-space: nowrap;
}

1.15.6 Text Shadow


The text-shadow property adds shadow to text. In its simplest use, you only specify the horizontal shadow
(2px) and the vertical shadow (2px):

Example

h1 {

text-shadow: 2px 2px;

Next, add a color (red) to the shadow:

Example

h1 {

text-shadow: 2px 2px red;

Then, add a blur effect (5px) to the shadow:

1.16 Bootstrap

•Bootstrap is a free front-end framework for faster and easier web development

•Bootstrap includes HTML and CSS based design templates for typography, forms, buttons, tables,
navigation, modals, image carousels and many other, as well as optional JavaScript plugins

Unit 1 Page 40 of 44
310252 Web Technology

•Bootstrap also gives you the ability to easily create responsive designs
1.16.1 Responsive Web Design
•Responsive web design is about creating web sites which automatically adjust themselves to look
good on all devices, from small phones to large desktops.

Example

<div class="jumbotron text-center">


<h1>My First Bootstrap Page</h1>
<p>Resize this responsive page to see the effect!</p>
</div>

<div class="container">
<div class="row">
<div class="col-sm-4">
<h3>Column 1</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 2</h3>
<p>Lorem ipsum dolor..</p>
</div>
<div class="col-sm-4">
<h3>Column 3</h3>
<p>Lorem ipsum dolor..</p>
</div>
</div>
</div>

1.16.2 Advantages of Bootstrap:


•Easy to use: Anybody with just basic knowledge of HTML and CSS can start using Bootstrap

•Responsive features: Bootstrap's responsive CSS adjusts to phones, tablets, and desktops

•Mobile-first approach: In Bootstrap, mobile-first styles are part of the core framework

•Browser compatibility: Bootstrap 4 is compatible with all modern browsers (Chrome, Firefox,
Internet Explorer 10+, Edge, Safari, and Opera)

1.16.3 Installation
There are two ways to start using Bootstrap 4 on your own web site.

a.Include Bootstrap 4 from a CDN

b.Download Bootstrap 4 from getbootstrap.com

Unit 1 Page 41 of 44
310252 Web Technology

If you don't want to download and host Bootstrap 4 yourself, you can include it from a CDN (Content
Delivery Network). jsDelivr provides CDN support for Bootstrap's CSS and JavaScript. You must also
include jQuery:

<!-- Latest compiled and minified CSS -->


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/
bootstrap@4.6.1/dist/css/bootstrap.min.css">

<!-- jQuery library -->


<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/
jquery.slim.min.js"></script>

<!-- Popper JS -->


<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/
umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->


<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/
js/bootstrap.bundle.min.js"></script>

1.16.4 Create First Web Page with Bootstrap 4


1. Add the HTML5 doctype

Bootstrap 4 uses HTML elements and CSS properties that require the HTML5 doctype. Always
include the HTML5 doctype at the beginning of the page, along with the lang attribute and the
correct character set:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
</html>

2. Bootstrap 4 is mobile-first

Bootstrap 4 is designed to be responsive to mobile devices. Mobile-first styles are part of the core
framework.

To ensure proper rendering and touch zooming, add the following <meta> tag inside the
<head> element:

Unit 1 Page 42 of 44
310252 Web Technology
<meta name="viewport" content="width=device-width, initial-scale=1">

The width=device-width part sets the width of the page to follow the screen-width of the device
(which will vary depending on the device).

The initial-scale=1 part sets the initial zoom level when the page is first loaded by the browser.

3. Containers

Bootstrap 4 also requires a containing element to wrap site contents. There are two container classes to
choose from:
•The .container class provides a responsive fixed width container
•The .container-fluid class provides a full width container, spanning the entire width of the viewport
The following example shows the code for a basic Bootstrap 4 page (with a responsive fixed width container):

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/
bootstrap@4.6.1/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/
jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/
umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/
js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>
</body>
</html>

Output

Unit 1 Page 43 of 44
310252 Web Technology

The following example shows the code for a basic Bootstrap 4 page (with a full width container):

<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap 4 Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/
bootstrap@4.6.1/dist/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/
jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/
umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/
js/bootstrap.bundle.min.js"></script>
</head>
<body>

<div class="container-fluid">
<h1>My First Bootstrap Page</h1>
<p>This is some text.</p>
</div>

</body>
</html>

Output

Unit 1 Page 44 of 44

You might also like