Web Engineering CHP 1
Web Engineering CHP 1
A Complicated Ecosystem
The model shows web development as a three story building. Each floor depicts
several aspects of web development with an illustration.
Ground floor shows Servers, configuration, Networks and Protocols which are the
basic building blocks
Middle floor shows different languages which are a part of web development like
HTML, CSS, PHP, JavaScript, databases, APIs and Tools.
Top level shows advanced concepts like Design, Search, integration, Frameworks and
Security
Internet vs Web
Internet is the hardware part. It is collection of computer networks connected
through either copper wires, fiber optic cables or wireless connections
World wide web can be termed as the software part. It is a collection of web
pages connected through hyperlinks and URLs. In short, the web is one of the
services provided by the internet. Other services over the internet include
email, file transfer services (FTP) etc. all of the services can be provided to
consumers for use by business or government
Web 2.0
Web 2.0 is mainly characterized by;
• User Generated Content (UGC)
• Dynamic websites
In the mid-2000s, a new buzzword entered the computer lexicon: Web 2.0.
This term had two meanings, one for user and one for developers.
For the users, Web 2.0 referred to an interactive experience where users could
contribute and consume web content, thus creating a more user driven web
experience. Some of the most popular websites today fall into this category:
Facebook, YouTube, and Wikipedia. This shift to allow feedback from the user, such
as comments on a story, threads in a message board, or a profile on a social
networking site has revolutionized what it means to use a web application.
For software developers, Web 2.0 also referred to a change in the paradigm of how
dynamic websites are created. Programming logic, which previously existed only on
the server, began to migrate to the browser. This required learning JavaScript, a
rather tricky programming language that runs in the browser, as well as mastering
the rather difficult programming techniques involved in asynchronous
communication.
Web 3.0
It mainly characterized by:
• Machine understandable contents
• Semantic web
Web Science
Web science as it is known, studies the sociotechnical systems that apply the web is
areas as diverse as finance, politics, activism, romance, and hate speech. If you look
at each interaction on the web as more than just a technical exchange using
protocols and file transmission, you can see there is often an underlying social need
motivating each exchange. The technical system facilitates a social interaction and
social interactions span nearly the entire human experience, so there is now an
entire area of study looking at the web as a sociotechnical system.
Web Engineering Chp 1 Page 6
entire area of study looking at the web as a sociotechnical system.
This is just another example of how the web can facilitate entirely new areas of
study.
Server Types
Most real-world websites are typically not served from a single server machine, but by many server machines. It
is common to split the functionality of a website between several different types of server, as shown in following
figure. These include the following:
1. Web servers
A web server is a computer servicing HTTP requests. This typically refers to a computer running web server
software, such as Apache or Microsoft IIS (Internet Information Services).
2. Application servers
An application server is a computer that hosts and executes web applications, which may be created in
PHP, [Link], Ruby on Rails, or some other web development technology.
3. Database servers
A database server is a computer that is devoted to running a Database Management System (DBMS), such
as MySQL, Oracle, or MongoDB, that is being used by web applications.
4. Mail servers
A mail server is a computer creating and satisfying mail requests, typically using the Simple Mail Transfer
Protocol (SMTP).
5. Media servers
A media server (also called a streaming server) is a special type of server dedicated to servicing requests for
images and videos. It may run special software that allows video content to be streamed to clients.
5. Authentication servers
An authentication server handles the most common security needs of web applications. This may involve
interacting with local networking resources, such as LDAP (Lightweight Directory Access Protocol) or Active
Directory.
Server Farms
A single web server that is also acting as an application or database server will be hard-pressed to handle more
than a few hundred requests a second. A busy site can receive thousands or even tens of thousands of requests
a second; globally popular sites such as Facebook receive millions of requests a second.
The usual strategy for busier sites is to use a server farm. The goal behind server farms is to distribute incoming
requests between clusters of machines so that any given web or data server is not excessively overloaded, as
shown in following figure. Special devices called load balancers distribute incoming requests to available
machines.
Server Racks
In a server farm, the computers do not look like the ones in your house. Instead, these computers are more like
the plates stacked in your kitchen cabinets. That is, a farm will have its servers and hard drives stacked on top of
each other in server racks. A typical server farm will consist of many server racks, each containing many servers,
as shown in following figure.
The broadband modem, also called a cable modem or DSL (digital subscriber line) modem, is a bridge between the network hardware
outside the house (typically controlled by a phone or cable company) and the network hardware inside the house. The wireless router
is perhaps the most visible manifestation of the Internet in one's home.
The various neighborhood broadband cables are aggregated and connected to fiber optic cable via fiber connection boxes.
These fiber optic cables eventually make their way to an ISP's head-end, which is a facility that may contain a cable modem
termination system (CMTS) or a digital subscriber line access multiplexer (DSLAM) in a DSL based system. This is a special type of very
large router that connects and aggregates subscriber connections to the larger Internet. These different headends may connect
directly to the wider Internet, or instead be connected to a master head-end, which provides the connection to the rest of the Internet.
Routing Tables
The flow of internet traffic or information is carried out mainly by routers. A router is a hardware device that forwards data packets
from one network to another network. When the router receives a data packet, it examines the packet's destination address and then
forwards it to another destination. A router uses a routing table to help determine where a packet should be sent. It is a table of
connections between target addresses and the destination (typically another router) to which the router can deliver the packet. In
following figure, the different routing tables use next-hop routing, in which the router only knows the address of the next step of the
path to the destination; it leaves it to that next step to continue the routing process. The packet thus makes a variety of successive
hops until it reaches its destination.
within a country to interconnect and between different countries. More and more networks began to interconnect with each other
using an Internet exchange point (IX or IXP). Multiple paths between IXPs provide a powerful way to handle outages and keep packets
Under-ocean connectivity
Eventually, international Internet communication will need to travel underwater. The amount of undersea fiber optic cable is quite
staggering and is growing yearly. As can be seen in following figure, over 250 undersea fiber optic cable systems operated by a variety
of different companies span the globe.
2. System Administrator
Once the system is built and wired to the network, system administrators are the next people required to get things up and running. Often they
choose and install the network operating system, then manage the shared operating system environments for other users. This position is often
combined with the hardware architect in smaller firms.
4. Security Specialist/Consultant/Expert
A good system administrator and network architect will certainly have insights into security as they perform their duties. However, because security
is so vital to web development in general, and because the knowledge necessary to do security work is complicated and ever changing, it is not
uncommon for companies to outsource their security needs to security specialists. These specialists will test for vulnerabilities, implement security
best practices, and make updates and changes to programming code or hardware infrastructure to protect a site against well-known or newly
emerging (called zero hour) threats.
5. Developer/Programmer
Programmers can be assigned a wide range of tasks aside from simple coding. Writing good documentation, using version control software, engaging
in code reviews, running test cases, and more might be typical tasks, depending on company practices. Programmer positions often begin at the
entry level, with higher-level design decisions left to software engineers and senior developers. In terms of the web development world, the terms
programmers or developer are quite broad; typically, however, this term is used to indicate a job focused more on server-side development using
languages like PHP.
7. Software Engineer
A software engineer is a programmer who is adept at the language of analysis and design, and uses established best practices in the development of
software. Sometimes the role of a programmer and software engineer are used interchangeably, but a software engineer has more knowledge of the
software development life cycle and can effectively gather requirements and speak with clients about technical and business matters.
9. Tester/Quality Assurance
Testers are the people who try to identify flaws in software before it gets released. This type of work is often called quality assurance (QA). Although
some test roles are for nonexperts, many testers know how to program and might write automated tests as well as develop testing plans from
requirements. Although these duties are often integrated with developers, they can form a job all their own.
2. Design Companies
Design companies are at the opposite end of the spectrum, with few technical positions available. These firms will provide professional artistic and
design services that might go beyond the web and include logos and branding in general. Some companies produce mockups in Photoshop, for
example, which a web developer (at another company) can then turn into a website.
5. Start-Up Companies
Start-up ventures in web development have been some of the biggest success stories in the business world. Start-ups are often attractive places for
new graduates to work, with less competition from experienced candidates and potentially lots of jobs available from developers to designers and
system administrators. The smaller start-ups companies often require full-stack developers, who can take on any role from system administrator
through to lead developer.
IP-Address
There are two types of IP addresses: IPv4 and IPv6. IPv4 addresses are the IP addresses from the original TCP/IP protocol. In IPv4, 12 numbers
are used (implemented as four 8-bit integers), written with a dot between each integer (see following figure). Since an unsigned 8-bit integer's
The decision to make IP addresses 32 bits limited the number of hosts to 4.2 billion. As more and more devices connected to the Internet the
supply of addresses dwindled, especially in some local areas that had already distributed their allotment.
To future-proof the Internet against the 4.2 billion limit, a new version of the IP protocol was created, IPv6. This newer version uses eight 16-bit
integers for 2128 unique addresses, over a billion billion times the number in IPv4. These 16-bit integers are normally written in hexadecimal,
due to their longer length.
3. Transport Layer
The transport layer ensures transmissions arrive in order and without error. This is accomplished through a few mechanisms. First, the data is
broken into packets formatted according to the Transmission Control Protocol (TCP). Each data packet has a header that includes a sequence
number, so the receiver can put the original message back in order, no matter when they arrive. Secondly, each packet acknowledges its
successful arrival back to the sender so in the event of a lost packet, the transmitter will realize a packet has been lost since no ACK arrived for
that packet. That packet is retransmitted, and although out of order, is reordered at the destination, as shown in following figure. This means
you have a guarantee that messages sent will arrive and will be in order.
Sometimes we do not want guaranteed transmission of packets. Consider a live multicast of a soccer game, for example. Millions of subscribers
may be streaming the game, and the broadcaster can't afford to track and retransmit every lost packet. A small loss of data in the feed is
acceptable, and the customers will still see the game. An Internet protocol called User Datagram Protocol (UDP) is used in these scenarios in
lieu of TCP. Other examples of UDP services include Voice Over IP, many online games, and Domain Name System (DNS).
4. Application Layer
Application layer protocols implement process-to-process communication and are at a higher level of abstraction in comparison to the low-
level packet and IP address protocols in the layers below it. There are many application layer protocols. A few that are useful to
web developers include the following:
A domain name can be broken down into several parts. They represent a hierarchy, with the rightmost parts being closest to the root at the
“top” of the Internet naming hierarchy. All domain names have at least a top-level domain (TLD) name and a second-level domain (SLD) name.
Most websites also maintain a third-level WWW subdomain and perhaps others. Following figure illustrates a domain with four levels.
Domain registration
Special organizations or companies called domain name registrars manage the registration of domain names. These domain name registrars
are given permission to do so by the appropriate generic top-level domain (gTLD) registry and/or a country code top-level domain (ccTLD)
registry. In the 1990s, a single company (Network Solutions Inc.) handled the com, net, and org registries. By 1999, the name registration
system changed to a market system in which multiple companies could compete in the domain name registration business. A single
organization—the nonprofit Internet Corporation for Assigned Names and Numbers (ICANN)—still oversees the management of top-level
domains, accredits registrars, and coordinates other aspects of DNS. At the time of writing this chapter, there were almost 1000 different
ICANN-accredited registrars worldwide. Following figure illustrates the process involved in registering a domain name.
Address Resolution
While domain names are certainly an easier way for users to reference a website, eventually your browser needs to know the IP address of the
website in order to request any resources from it. DNS provides a mechanism for software to discover this numeric IP address. This process is
referred to as address resolution. When you request a domain name, a computer called a domain name server will return the IP address for
that domain. With that IP address, the browser can then make a request for a resource from the web server for that domain. What actually
happens during address resolution is more complicated, as can be seen in following figure.
1. The resolution process starts at the user's computer. When the URL [Link] is requested (perhaps by clicking a link or typing it
in), the browser will begin by seeing if it already has the IP address for the domain in its cache. If it does, it can jump to step in the diagram.
2. If the browser doesn't know the IP address for the requested site, it will delegate the task to the DNS resolver, a software agent that is part
of the operating system. The DNS resolver also keeps a cache of frequently requested domains; if the requested domain is in its cache, then the
process jumps to step .
3. Otherwise, it must ask for outside help, which in this case is a nearby DNS server, a special server that processes DNS requests. This might be
a computer at your Internet service provider (ISP) or at your university or corporate IT department. The address of this local DNS server is
usually stored in the network settings of your computer's operating system. This server keeps a more substantial cache of domain name/IP
address pairs. If the requested domain is in its cache, then the process jumps to step .
4. If the local DNS server doesn't have the IP address for the domain in its cache, then it must ask other DNS servers for the answer. Thankfully,
1. Protocol
This part describes the protocol through which a web-page is accessed. When
we open a website, we need to specify the protocol first. Most of the unsecured
websites are accessed through HTTP protocol while in the case of secured
websites, HTTPS protocol is used. Web browsers also support other protocols.
For example, FTP protocol is used for accessing files.
2. Domain
The address of a website is called domain. Domain consists of top-level domain,
country code top-level domain, second level domain, third level domain etc.
Domain name Server finds IP address against this name and this website can be
accessed using that IP address.
Port: It is an optional part of a URL. Usually, it is not visible. Most of the times,
HTTP servers listen at port 80. A colon is added after domain name and then
integer port number is specified.
3. Path
After domain, the path, of the file we want to access, is specified. In figure 1,
[Link] is path of a file being accessed. When path is not mentioned, default
files like [Link] or [Link] are returned.
4. Query String
It is an information passed to the file. Query strings are mostly used in dynamic
websites. Information in query string is sent to server in the form of key value
pairs. It starts from delimiter ‘?’, and if there are more than one keys in a query
string, they are separated using ‘&’. Query string is page=17.
Browser Caching
When we visit a website and fetch some images and files from it, they are stored in
browser cache. Next time, when we need that file from the same server, the file will
be retrieved from browser cache instead of server, resulting in fast browsing.
Caching can also be disabled to avoid caching, like done in banking websites.
Browser Extensions
Extensions can modify the page being rendered. They are designed for specific
purposes. For example, extensions like ‘Lighthouse’ and ‘React developer tools’ are
very useful for developers while extensions like ‘Adblock’ and ‘Third Party Plugins’
are used by general public.
1. Application Stacks
The most commonly used application stack is LAMP which contains Linux operating
system, Apache web server, MySQL database, and PHP scripting language. It is
traditionally used for dynamic websites. There are other stacks as well. For example,
WAMP, WISA, and MEAN. Therefore, a full-stack developer is supposed to have
expertise of working on operating system, web server, frontend development, and
backend development.
2. Operating Systems
Mostly used operating systems are Linux, Mac, and Windows.
4. Database software
Relational databases like MySQL, PostgreSQL, and Sqlite are mostly used. However,
document based databases are also being used these days. One important example
of document based databases is MongoDB.
5. Scripting languages
The content of a dynamic website can be generated in almost every scripting
language. However, PHP is world-wide used for this purpose. These days, [Link],
Python, and [Link] are also being used as scripting languages.
Multi-tier architecture
Web development can be realized at multiple tiers.
1. 2-tier architecture
When we access a website, at least 2-tiers are created i.e.
a. Client-side tier
b. Server-side tier
2. 3-tier architecture
In software engineering perspective, these tiers can be broken down to further tiers.
In 3-tier architecture
a. First tier is responsible for content display (Presentation Layer)
b. Second tier is business logic for generating dynamic content (Functional
Logic Layer)
c. Third tier is database layer which stores data and manages database.
(Database Management Layer)
The advantage of separating presentation and business logic layers is that when we
change business logic for some users, we do not need to change presentation layer
necessarily.
HTML validator, a tool of W3C, is used to identify errors in an HTML page and give
recommendations in the form of warnings.
15.1 HTML5
It is the latest version of HTML supported by all of the modern browsers.
HTML Tags
HTML is only used for structuring and storing content. It is not used for styling but
style sheets can be used for this purpose. Common HTML tags are explained below.
1. DOCTYPE
This tag is used to inform web server and browser that the document is an
HTML document. It is written in the start of document. Its syntax is <!DOCTYPE
html>.
2. Head and Body tags
External files, document title, and meta data about document are mentioned in
the ‘head’ tag. The contents of document are mentioned in the ‘body’ tag.
Earlier, parent ‘html’ tag was necessary but this compulsion has been removed
in HTML5. However, most developers still use this tag.
3. Meta Tag
This tag contains information about coding details of HTML contents.
4. Link Tag
This tag is used to link the external styles sheets to an HTML document.
5. Script Tag
To specify a certain script from an external file, script tag is used.
6. Heading Tag
HTML provides six levels of headings (h1 - h6). Headings are also used by the
browser to create a document outline for the page. It is recommended not to
use different headings for setting font size.
7. Paragraphs and Divisions
Paragraph is a container for text and other HTML elements. <p> tag is used of
paragraph.
Divisions are used to create a logical grouping of content. It is also a container
element, and <div> tag is used for division. Following figure demonstrates a
paragraph tag.
Entity Description
Nonbreakable space
< <
> >
© ©
Links
Links are an essential feature of all web pages. Links are created using the element
(the “a” stands for anchor). It has two main parts: the destination and the label.
Lists
HTML provides three types of lists which are explained below.
1. Unordered list
2. Ordered list
3. Description list
4. Nested list
1. Unordered lists
Collections of items in no particular order is called unordered list. These are by
default rendered by the browser as a bulleted list. However, it is common in CSS
to style unordered lists without the bullets. Unordered lists have become the
conventional way to markup navigational menus.
2. Ordered lists
Collections of items that have a set order is called ordered list. These are by
default rendered by the browser as a numbered list.
4. Description lists
Collection of name and description/definition pairs is called a description list.
There are many more semantic HTML tags to use as you build a standards-compliant
website.
1. Advantages Semantic Structuring
Eliminating presentation-oriented markup and writing semantic HTML markup has a
variety of important advantages:
1. Maintainability.
Web pages with a lot of presentation markup are more difficult to edit and change
than those with semantic markup. Our students are frequently startled to hear that
maintaining and altering old code takes more time than writing new code. This is
especially true for web initiatives. Web projects, in our experience, incur more
"requirements drift" because of end user and customer input than traditional
software development projects.
2. Performance.
Semantic web pages are typically quicker to author and faster to download.
3. Accessibility.
The content on web pages is not accessible to all web users. Voice reading software
is used by users with vision problems to use the internet. If a website does not
employ semantic markup, visiting it with speech reading software might be an
extremely irritating experience. Many governments also require that websites for
organizations that receive federal support follow particular accessibility criteria. The
US government, for example, maintains its own set of Section 508 Accessibility
Guidelines ([Link]
2. Header Tag
The header of a page or section is defined with the <header> tag. It usually includes a
logo, a search engine, and navigational connections, among other things. This tag
does not create a new outline section. The heading (an <h1>–<h6> element) of a
surrounding section is typically contained in a <header> element. This, however, is
not essential. One of the HTML5 elements is the header tag. Several <header> tags
can be used in an HTML document, and they can be positioned in any area of it. It is
forbidden to use the <header> tag inside the <footer> and <address> components, as
well as inside another <header> tag.
The tag <header> is used in pairs. Between the opening (<header>) and closing
(</header>) tags, the content is written.
3. Footer Tag
A web page's or section's footer is defined by the <footer> tag. It usually includes
copyright information, contact information, navigation links, and so on. On a web
page, there might be many <footer> tags. You can, for example, include a footer
within the <article> element to keep information about the content (links, footnotes,
etc.). Except for the <footer> and <header> tags, the tag can include other HTML
components. One of the HTML5 components is the footer. If the footer has contact
information, provide it in the <address> tag.
4. Navigation Tag
One of the HTML5 elements is the <nav> tag. It specifies a set of navigation links,
either within the current content or to other papers. Tables of contents, menus, and
indexes are examples of navigation blocks.
A single HTML document can include multiple <nav> tags, such as one for site
navigation and another for intra-page navigation.
It's worth noting that the <nav> element doesn't contain all of the links in the HTML
content; it only contains the primary navigation blocks. The nav> element can be
used to define links in the website's footer, however the <footer> tag is more
commonly used in such circumstances.
The <nav> tag is not allowed to be nested within the address> element.
The <nav> tag is a pair of tags. The material is written in the middle of the page.
5. Main Tag
Unlike elements like <body>, <h2>, and others, this element has no effect on the
DOM's understanding of the page's structure. Landmarks can be used by assistive
technology to easily identify and navigate to the document's big portions. It is
preferable to utilise the <main> element instead of declaring role="main."
The "skipnav" technique allows users of assistive technology to skip huge chunks of
repetitive material. This allows the user to quickly reach the primary material of a
website. If you give the <main> element an id property, it will become the target of a
skip navigation link.
The tag main> is used in pairs. Between the opening (<main>) and closing (</main>)
tags, the text is written. The Global Attributes and Event Attributes are supported by
the <main>tag.
6. Article Tag
One of the HTML5 elements is the <article> tag. It's used to describe stuff that's self-
contained and self-contained. An article should have a distinct significance and stand
out from the rest of the web page's material.
A blog entry, forum post, news item, or user remark can all be included in the
<article> element.
The internal element represents an article that is associated to the external element
when the <article> element is nested. The address> element can be used to provide
author information for the <article> element. It will not, however, apply to nested
<article> components. In a single HTML document, many article> tags can be used.
The <h2> to <h6> tags can be nested within the <article> tag. If the <h1> tag has
never been used previously, it can be used now. A <time> element with a datetime
attribute can be used to express the <article> tag's publishing date and time.
The tag article> is used in pairs. Between the opening (article>) and closing (/article>)
tags, the text is written.
7. Section Tag
One of the HTML5 components is the <section>. It's utilised to make separate
sections of a website with logically connected content (news block, contact
information, etc.). When designing a landing page, the <section> tag is frequently
used to break the page into logical blocks.
A navigation menu, for example, must be wrapped in a <nav> tag, while a map
The nested <section> tag can be used to divide information into groups within the
<article> tag. As a result, using <h1> -<h6> heads within the <article> and <section>
tags is essential. The usage of a <h2> title in each section defined by the <section>
tag is permitted. Instead of using the <section> element as a universal container for
generating page structure, use the <div> tag instead.
The tag <section> is used in pairs. Between the opening (<section>) and ending
(</section>) tags, the text is written.
8. Figure Tag
The <figure> tag is used to indicate content that is self-contained. Diagrams, photos,
illustrations, code samples, and so forth can all be included in the tag. One of the
HTML5 elements is the figure tag. The <figure> tag's content is tied to the main
flow's content. It is, nonetheless, regarded as a self-contained unit. The <figcaption>
element is used to add a caption or explanation to the content of the figure> tag. The
<figcaption> tag is a child element of the figure> tag, and it is either the first or last
child element. The content will be shown at the top of the image if <figcaption> is
the first nested element.
The tag <figure> is used in pairs. Between the beginning (<figure>) and closing
(</figure>) tags, the content is written.
9. Caption Tag
The table's header is defined using the <caption> tag. The tag must be the first child
of its parent <table> element and must be inside the <table> element immediately
after the opening (<table>) tag. There is only one caption per table that can be
defined. You must use the <figcaption> element instead of the <caption> element
when the table> element containing the caption> is the only descendent of the
<figure> element. A table caption is center-aligned above a table by default.
However, the caption can be aligned and placed using the text-align and caption-side
attributes.
The tag <caption> is used in pairs. Between the opening (<caption>) and closing
(</caption>) tags, the text is written.
While we will not be recommending specific tools for creating web content, we believe it is critical to
understand the many types of web development tools and their relative benefits and drawbacks. Web
development tools are divided into five categories:
• WYSIWYG editors,
• Code editors,
• Full IDEs,
• Cloud-based environments,
• Code playgrounds.
1. WYSIWYG editors.
Web tools that provide a user experience similar to that of a word processor are known as What-You-See-Is-
What-You-Get. The benefit of such tools is that you don't require much (if any) HTML knowledge. However,
there is a significant downside to using such technologies. These tools are never fully WYSIWYG, and they
frequently have trouble previewing increasingly complex CSS. Indeed, in order to remedy such issues, these
technologies nearly always have to give users with a typical HTML view. While we would never recommend
relying only on such a tool, inexperienced end users may find them useful. In this genre, Adobe Dreamweaver
and Adobe Muse are two prominent editors. WYSIWYG editors are also used in web-based publishing
programs like blogs and content management systems.
2. Code editors.
Since web developers typically need knowledge of HTML, CSS, JavaScript, and more, many web developers
prefer to use tools that allow them to focus on viewing and editing these text files. Nonetheless, it is helpful to
use a tool that “understands” HTML, CSS, and so on. Such a tool might provide color coding, intelligent hints,
tag completion, and so on. There are a wide range of choices in this genre, many of them open source. Some of
the options include Atom, BlueFish, Brackets, Notepad++, Sublime Text, and Visual Studio Code.
3. Full IDEs.
Integrated Development Environments provide a more full featured programming experience. They not only
provide most of the same functionality as the previously mentioned code editors, but also typically provide extra
capabilities, such as comprehensive help files, build tools, multiple-language support, and integration with other
enterprise tools, such as databases. Some of the options in this genre include Eclipse, NetBeans, and Visual
Studio. This extra power does come at a price, both figuratively and literally. The figurative costs is these
complicated IDEs typically have a more substantial learning curve and can often have steep hardware
requirements.
4. Cloud-based environments.
One of the fastest growing approaches to developing web applications is to do one's development, testing, and
hosting all within an online environment. The key advantage of such an approach is that you don't have to worry
about installing, supporting, and synchronizing different web development tools, since it is all done for you by
the online environment. As well, using such online environments means that you don't really care what device
you have; if you have an Internet connection, you can do your coding. Of course, that's also the key
disadvantage. Since you need an Internet connection, you can't code while on the plane or in a forest (though
these environments sometimes provide a mechanism for offline usage). At the time of writing, CodeAnywhere
and Cloud9 are two popular sites providing a complete IDE for web development.
5. Code playgrounds.
Our final approach to web development tools also makes use of online environments. Code
playgrounds are not about constructing complete sites. Instead, they provide a way to
experiment, demonstrate, and share smaller snippets of code. Some of the most popular
include CodePen , JSFiddle, and CSS Deck. These environments are especially valuable for
students as a way to construct online portfolios and to show off their skills to prospective
clients and employers.
Introduction to CSS
In current web development best practices HTML should not describe the formatting or presentation of
documents. Instead that presentation task is best performed using Cascading Style Sheets (CSS). CSS is a W3C
standard for describing the appearance of HTML elements. Another common way to describe CSS's function is
to say that CSS is used to define the presentation of HTML documents. With CSS, we can assign font
properties, colors, sizes, borders, background images, and even position elements on the page. CSS can be
added directly to any HTML element (via the style attribute), within the <head> element, or, most commonly, in
a separate text file that contains only CSS.
Benefits of CSS
Before digging into the syntax of CSS, we should say a few words about why using CSS is a better way of
describing appearances than HTML alone. The benefits of CSS include the following:
CSS Syntax
A CSS document consists of one or more style rules. A rule consists of a selector that identifies the HTML
element or elements that will be affected, followed by a series of property:value pairs (each pair is also called a
declaration).
Each individual CSS declaration must contain a property. These property names are predefined by the CSS
standard. The CSS2.1 recommendation defines over a hundred different property names, so some type of
reference guide, whether in a book, online, or within your web development software, can be helpful.5 This
section will only be able to cover most of the common CSS properties. The most used CSS properties are given
below. Properties marked with an asterisk contain multiple subproperties not listed here (e.g., border-top,
border-top color, border-top-width, etc).
Fonts
font
font-family
font-size
font-style
font-weight
@font-face
Text
letter-spacing
line-height
text-align
text-decoration*
text-indent
Color and background
background
background-color
background-image
background-position
background-repeat
box-shadow
color
opacity
Borders
border*
border-color
border-width
border-style
border-top, border-left, …*
border-image*
border-radius
Spacing
padding
padding-bottom, padding-left, …
margin
margin-bottom, margin-left, …
Sizing
height
max-height
max-width
min-height
min-width
width
Layout
bottom, left, right, top
clear
display
float
overflow
position
Just as there are multiple ways of specifying color in CSS, so too there are multiple ways of
specifying a unit of measurement. these units can sometimes be complicated to work with.
When working with print design, we generally make use of straightforward absolute units
such as inches or centimeters and picas or points. However, because different devices have
differing physical sizes as well as different pixel resolutions and because the user is able to
change the browser size or its zoom mode, these absolute units don't always make sense with
web element
measures.
Below is a list of the different units of measure in CSS. Some of these are relative units, in
that they are based on the value of something else, such as the size of a parent element.
Others are absolute units; in that they have a real-world size. Unless you are defining a style
sheet for printing, it is recommended you avoid using absolute units. Pixels are perhaps the
one popular exception (though, as we shall see later, there are also good reasons for avoiding
the pixel unit). In general, most of the CSS that you will see uses either px, em, or % as a
measure unit.
Units of Measure Values
px
Pixel. In CSS2 this is a relative measure, while in CSS3 it is absolute (1/96 of an inch).
em
Equal to the computed value of the font-size property of the element on which it is used.
When used for font sizes, the em unit is in relation to the font size of the parent.
%
A measure that is always relative to another value. The precise meaning of % varies
depending upon the property in which it is being used.
From <[Link]
Location of styles
As mentioned earlier, CSS style rules can be in three different locations. These three are not
mutually exclusive, in that you could place your style rules in all three. In practice, however,
web authors tend to place all their style definitions in one (or more) external style sheet files.
Inline Styles
Inline styles are style rules placed within an HTML element via the style attribute. An inline
style only affects the element it is defined within and overrides any other style definitions for
properties used in the inline style. Notice that a selector is not necessary with inline styles and
that semicolons are only required for separating multiple rules. Using inline styles is
generally discouraged since they increase bandwidth and decrease maintainability (because
presentation and content are intermixed and because it can be difficult to make consistent
inline style changes across multiple files). Inline styles can, however, be handy for quickly
testing out a style change.
Embedded Style Sheet
Embedded style sheets (also called internal styles) are style rules placed within the <style>
element (inside the <head> element of an HTML document). While better than inline styles,
using embedded styles is also by and large discouraged. Since each HTML document has its
own <style> element, it is more difficult to consistently style multiple documents when using
embedded styles. Just as with inline styles, embedded styles can, however, be helpful when
quickly testing out a style that is used in multiple places within a single HTML document.
We sometimes use embedded styles in the book or in lab materials for that
reason.
External Style Sheet
External style sheets are style rules placed within a external text file with the .css extension.
This is by far the most common place to locate style rules because it provides the best
maintainability. When you make a change to an external style sheet, all HTML documents
that reference that style sheet will automatically use the updated version. The browser can
cache the external style sheet, which can improve the performance of the site as well.
From <[Link]
Selectors (A CSS Selector is used to select HTML elements that you want to style.)
As teachers, we often need to be able to relay a message or instruction to either individual
students or groups of students in our classrooms. In spoken language, we have a variety of
different approaches we can use. We can identify those students by saying things like: “all of
you talking in the last row,” or “all of you sitting in an aisle seat,” or “all of you whose name
begins with ‘C’,” or “all first-year students,” or “John Smith.” Each of these statements
identifies or selects a different (but possibly overlapping) set of students. Once we have used
our student selector, we can then provide some type of message or instruction, such as “talk
more quietly,” “hand in your exams,” or “stop texting while I am speaking.” when defining
CSS rules, you will need to first use a selector to tell the browser which elements will be
affected by the property values. CSS selectors allow you to select individual or multiple
HTML elements. The topic of selectors has become more complicated than it was when we
started teaching CSS in the late 1990s. There are now a variety of new selectors that are
supported by most modern browsers. Before we get to those, let us look at the three basic
selector types that have been around since the earliest CSS2 specification.
Element Selectors
Element selectors select all instances of a given HTML element. You can select all elements
by using the universal element selector, which is the * (asterisk) character. You can select a
group of elements by separating the different element names with commas. This is a sensible
way to reduce the size and complexity of your CSS files, by combining multiple identical
rules into a single rule.
Class Selectors
A class selector allows you to simultaneously target different HTML elements regardless of
their position in the document tree. If a series of HTML elements have been labeled with the
same class attribute value, then you can target them for styling by using a class selector,
which takes the form: period (.) followed by the class name.
Id Selectors
An id selector allows you to target a specific element by its id attribute regardless of its type
or position. If an HTML element has been labeled with an id attribute, then you can target it
for styling by using an id selector, which takes the form: pound/hash (#) followed by the id
name.
Attribute Selectors
An attribute selector provides a way to select HTML elements either by the presence of an
element attribute or by the value of an attribute. This can be a very powerful technique, but
because of uneven support by some of the browsers in the past, not all web authors have used
them. Followings are the most common ways one can construct attribute selectors in CSS3.
[]
A specific attribute.
[title]
Matches any element with a title attribute
[=]
A specific attribute with a specific value. a[title=“posts from this country”] Matches any <a>
element whose title attribute is exactly “posts from this
country“
[~=]
A specific attribute whose value matches at least one of the words in a space delimited list of
words. [title~=“Countries”] Matches any title attribute that contains the word “Countries“
[^=]
A specific attribute whose value begins with a specified value. a[href^=“mailto”] Matches
any <a> element whose href attribute begins with “mailto“
[*=]
A specific attribute whose value contains a substring. img[src*=“flag”] Matches any <img>
element whose src attribute contains somewhere within it the text “flag“
[$=]
A specific attribute whose value ends with a specified value. a[href$=“.pdf”] Matches any
<a> element whose href attribute ends with the text “.pdf“
Attribute Selectors
An attribute selector provides a way to select HTML elements either by the presence of an
element attribute or by the value of an attribute. This can be a very powerful technique, but
because of uneven support by some of the browsers in the past, not all web authors have used
them. Followings are the most common ways one can construct attribute selectors in CSS3.
[]
A specific attribute.
[title]
Matches any element with a title attribute
[=]
A specific attribute with a specific value. a[title=“posts from this country”] Matches any <a>
element whose title attribute is exactly “posts from this
country“
[~=]
A specific attribute whose value matches at least one of the words in a space delimited list of
words. [title~=“Countries”] Matches any title attribute that contains the word “Countries“
[^=]
A specific attribute whose value begins with a specified value. a[href^=“mailto”] Matches
any <a> element whose href attribute begins with “mailto“
[*=]
A specific attribute whose value contains a substring. img[src*=“flag”] Matches any <img>
element whose src attribute contains somewhere within it the text “flag“
[$=]
A specific attribute whose value ends with a specified value. a[href$=“.pdf”] Matches any
<a> element whose href attribute ends with the text “.pdf“
From <[Link]
Background:
the background color or image of an element fills an element out to its border (if it has one,
that is).
Common Background Properties
Reference: taken from [Link]
Value Description
background-color Specifies the background color to be used
background-image Specifies ONE or MORE background images to be used
background-position Specifies the position of the background images
background-size Specifies the size of the background images
background-repeat Specifies how to repeat the background images
background-origin Specifies the positioning area of the background images
background-clip Specifies the painting area of the background images
background- Specifies whether the background images are fixed or scrolls with the
attachment rest of the page
Collapsing Margins
Box Dimensions
Content-box
• width/height applied to contents only
• borders and padding counted separately
• margins counted separately
Border-box
• width/height include border and padding
• margins counted separately
Property Description
font A combined shorthand property that allows you to set the family, style, size,
variant, and weight in one property.
style weight variant size font-family
font- Specifies the typeface/font to use. More than one can be specified.
family
font-size The size of the font in one of the measurement units
font-style Specifies whether italic, oblique, or normal
font- Specifies either small-caps text or none
variant
font- Specifies either normal, bold, bolder, lighter, or a value between 100 and 900 in
weight multiples of 100, where larger number represents
weightier (i.e., bolder) text.
Font Sizes
Paragraph Properties
Reference: taken from [Link]
Property Description
From <[Link]
Styling Tables
You can style the tables in different way outs.
Table Borders
Following are some examples of the table with different borders:
Accessible Tables
• Use tables for data, not layout
• Use the <caption> element
• Connect cells with a textual description in the header
Code:
<caption>Famous Paintings</caption>
<tr>
<th scope="col">Title</th>
<th scope="col">Artist</th>
<th scope="col">Year</th>
<th scope="col">Width</th>
<th scope="col">Height</th>
</tr>
Introducing Forms
Forms provide the user with an alternative way to interact with a web server. Up to now,
clicking hyperlinks was the only mechanism available to the user for communicating with the
server.
Query Strings
The browser packages the user's data input into something called a query string. A query
string is a series of name=value pairs separated by ampersands (the & character).
GET • Data can be clearly seen in the address bar. This may be an
• advantage during development but a disadvantage in
• production.
• Data remains in browser history and cache. Again this may
• be beneficial to some users, but a security risk on public
• computers.
• Data can be bookmarked (also an advantage and a
• disadvantage).
• Limit on the number of characters in the form data
• returned.
POST • Data can contain binary data.
• Data is hidden from user.
• Submitted data is not stored in cache, history, or
• Bookmarks.
Datalist:
<datalist> element is new addition to HTML5. This element allows to define a list of
elements that can appear in a drop-down autocomplete style list for a text element.
Choice Controls:
Forms often need the user to select an option from a group of choices. HTML provides
several ways to do this.
1. Select Lists:
The <select> element is used to create a multiline box for selecting one or more items. The
options can be hidden in a dropdown list or multiple rows of the list can be visible. Option
items can be grouped together via the <optgroup> element.
2. Radio Buttons:
Radio buttons are useful when you want the user to select a single item from a small list of
choices and you want all the choices to be visible.
3. Check Boxes:
Checkboxes are used for getting yes/no or on/off responses from the user.
Button Controls:
HTML defines several different types of buttons which are mentioned below:
Type Description
Submit Creates a button that submits the form data to the
server.
Reset Creates a button that clears any of the user’s already
entered form data.
button Creates a custom button. This button may require
JavaScript for it to actually perform any action.
image Creates a custom submit button that uses an image for
its display.
From <[Link]
From <[Link]
Microformats:
The web has millions of pages in it. Yet, despite the incredible variety, there is a surprising
amount of similar information from site to site. Most sites have some type of Contact Us
page, in which addresses and other information are displayed; similarly, many sites contain a
calendar of upcoming events or information about products or news. The idea behind
microformats is that if this type of common information were tagged in similar ways, then
automated tools would be able to gather and transform it. A microformat is a small pattern of
HTML markup and attributes to represent common blocks of information such as people,
events, and news stories so that the information in them can be extracted and indexed by
software agents.
One of the most common microformats is hCard, which is used to semantically markup
contact information for a person. Google Map search results now make use of the hCard
microformat so that if you used the appropriate browser extension, you could save the
information to your computer or phone’s contact list.
From <[Link]
File Formats:
1. JPEG:
JPEG (Joint Photographic Experts Group) or JPG is a 24-bit, true-color file format that is
ideal for photographic images. It uses a sophisticated compression scheme that can
dramatically reduce the file size of the image. JPEG is the ideal file format for photographs
and other continuous-tone images such as paintings and grayscale images.
2. GIF:
The GIF (Graphic Interchange Format) file was the first image format supported by the
earliest web browsers. Unlike the 24-bit JPEG format, GIF is an 8-bit or less format, meaning
that it can contain no more than 256 colors. GIF files use a much simpler compression system
that is lossless, which means that no pixel information is lost.
3. PNG:
The PNG (Portable Network Graphics) format is a more recent format. Its main features are:
5. Lossless compression.
5. 8-bit (or 1-bit, 2-bit, and 4-bit) indexed color as well as full 24-bit true color
5. From 1 to 8 bits of transparency.
For normal photographs, JPEG is generally still a better choice because the file size will be
smaller than using PNG.
4. SVG:
The SVG (Scalable Vector Graphics) file format is a vector format. SVG graphics do not lose
quality when enlarged or reduced.
Other Formats:
There are many other file formats for graphical information. The TIF (Tagged Image File)
format is a cross-platform lossless image format that supports multiple color depths, 8-bit
transparency, layers and color channels, the CMYK and RGB color space, and other features
especially useful to print professionals.
From <[Link]
Normal Flow:
To understand CSS positioning and layout, it is essential to first understand the idea of
normal flow, and how the browser will normally display block-level elements and inline
elements from left to right and from top to bottom.
Block-level elements: such as <p>, <div>, <h2>, <ul>, and <table> are each contained on
their own line. Because block-level elements begin with a line break, without styling, two
block-level elements can’t exist on the same line. Block-level elements use the normal CSS
box model, in that they have margins, paddings, background colors, and borders.
Inline elements: do not form their own blocks but instead are displayed within lines. Normal
text in an HTML document is inline, as are elements such as <em>, <a>, <img>, and <span>.
From <[Link]
Positioning Elements:
It is possible to move an item from its regular position in the normal flow. The position
property is used to specify the type of positioning, and the possible values. The left, right,
top, and bottom properties are used to indicate the distance the element will move; the effect
of these properties varies depending upon the position property.
Relative positioning:
In relative positioning an element is displaced out of its normal flow position and moved
relative to where it would have been placed.
Static:
The element is positioned according to the normal flow. This is the default.
Fixed:
The element is fixed in a specific position in the window even when the document is scrolled.
Absolute:
The element is removed from normal flow and positioned in relation to its nearest positioned
ancestor.
Absolute Positioning:
When an element is positioned absolutely, it is removed completely from normal flow. Thus,
unlike with relative positioning, space is not left for the moved element, as it is no longer in
the normal flow. Its position is moved in relation to its container block.
Z- Index:
Each positioned element has a stacking order defined by the z-index property (named for the
z-axis). Items closest to the viewer (and thus on the top) have a larger z-index value, which
can be seen in the first. Unfortunately, working with z-index can be tricky and seemingly
counterintuitive.
Fixed Position:
The fixed position value is used relatively infrequently. It is a type of absolute positioning,
except that the positioning values are in relation to the viewport (i.e., to the browser window).
Elements with fixed positioning do not move when the user scrolls up or down the page. The
fixed position is most commonly used to ensure that navigation elements or advertisements
are always visible.
From <[Link]
Floating Elements:
It is possible to displace an element out of its position in the normal flow via the CSS float
property. An element can be floated to the left or floated to the right. When an item is floated,
it is moved all the way to the far left or far right of its containing block and the rest of the
content is “re-flowed” around the floated element.
Clear Property:
You can stop elements from flowing around a floated element by using the clear property.
Values for clear property are shown below:
Values Description
Left The left-hand edge of the element cannot be adjacent to another element.
Right The right-hand edge of the element cannot be adjacent to another element.
Both Both the left-hand and right-hand edges of the element cannot be adjacent to
another element.
None The element can be adjacent to other elements.
Containing Floats:
Another problem that can occur with floats is when an element is floated within a containing
block that contains only floated content. In such a case, the containing block essentially
disappears.
There are in fact two different ways to hide elements in CSS: using the display property and
using the visibility property. The display property takes an item out of the flow: it is as if the
element no longer exists. The visibility property just hides the element, but the space for that
element remains.
From <[Link]
From <[Link]
Using floats is perhaps the most common way to create columns of content. The first step is
to float the content container that will be on the left-hand side. Remember that the floated
container needs to have a width specified. The background of the floated element stops when
its content ends. If we wanted the background color to descend down to the footer, then it is
difficult (but not impossible) to achieve this visual effect with floats.
Positioning can also be used to create a multicolumn layout. This approach typically uses
some type of container that establishes the positioning context. With positioning it is easier to
construct our source document with content in a more SEO-friendly manner; in this case, the
main <div> can be placed first.
When an item is positioned, it is removed entirely from normal flow, so subsequent items
will have no “knowledge” of the positioned item. One solution to this type of problem is to
place the footer within the main container.
2. flex-end:
Items are packed toward the end of the flex-direction.
Example:
4. Space-between:
Items are evenly distributed in the line; first item is on the start line, last item on the end line.
Example:
5. space-around:
Items are evenly distributed in the line with equal space around them.
Example:
Flexgrow set to be 1
If one of the children has a value of 2, that child would take up twice as much of the space
either one of the others.
Example:
Flexgrow set to be 2
2. Flex-basis:
This defines how much space an element is taking initially.
3. Flex-shrink
This defines the ability for a flex item to shrink if necessary.
From <[Link]
From <[Link]
One of the main problems faced by web designers is that the size of the screen used to view
the page can vary quite a bit. Users with the large monitor might expect a site to take
advantage of the extra size; users with the small monitor will expect the site to scale to the
smaller size and still be usable. Satisfying both users can be difficult; the approach to take for
one type of site content might not work as well with another site with different content.
Fixed Layout:
The first approach is to use a fixed layout. In a fixed layout, the basic width of the design is
set by the designer, typically corresponding to an “ideal” width based on a “typical” monitor
resolution. Fixed layouts are created using pixel units, typically with the entire content within
a <div> container (often named "container", "main", or "wrapper") whose width property has
been set to some width. The advantage of a fixed layout is that it is easier to produce and
generally has a predictable visual result.
Fixed layouts have other drawbacks. For larger screens, there may be an excessive amount of
blank space to the left and/or right of the content. Much worse is when the browser window
shrinks below the fixed width; the user will have to horizontally scroll to see all the content.
Liquid Layout:
The second approach to dealing with the problem of multiple screen sizes is to use a liquid
layout (also called a fluid layout). In this approach, widths are not specified using pixels, but
percentage values. The obvious advantage of a liquid layout is that it adapts to different
browser sizes, so there is neither wasted white space nor any need for horizontal scrolling.
From <[Link]
Responsive Design:
In a responsive design, the page “responds” to changes in the browser size that go beyond the
width scaling of a liquid layout. One of the problems of a liquid layout is that images and
horizontal navigation elements tend to take up a fixed size, and when the browser window
shrinks to the size of a mobile browser, liquid layouts can become unusable. In a responsive
layout, images will be scaled down and navigation elements will be replaced as the browser
shrinks. There are four key components that make responsive design work.
1. Liquid layouts.
2. Scaling images to the viewport size.
3. Setting viewports via the <meta> tag.
4. Customizing the CSS for different viewports using media queries.
Setting Viewports:
A key technique in creating responsive layouts makes use of the ability of current mobile
browsers to shrink or grow the web page to fit the width of the screen. The way this works is
the mobile browser renders the page on a canvas called the viewport. On iPhones, for
instance, the viewport width is 980 px, and then that viewport is scaled to fit the current
width of the device.
Media Queries:
The other key component of responsive designs is CSS media queries. A media query is a
way to apply style rules based on the medium that is displaying the file. You can use these
queries to look at the capabilities of the device, and then define CSS rules to target that
device. Unfortunately, media queries are not supported by Internet Explorer 8 and earlier.
Scaling Images
Responsive designs begin with a liquid layout, that is, one in which most elements have their
widths specified as percentages. We simply need to specify the following rule to make image
scale in size:
Image {
width: 100%;
max-width: 1024px;
}
<picture>
Example:
From <[Link]
From <[Link]
From <[Link]
CSS Frameworks:
A CSS framework is a pre created set of CSS classes or other software tools that make it
easier to use and work with CSS. They are two main types of CSS framework: grid systems
and CSS preprocessors.
CSS Preprocessors:
CSS preprocessors are tools that allow the developer to write CSS that takes advantage of
programming ideas such as variables, inheritance, calculations, and functions. A CSS
preprocessor is a tool that takes code written in some type of preprocessed language and then
converts that code into normal CSS. The advantage of a CSS preprocessor is that it can
provide additional functionalities that are not available in CSS.
Installing Bootstrap
Bootstrap has two parts:
1. CSS
2. JavaScript
Ways to get Bootstrap:
There are three main ways to get the bootstrap:
1. Content Delivery Network
2. Web server/local Machines
3. Package Managers
Bootstrap Requirements:
Require certain tags on the web page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
</html>
Grid Layout:
Grid systems make it easier to create multicolumn layouts. There are many CSS grid
Systems. Some of the most popular are Bootstrap, Blueprint, and 960 ([Link]). The most
important of these capabilities is a grid system. Print designers typically use grids as a way to
achieve visual uniformity in a design. CSS frameworks provide similar grid features. The 960
framework uses either a 12- or 16-column grid. Bootstrap uses a 12-column grid. Blueprint
uses a 24-column grid. The grid is constructed using <div> elements with classes defined by
the framework. In Bootstrap, content must be placed within the <div class="row"> row
container.
From <[Link]
From <[Link]
From <[Link]
Typography in Bootstrap:
Typography is a feature of Bootstrap for styling and formatting the text content. It is used to
create customized headings, inline subheadings, lists, paragraphs, aligning, adding more
design-oriented font styles and much more. By default, Bootstrap will style the HTML
headings (<h1> to <h6>).
Text Utilities:
1. Text alignment
Easily realign text to components with text alignment classes.
2. Text wrapping
Prevent text from wrapping with a .text-nowrap class.
3. Text transform
Transform text in components with text capitalization classes.
1. lowercased text.
2. UPPERCASED TEXT.
3. CapiTaliZed Text.
Colors in Bootstrap:
Bootstrap provides us the color utility due to this we can assign colors to text and the
background. Bootstrap supports many theme-wise colors. Colors can be used:
1. Text
Example: <p class="text-light bg-dark">.text-light</p>
1. Background
Example: <div class="p-3 mb-2 bg-primary text-white">.bg-primary</div>
1. Link
Example: <p><a href="#" class="text-danger">Danger link</a></p>
1. Alerts
Colors for themes can be changes using Saas CSS pre-processor.
Theme- based colors:
8 theme-based colors are mentioned below:
Text colors Background colors
Primary
Secondary
Success
Info
Warning
Danger
dark
From <[Link]
From <[Link]
Navigations in Bootstrap
Nav is one of the components available in bootstrap and it’s used for creating responsive
navigation bars. Navigation is implemented using:
Unordered list:
Example: < ul class = “nav”>
List items:
Example: <li class = “nav-item”>
Links:
Example: < a class =”nav-link”….>
Dropdown using nested unordered list:
Parent li:
Example: <li class = “nav-item dropdown”>
Parent link:
Example: < a class = “nav-link dropdown-toggle” data-bs-toggle = “dropdown” href = “#”>
Dropdown</a>
Nested ul:
Example: <ul class = “dropdown-menu”>
List item:
Example: <li><a class = dropdown-item”
From <[Link]
Inline JavaScript:
Inline JavaScript refers to the practice of including JavaScript code directly within certain
HTML attributes.
<a href="JavaScript:OpenWindow();"more info</a>
<input type="button” onclick="alert('Are you sure?');" />
Embedded JavaScript:
Embedded JavaScript refers to the practice of placing JavaScript code within a <script>
element.
<script type="text/javascript">
/* A JavaScript Comment */
alert ("Hello World!");
</script>
External JavaScript:
External files typically contain function definitions, data definitions, and other blocks of
JavaScript code. JavaScript external files have the extension .js.
<head>
<script type="text/JavaScript" src="[Link]">
</script>
</head>
From <[Link]
Variables in JavaScript:
There are two types of variables in programming language i-e dynamic and static. In c, c++
and java variables are statically typed. Some programming languages decided the type of
variable on runtime and java script is one of them, in python also variables are dynamically
typed. This simplifies variable declarations, so that we do not require the familiar type fields
like int, char, and String. Instead, to declare a variable x, we use the var keyword, the name,
and a semicolon.
Data Types in JavaScript:
There are two types of data types in java script i-e reference data type and primitive data type.
In reference data types we have objects and the address of objects will be stored in the
variable. Whereas, in primitive data types exact value of variable will be stored e.g Boolean,
number variable and string e.t.c. So in primitive data types values will be stored and in
reference address will be stored.
JavaScript Output:
It’s very important in every programming language to view the output. In JavaScript we have
three mechanisms to view the output:
1. Alert
2. Console. Log()
3. Document. Write ().
1. Alert:
The alert() function makes the browser show a pop-up to the user, with whatever is passed
being the message displayed. The following JavaScript code displays a simple hello world
message in a pop-up:
alert ( "Good Morning" );
The pop-up may appear different to each user depending on their browser configuration.
During debugging and testing we may use alert function.
1. Document. Write:
This method writes a string of text to a document stream opened by document. By using the
document. Write whatever we will write it will be the part of the HTML page.
1. Console log:
It is very good way to debug your application. We can open a console in web browser by
using: Ctrl + Shift + I for windows.
From <[Link]
From <[Link]
Conditionals:
In java script conditions are identical like c++. There are three types of conditional
statements:
1. If else if
2. Switch
3. Conditional assignment.
If else if:
Conditional statements are simple in which we have to write logical expressions. If logical
expression will be true then one block of expression will be executed if false then it will not
be executed.
Example:
var hourOfDay; // var to hold hour of day
var greeting; // var to hold the greeting message.
if (hourOfDay > 4 && hourOfDay < 12){
// if statement with condition
greeting = "Good Morning";
}
else if (hourOfDay >= 12 && hourOfDay < 20){
// optional else if
greeting = "Good Afternoon";
}
else{ // optional else branch
greeting = "Good Evening";
}
Switch Statements:
The switch statement evaluates an expression, matching the expression's value to
a case clause, and executes statements associated with that case, as well as statements
in cases that follow the matching case.
Example:
const expr = 'Papayas';
switch (expr) {
case 'Oranges':
[Link]('Oranges are $0.59 a pound.');
break;
case 'Mangoes':
case 'Papayas':
[Link]('Mangoes and papayas are $2.79 a pound.');
// expected output: "Mangoes and papayas are $2.79 a pound."
break;
default:
[Link](`Sorry, we are out of ${expr}.`);
}
Conditional assignment:
The conditional (ternary) operator is the only JavaScript operator that takes three operands:
a condition followed by a question mark (?), then an expression to execute if the condition
is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy.
This operator is frequently used as an alternative to an if...else statement.
Example:
/* x conditional assignment */
x = (y==4) ? "y is 4" : "y is not 4";
Condition Value if true Value if false
From <[Link]
Arrays:
Arrays are one of the most used data structures, and they have been included in JavaScript as
well. There are two main ways to define an array in java script.
1. Object literal notation
2. Array constructor
Array Constructor:
Array constructor is the second way for the creation of array. In array constructor “new”
keyword has been used and in parenthesis we will write commas separated values.
Example:
var greetings = new Array("Good Morning", "Good Afternoon");
From <[Link]
Event handling
In every language of computer science event has its own significance, but in JavaScript,
which is utilized in web development, it is very significant. An event is an action that occurs
as a result of the user or another source, such as a mouse click. Let’s see how it is handled in
JavaScript.
Introduction:
• JavaScript event is an action that can be detected by JavaScript.
• Many of them are initiated by user actions, some are generated by the browser itself.
• We say that an event is triggered and then is handled by JavaScript functions.
There are multiple ways to handle an event. Let’s have a look at them.
The given figure no.80.1 depicts it in detail.
Event Handling Approaches-Inline Hook
Figure no.80.1
The very first line portrays that a JavaScript code has been stored in an external file which
includes the some functions such as
function validated (node){….
} // validate the node
function check (node){….
} // check whether the node is or not an appropriate one.
function highlight (node){….
} // highlight text
The figure 80.1 clearly depicts the events on which these functions are invoked.
Another way of handling event is.
Event –Handling Approaches-Event property Approach:
• var mybutton=[Link] (‘example’);//In JavaScript, get an element
from the DOM tree (Any approach, such as
query Selector or get element ById, can be used). After that we write function name
on its appropriate event. As shown below.
• [Link]=alert (‘some message’);
• [Link] (‘click’, alert (‘some message’));// it take two parameter
• [Link] (‘mouseout’, funcName);
Similarly, we may define several events on a single object using this method.
The key benefit of this method is that JavaScript code is segregated from HTML. The
Event Types
Three types of Events:
1. mouse
2. Keyboard
3. touch
Mouse Events:
Event related to muse is called mouse events.
Mouse events are used to describe a variety of mouse-driven interactions. Mouse click and mouse
move events are two types of mouse events. Many mouse events can be sent at once, which is
unusual. The user may move the mouse from one div to another at the same time, activating the
mouseon and mouseout events as well as the mousemove event. To deal with these difficulties, use
the Cancelable and Bubbles properties. Following is the list of mouse events.
Keyboard Events:
the events related to keyboard is called keyboard events.
Within input fields, these events are most useful. With each key hit, we could, for example, validate
an email address or submit an asynchronous request for a dropdown list of suggestions with each
key press. <input type=“text” id=“key”>
For this input box, we could listen for key press events and replay each pushed key back to the user
as shown below.
[Link](“key”).addEventListener(“keydown”, function (e) {
var keyPressed=[Link];
// get the raw key code
var character=[Link](keyPressed);
// convert to string
alert (“Key “ + character + ” was pressed”);
});
Note: Regrettably, different browsers handle keyboard properties differently. For example, the
keyCode property is not available for the keypress event in FireFox. If we used the same callback
method for the keypress event in code above, we'd have to update the code to retrieve the key
press as follows:
// use either the which or the keyCode property
var keyPressed = [Link] || [Link];
Instead of clogging our code with these kind of browser testing conditional statements, we can use
something like the jQuery framework to handle these quirks.
Touch events:
these are relatively new events which are especially used in mobile devices.
• Touch events are a relatively new category of events that can be triggered by devices with
touch screens.
• Touch events are only available by default in Chrome and iOS Safari at the time of writing.
• In Edge and FireFox, the user must allow touch events. Pointer events, a new standard
specification that combines mouse, touch screen, and pen input into a single event type, are
supported by Microsoft Edge. However, pointer events are only supported in Edge at the time
of writing.
Let's look at an example where these events will be used to validate a form.
[Link] (‘change’, check_name);
[Link] (‘change’, check_email);
[Link] (‘submit’, validate);
function check_name () {
if ([Link]<5)
{
[Link]= ‘background-color: pink’;
} else {
[Link]= ‘background-color: white’;
}
}
Figure 84.1
……………………………………………………………………………………………………………………….
From <[Link]
Introduction to jQuery
JQuery is one of the JavaScript libraries that are used to assist us with web development.
jQuery is a popular framework that gives developers access to cross-browser animation tools, user
interface elements, and DOM manipulation functions, among other things. Learning about
frameworks, especially jQuery, can help you improve your development abilities by allowing you to
use ever-evolving frameworks that provide new and increasingly expected functionality.
The Most popular Framework
• Makes working with JavaScript and DOM easy// JQuery also makes it easy to select an
element and to perform different operation on it
• Cross browser compatibility // it makes sure that the code written is
executable on all the different browsers.
• Most popular JavaScript library (as of 2021). According to [Link]
□ Used by 78% of all website
□ 96% market share
How to include JQuery in our code, there are multiple ways to include it.
Including JQuey
• Use a Content Delivery Network
(CDN)
▪ <script src = [Link] </script>
//can include directly from CDN, [Link] is best as it has minimum size.
• Can also be
• Download and used on your web server
• Installed via package manager(npm, yarn, etc)
Note: JQuery can be included in the head, or before body in HTML file.
Let's have a look at an example that how it can be included in HTML file.
Figure 85.1 shows that how it can be included when we have an internet connection.
Figure no 85.1
But if we have no internet connection then download and save it in folder where you have HTML
file.
And then include it using absolute path as shown in figure 85.2
From <[Link]
jQuery selectors
The programmatic selection of DOM elements is one of the most common JavaScript jobs. The
element selection method in jQuery is both strong and easy. JavaScript has a variety of functions for
selecting an element, such as getElementByID() and querySelector().Although the querySelector()
and querySelectorAll() capabilities now let you pick DOM elements using CSS selectors, developers
have only been able to assume that these functions are available in most users' browsers since
around 2014 (IE 8 and earlier didn't fully support these techniques). One of the reasons for jQuery's
early popularity was that it gave programmers with a straightforward cross-browser way to
programmatically select an element using regular CSS selectors.
• The power of jQuery resides in the function named jQuery()
• There’s also an alias for this function named $()
• You can combine CSS selectors with the $() notation to select DOM objects that match CSS
attributes
Basic Selectors
The four basic selectors were defined back in Chapter 4, and include the universal selector, class
selectors, id selectors, and elements selectors. Selectors in jQuery are designed to closely resemble
the CSS specification, which is especially useful given that CSS is something you've learnt and used
throughout this book:
• $(“*”)—Universal selector matches all elements (and is slow).
• $(“tag”)—Element selector matches all elements with the given element name.
• $(“.class”)—Class selector matches all elements with the given CSS class.
• $(“#id”)—Id selector matches all elements with a given HTML id attribute.
jQuery Manipulators
jQuery Manipulators are methods used to modify HTML elements, such as changing text, HTML, CSS,
attributes, classes, or adding/removing elements from the page.
The checked property of a radio button or checkbox is the most common example of an HTML tag
that includes both properties and attributes. The attr () method could be used to set HTML
properties in earlier versions of jQuery. However, because properties are not actually characteristics,
strange behavior ensued. Although attr () may return some (less useful) values, the prop () method is
now preferred for retrieving and setting the value of a property.
To illustrate this subtle difference, consider a DOM element defined by
<input class=“meh” type=“checkbox” checked=“checked”>
The value of the attr () and prop () functions on that element differ as shown below.
var theBox = $(“.meh”);
[Link] (“checked”); // evaluates to TRUE
[Link] (“checked”); // evaluates to “checked”
val () used for getting/setting values of elements having the value property (e.g., <input type= “text”
…>
From <[Link]
Events in jQuery
Introduction:
jQuery, like JavaScript, allows you to create and manage JavaScript event listeners/handlers. With a
few minor syntax modifications, these events are used in the same way as JavaScript.
Listeners
For jQuery Setting up listeners for specific events is similar to how JavaScript works. While
addEventListener () is used in pure JavaScript, jQuery includes on () and off () methods as well as
shortcut methods for attaching events.
Looking at figure 89.1. we can see that jQuery is substantially less verbose than JavaScript once
again. Is that, however, all it has to offer? When working with events, jQuery also makes many
typical chores easier. Figure shows a simple example with three different mouse events. The click
event handler, in particular, makes advantage of the jQuery off () function to stop listening to the
mouse move event. This is far more straightforward than the JavaScript-only solution.
Binding and unbinding events
1. Creating Nodes
A node is any object in the DOM, such as an element, text, or comment. Creating nodes means
creating new HTML elements dynamically.
JavaScript
const para = [Link]("p");
[Link] = "Hello World";
jQuery
const para = $("<p>Hello World</p>");
or
const para = $("<p>").text("Hello World");
Example
JavaScript
const div = [Link]("div");
[Link] = "Software Engineer";
[Link](div);
jQuery
const div = $("<div>")
.text("Software Engineer");
$("body").append(div);
after()
$("#para").after("<hr>");
Result
<p>This is paragraph.</p>
<hr>
insertBefore()
$("<h3>Title</h3>").insertBefore("#para");
insertAfter()
$("<hr>").insertAfter("#para");
appendTo()
$("<li>Banana</li>").appendTo("#list");
Read as: Add <li> into #list.
wrapAll()
Wraps all selected elements together.
$("p").wrapAll("<div class='container'></div>");
Result
<div class="container">
<p>Hello</p>
<p>World</p>
</div>
wrapInner()
Wraps only the contents of an element.
HTML
<p id="demo">Hello World</p>
$("#demo").wrapInner("<strong></strong>");
Result
<p id="demo">
<strong>Hello World</strong>
</p>
unwrap()
Removes the parent wrapper while keeping the child elements.
Before
<div class="box">
<p>Hello</p>
</div>
$("p").unwrap();
After
<p>Hello</p>
A very powerful feature of jQuery is with the reference of Animation. Different elements
could be added through animation in html document.
Animation Effects:
Some of the generic animation methods are as show and fade In methods.
Show() and fadeIn():
.show(duration)
This function will display the image gradually over given duration in milli seconds.
For example;
If image was hidden then .show(1000) function will gradually show the image in 1000 milli
seconds (1 second).
You can also pass string parameters like slow or fast to show function.
.fadeIn(duration)
This function gradually fade the element by decreasing its opacity to given duration.
slide()
This function will move the element from one position to another.
For example;
A menu item will slide down from a button when mouse hover or enter on button element
and when mouse leave the button ,sliding menu disappers.
Figure-1: slide() function (taken from Fundamentals of Web Development second edition 2017)
Use animation to a limited extent, because animations take time and if users want to do
work fast, animations will annoy users because of their durations.
Raw Animations in jQuery:
Along with generic animation methods of jQuery, there are some raw animations which
could be used for custom type requirements. You can animate any numeric CSS property.
animate()
$(“#box”).animate({left:’495px’);
Function animate will move the box about 495 pixels on left side. Box animation will be
visible from one position to other. The position of object must be relative not statis.
For example:
Following code example shows a box enter on the page from left side, then move upwards,
and by clicking on the button in that dialogue box, the dialogue box get fade.
Example-1: animate function output (taken from Fundamentals of Web Development second edition 2017)
From <[Link]
Introduction to Ajax
Ajax is a very important feature of JavaScript through which we fetch data from server while
staying on client side.
AJAX is known as Asynchronous JavaScript and XML. Earlier it was originally using XML, but
now it is using JSON format.
General Sequence of Events:
As shown in Figure 1;
1. In browser Dom will be created.
2. HTML document will be shown and html page will be listening for events(scroll events,
click events, etc).
Example-1: UML sequence diagram of an AJAX request (taken from Fundamentals of Web Development second
edition 2017)
Asynchronous Request:
When event occur and there is the need to fetch some data from server, then we sends
asynchronous request to server and server send back the request with data. We will place
that data in appropriate place and then html page layout will be updated.
Synchronous Request:
The page loaded is again sent back to server with query string or other way to get
information. Server creates a new web page and send it back to us. For example; we want to
change the time on a web page and send a request for it to server, server change the time
along with recreate all the content of web page.
Figure 10.14 Illustration of an AJAX implementation of the server time web page
(taken from Fundamentals of Web Development second edition 2017)
From <[Link]