Full Stack Modified Unit-1
Full Stack Modified Unit-1
UNIT-1
Full stack: In technology development, full stack refers to an entire computer system or
application from the front end to the back end and the code that connects the two. The back end
of a computer system encompasses “behind-the-scenes” technologies such as the database and
operating system.
Full Stack Web Developer: A full stack web developer is a person who can develop
both client side and server side of a website. They are proficient in both front-end and back-end
languages and frameworks, as well as in server, network and hosting environments.
(or)
Full Stack Developer is an engineer who works on both client-side and server-side of the
software/web application. This type of developer works on the Full Stack of a software
application Front end development, Back end development, Database, Server, API, and version
controlling systems. Hence, the name "Full Stack" Developer. Full stack developer translates
user requirements into the overall architecture and implements the new systems.
Why Do You Need a Full-Stack Developer?
Full stack developer helps you to keep every part of the system running smoothly
Full stack developer can provide help to everyone in the team and greatly reduce the time
and technical costs of team communication
If one person plays different roles, it saves your company's personnel, infrastructure and
operational cost.
1) Front-end technology
Full stack developer should be master of essential front-end technologies like HTML5, CSS3,
JavaScript and Knowledge of third-party libraries like jQuery, Angular, ReactJS are is desirable.
2) Development Languages
Full stack engineer should know at least one server-side programming languages like Java,
Python, Ruby, .Net, JSP, Servlet etc.
3) Databases
Knowledge of various DBMS technology is another important need of full stack developer.
MySQL, MongoDB, Oracle, SQLServer are widely used for this purpose.
In order to become a successful Full Stack web developer, the knowledge of designing is also
recommended. Moreover, the person should know the principle of basic prototype design and
UI /UX design.
5) Server
Exposure to handling Apache or nginx servers is desirable. A good background in Linux helps
tremendously in administering servers.
A version control system allows full stack developers to keep track of all the changes made in
the codebase. The knowledge of Git helps full stack developers to understand how to get the
latest code, update parts of the code, and make changes in other developer's code without
breaking things.
Knowledge of web services or API is also important for full stack developers. Knowledge of
creations and consumption of REST and SOAP services is desirable.
SOAP (Simple Object Access Protocol) is a standards-based web services access protocol that
has been around for a long time. REST (Representational State Transfer) is another standard,
made in response to SOAP's shortcomings. It seeks to fix the problems with SOAP and provide
a simpler method of accessing web services.
Other important points:
A Java Full Stack Developer is a developer who has expertise and deep knowledge of
frameworks and tools used in Java full stack development like Core Java, servlets, APIs,
database, web architecture, etc. A Full Stack Java developer can build whole Java
applications including front end, back-end, database, APIs, server and version control.
JavaScript has been around for over 20 years. It is the dominant programming language in
web development.
In the beginning JavaScript was a language for the web client (browser). Then came the
ability to use JavaScript on the web server (with Node.js).
The idea of "Full Stack JavaScript" is that all software in a web application, both client side
and server side, should be written using JavaScript only.
Software stack is a collection of the programs which are used together to produce a specific
result. It includes an operating system and its application. For example, a smartphone software
stack includes OS along with the phone app, web browsers, and default applications.
Types of full stack developers:
JavaScript Full-Stack Developers,
MERN Stack Developers,
MEAN Stack Developers,
Ruby on Rails Full-Stack Developers,
Python Full-Stack Developers,
LAMP Stack Developers,
Java Full-Stack Developers,
PHP Full-Stack Developers,
Mobile Full-Stack Developers, and
DevOps Full-Stack Developers.
Popular Stacks:
LAMP Stack:
LAMP is a widely used model for web service stacks. Its name "LAMP" is an acronym of four
open-source components.
MEAN Stack:
Translate user requirements into the overall architecture and implementation of new
systems
Manage Project and coordinate with the Client
Write backend code in Ruby, Python, Java, PHP languages
Writing optimized front end code HTML and JavaScript
Understand, create and debug database related queries
Create test code to validate the applicaition against client requirement.
Monitor the performance of web applications & infrastructure
Troubleshooting web application with a fast and accurate a resolution
Advantages:
Disadvantages:
Front end: It is the visible part of website or web application which is responsible for user
experience. The user directly interacts with the front end portion of the web application or
website.
HTML, CSS, BOOTSTRAP, W3.CSS, JAVASCRIPT, ES5, HTML DOM, JSON, XML,
JQUERY, ANGULAR, REACT, BACKBONE.JS, EMBER.JS, REDUX, STORYBOOK,
GRAPHQL, METEOR.JS, GRUNT, GULF.
HTML: HTML stands for Hyper Text Markup Language. It is used to design the front end
portion of web pages using markup language. HTML is the combination of Hypertext and
Markup language. Hypertext defines the link between the web pages. The markup language is
used to define the text documentation within tag which defines the structure of web pages.
CSS: Cascading Style Sheets, fondly referred to as CSS, is a simply designed language
intended to simplify the process of making web pages presentable. CSS allows you to apply
styles to web pages. More importantly, CSS enables you to do this independent of the HTML
that makes up each web page.
JavaScript: JavaScript is a famous scripting language used to create the magic on the sites to
make the site interactive for the user. It is used to enhancing the functionality of a website to
running cool games and web-based software.
AngularJS: AngularJs is a JavaScript open source front-end framework that is mainly used to
develop single page web applications(SPAs). It is a continuously growing and expanding
framework which provides better ways for developing web applications. It changes the static
HTML to dynamic HTML. It is an open source project which can be freely used and changed
by anyone. It extends HTML attributes with Directives, and data is bound with HTML.
React.js: React is a declarative, efficient, and flexible JavaScript library for building user
interfaces. ReactJS is an open-source, component-based front end library responsible only for
the view layer of the application. It is maintained by Facebook.
Bootstrap: Bootstrap is a free and open-source tool collection for creating responsive websites
and web applications. It is the most popular HTML, CSS, and JavaScript framework for
developing responsive, mobile-first web sites.
jQuery: jQuery is an open source JavaScript library that simplifies the interactions between an
HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript.
Elaborating the terms, jQuery simplifies HTML document traversing and manipulation,
browser event handling, DOM animations, Ajax interactions, and cross-browser JavaScript
development.
SASS: It is the most reliable, mature and robust CSS extension language. It is used to extend
the functionality of an existing CSS of a site including everything from variables, inheritance,
and nesting with ease.Some other libraries and frameworks are: Semantic-UI, Foundation,
Materialize, Backbone.js, Express.js, Ember.js etc.
Other Important Points:
Work with text editors to use shortcuts and its facilities i.e. Visual studio, Atom, Sublime
etc.
Make UI responsible using grid system.
Git and git commands like init, add, commit etc for version control and to work with
team.
Other tools like npm & yarn package managers, sass css pre-processor, browser
DevTools i.e. chrome devtools.
Understand using HTTP, JSON, GraphQL APIs to fetch data using axios or other tools.
It also requires some design skill to make layout and look better.
Back end: It refers to the server-side development of web application or website with a
primary focus on how the website works. It is responsible for managing the database through
queries and APIs by client-side commands. This type of website mainly consists of three parts
front end, back end, and database.
PHP,ASP,C+
+,C#,JAVA,PYTHON,NODE.JS,EXPRESS.JS,RUBY,REST,GO,SQL,MONGODB,FIREBAS
E.COM,SASS,LESS,PARSE.COM,
PASS (AZURE, HEROKU)
The back end portion is built by using some libraries, frameworks, and languages which are
discussed below:
PHP: PHP is a server-side scripting language designed specifically for web
development. Since, PHP code executed on server side so it is called server side
scripting language.
C++ It is a general purpose programming language and widely used now a days for
competitive programming. It is also used as backend language.
Java: Java is one of the most popular and widely used programming language and
platform. It is highly scalable. Java components are easily available.
Python: Python is a programming language that lets you work quickly and integrate
systems more efficiently.
JavaScript: Javascript can be used as both (front end and back end) programming
languages.
Node.js: Node.js is an open source and cross-platform runtime environment for
executing JavaScript code outside of a browser. You need to remember that NodeJS
is not a framework and it’s not a programming language. Most of the people are
confused and understand it’s a framework or a programming language. We often
use Node.js for building back-end services like APIs like Web App or Mobile App.
It’s used in production by large companies such as Paypal, Uber, Netflix, Wallmart
and so on.
Back End Frameworks: The list of back end frameworks are: Express, Django,
Rails, Laravel, Spring etc.
The other backend program/scripting languages are: C#, Ruby, REST, GO etc.
Other Important Points:
Structuring the data in efficient way.
Handle request-response of APIs for storing and retrieve data.
Security of data is important.
Database:
Database is the collection of inter-related data which helps in efficient retrieval,
insertion and deletion of data from database and organizes the data in the form of
tables, views, schemas, reports etc.
Oracle: Oracle database is the collection of data which is treated as a unit. The purpose
of this database is to store and retrieve information related to the query. It is a database
server and used to manages information.
MongoDB: MongoDB, the most popular NoSQL database, is an open source document-
oriented database. The term ‘NoSQL’ means ‘non-relational’. It means that MongoDB
isn’t based on the table-like relational database structure but provides an altogether
different mechanism for storage and retrieval of data.
Sql: Structured Query Language is a standard Database language which is used to
create, maintain and retrieve the relational database.
<html lang="en">
<head>
</head>
<body>
<p>Hello World!<p>
</body>
</html>
To open the file in a browser. Navigate to your file then double click on it. It will open in your
default Web browser. If it does not, open your browser and drag the file to it.
The first line <!DOCTYPE html> is the document type declaration. It instructs the web browser
that this document is an HTML5 document. It is case-insensitive.
The <head> element is a container for the tags that provides information about the document, for
example, <title> tag defines the title of the document.
The <body> element contains the document's actual content (paragraphs, links, images, tables,
and so on) that is rendered in the web browser and displayed to the user.
HTML is written in the form of HTML elements consisting of markup tags. These markup tags
are the fundamental characteristic of HTML. Every markup tag is composed of a keyword,
surrounded by angle brackets, such as <html>, <head>, <body>, <title>, <p>, and so on.
HTML tags normally come in pairs like <html> and </html>. The first tag in a pair is often
called the opening tag (or start tag), and the second tag is called the closing tag (or end tag).
An opening tag and a closing tag are identical, except a slash (/) after the opening angle bracket
of the closing tag, to tell the browser that the command has been completed.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<p>This is a paragraph.</p>
<p>
</p>
</body>
</html>
HTML TAGS:
1. <html> </html> [HTML open / close tags]
2. <h1> </h1> [Heading 1 open / close tags]
3. <h2> </h2> [Heading 2 open / close tags]
4. <h3> </h3> [Heading 3 open / close tags]
5. <h4> </h4> [Heading 4 open / close tags]
6. <h5> </h5> [Heading 5 open / close tags]
7. <h6> </h6> [Heading 6 open / close tags]
8. <title> </title> [Title open/ close tags]
9. <center> </center> [Center alignment open/close tags]
10. <body> </body> [Body open/ close tags]
11. <body bgcolor=”colorname”>
12. <body background=”image.jpg”>
13. <input type=”text” > [input type tags]
14. <input type=”number”>
15. <input type=”radio”>
16. <input type=”checkbox”>
17. <input type=”password”>
18. <input type=”button”>
19. <input type=”submit”>
20. <input type=”reset”>
21. <input type=”date”>
22. <input type=”email”>
23. <input type=”file”>
24. <input type=”color”>
25. <img src=”name.jpg”>
26. <marquee> Type text </marquee>
27. <p> </p> [Paragraph tag]
28. <q> </q> [Quotation tag]
29. <table> </table> [Table tag]
30. <tr> </tr> [Table row]
31. <td> </td> [Table data]
32. <ul> </ul> [Unordered List]
33. <li> </li> [List]
34. <u> </u> [Underline]
35. <br> </br> [Line Break]
36. <hr> [horizontal row]
37. <del> </del> [Strikethrough]
38. <sup> </sup> [Super Script]
39. <sub> </sub> [Sub Script]
40. <select> [Drop down List tag]
<option value="Volvo">Volvo</option>
<option value="Saab">Saab</option>
<option value="Mercedes">Mercedes</option>
<option value="Audi">Audi</option>
</select>
41. <a href=”name.html”>Click Here</a> [anchor tag]
42. <font size="3" color="red">This is some text!</font> [Font tags]
<font size="2" color="blue">This is some text! </font>
<font face="verdana" color="green">This is some text! </font>
43. <textarea rows="4" cols="50"> ………………..</textarea> [Text area]
44. <form action=”pagename.html”> </form> [Action tag]
HTML5
HTML5 is the latest and most enhanced version of HTML. Technically, HTML is not a
programming language, but rather a markup language.
HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML
1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting content on the World
Wide Web.
HTML5 is cooperation between the World Wide Web Consortium (W3C) and the Web
Hypertext Application Technology Working Group (WHATWG).
The new standard incorporates features like video playback and drag-and-drop that have been
previously dependent on third-party browser plug-ins such as Adobe Flash, Microsoft
Silverlight, and Google Gears.
Browser Support:
The latest versions of Apple Safari, Google Chrome, Mozilla Firefox, and Opera all support
many HTML5 features and Internet Explorer 9.0 will also have support for some HTML5
functionality.
The mobile web browsers that come pre-installed on iPhones, iPads, and Android phones all
have excellent support for HTML5.
New Features: HTML5 introduces a number of new elements and attributes that can help you
in building modern websites.
New Semantic Elements − These are like <header>, <footer>, and <section>.
Forms 2.0 − Improvements to HTML web forms where new attributes have been
introduced for <input> tag.
Persistent Local Storage − To achieve without resorting to third-party plugins.
WebSocket − A next-generation bidirectional communication technology for web
applications.
Server-Sent Events − HTML5 introduces events which flow from web server to the
web browsers and they are called Server-Sent Events (SSE).
Canvas − This supports a two-dimensional drawing surface that you can program with
JavaScript.
Audio & Video − You can embed audio or video on your webpages without resorting to
third-party plugins.
Geolocation − Now visitors can choose to share their physical location with your web
application.
Microdata − This lets you create your own vocabularies beyond HTML5 and extend
your web pages with custom semantics.
Drag and drop − Drag and drop the items from one location to another location on the
same webpage.
Why use HTML5:It is enriched with advance features which makes it easy and interactive for
designer/developer and users.
It facilitates you to design better forms and build web applications that work offline.
It provides you advance features for that you would normally have to write JavaScript to do.
The most important reason to use HTML 5 is, we believe it is not going anywhere. It will be here
to serve for a long time according to W3C recommendation.
HTML5 Syntax:
The HTML 5 language has a "custom" HTML syntax that is compatible with HTML 4 and
XHTML1 documents published on the Web, but is not compatible with the more esoteric
SGML features of HTML 4.
HTML 5 does not have the same syntax rules as XHTML where we needed lower case tag
names, quoting our attributes, an attribute had to have a value and to close all empty elements.
HTML5 comes with a lot of flexibility and it supports the following features −
The DOCTYPE:
DOCTYPEs in older versions of HTML were longer because the HTML language was SGML
based and therefore required a reference to a DTD.
DOCTYPE declaration appears at the top of a web page before all other elements. According to
the HTML specification or standards, every HTML document requires a valid document type
declaration to insure that your web pages are displayed the way they are intended to be
displayed.
syntax:
<!DOCTYPE html>
HTML Meta:
The <meta> tags are typically used to provide structured metadata such as a
document's keywords, description, author name, character encoding, and other metadata.
Any number of meta tags can be placed inside the head section of an HTML or XHTML
document.
Metadata will not be displayed on the web page, but will be machine parsable, and can be
used by the browsers, search engines like Google or other web services.
syntax:
<meta charset = "UTF-8">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
It's common practice to add a type attribute with a value of "text/javascript" to script elements
as follows −
HTML 5 removes extra information required and you can use simply following syntax −
HTML 5 removes extra information required and you can simply use the following syntax −
HTML 5 Tags:
There is a list of newly included tags in HTML 5. These HTML 5 tags (elements) provide a
better document structure. This list shows all HTML 5 tags in alphabetical order with
description.
Tag Description
<aside> It specifies that article is slightly related to the rest of the whole page.
<bdi> The bdi stands for bi-directional isolation. It isolates a part of text that is
formatted in other direction from the outside text document.
<menuitem> It defines a command that the user can invoke from a popup menu.
<rp> It defines what to show in browser that don't support ruby annotation.
It specifies
<summary> a visible heading for <detailed> element.
Graphics Tags
Type Description
datetime It defines full date and time display with time zone information.
month It defines the input field to enter month for the particular year
week It defines a selector for week value for the particular year.
HTML5 Elements:
HTML5 elements are marked up using start tags and end tags. Tags are delimited using angle
brackets with the tag name in between.
The difference between start tags and end tags is that the latter includes a slash before the tag
name.
<p>...</p>
HTML5 tag names are case insensitive and may be written in all uppercase or mixed case,
although the most common convention is to stick with lowercase.
Most of the elements contain some content like <p>...</p> contains a paragraph. Some
elements, however, are forbidden from containing any content at all and these are known as
void elements. For example, br, hr, link, meta, etc.
HTML5 Attributes
Elements may contain attributes that are used to set various properties of an element.
Some attributes are defined globally and can be used on any element, while others are defined
for specific elements only.
The example of an HTML5 attribute which illustrates how to mark up a div element with an
attribute named class using a value of "example" −
Attributes may only be specified within start tags and must never be used in end tags.
HTML5 attributes are case insensitive and may be written in all uppercase or mixed case,
although the most common convention is to stick with lowercase.
In addition to the element specific attributes, the HTML5 defines few attributes that are common
to all elements. These attributes may be specified on all elements, with some exceptions where it
is not relevant, such as elements found inside the <head> section of the document,
e.g. <base>, <script>, <title> etc.
accesskey shortcut key Specifies a keyboard shortcut to activate or focus the element.
contenteditable true Indicates whether the content of an element is editable by the user
false or not.
contextmenu menu-id Specifies a context menu for an element. A context menu is a menu
that appears when the user clicks the right mouse button on the
element.
data-* data Specified on any HTML element, to store custom data specific to
the page.
dir ltr Specifies the base direction of directionality of the element's text.
rtl
dropzone copy Specifies whether the dragged data is copied, moved, or linked,
move when dropped.
link
hidden hidden Indicates that the element is not yet, or is no longer, relevant.
lang language- Specifies the primary language for the element's text content.
code
spellcheck true Specifies whether the element may be checked for spelling errors
false or not.
xml:lang language- Specifies the primary language for the element's text content, in
code XHTML documents.
Event Attributes in HTML5
The following event attributes can be applied to the most of the elements for the execution of
JavaScript when certain events occur, with some exceptions where it is not relevant such as
elements found inside the <head> section, e.g. <title>, <base>, <link> etc.
Window Events
Onhashchange script Fires when the fragment identifier part of the document's URL i.e. the
portion of a URL that follows the sign (#) changes.
Onmessage script Fires when the message event occurs i.e. when user sends a cross-
document message or a message is sent from a worker
with postMessage() method. See HTML5 Web Workers.
Onoffline script Fires when the network connection fails and the browser starts
working offline.
Ononline script Fires when the network connections returns and the browser starts
Attribute Value Description
working online.
Onpagehide script Fires when the page is hidden, such as when a user is moving to
another webpage.
Onpageshow script Fires when the page is shown, such as when a user navigates to a
webpage.
Onpopstate script Fires when changes are made to the active history.
Onunload script Fires immediately before the document is unloaded or the browser
window is closed.
Form Events
Events that occur due to the user interacting with the HTML form controls.
Onchange script Fires when the value or state of the element is changed.
Oninput script Fires when the value of an element is changed by the user.
Oninvalid script Fires when a submittable element do not satisfy their constraints
during form validation.
Onselect script Fires when some text is being selected or the current selection is
changed by the user.
Onsearch script Fires when the user writes something in a search input field.
Mouse Events
Events that occur due to the user interacting with a pointing device such as a mouse:
Onclick script Fires when the user clicks the left mouse button on the element.
Oncontextmenu script Fires when a context menu is triggered by the user through right-click
on the element.
Ondrag script Fires when the user drags an element. The ondrag event fires
throughout the drag operation.
Attribute Value Description
Ondragend script Fires when the user releases the mouse button at the end of a drag
operation.
Ondragenter script Fires when the user drags an element to a valid drop target.
Ondragleave script Fires when an element leaves a valid drop target during a drag
operation.
Ondragover script Fires when an element is being dragged over a valid drop target.
Ondragstart script Fires when the user starts to drag a text selection or selected element.
Ondrop script Fires when the mouse button is released during a drag-and-drop
operation i.e. when dragged element is being dropped.
Onmousedown script Fires when the mouse button is pressed over an element.
Onmousemove script Fires when the user moves the mouse pointer over an element.
Onmouseout script Fires when the user moves the mouse pointer outside the boundaries of
an element.
Onmouseover script Fires when the user moves the mouse pointer onto an element.
Onmouseup script Fires when the user releases the mouse button while the mouse is over
an element.
Onscroll script Fires when the user scrolls the contents of an element by scrolling the
element's scrollbar.
Onshow script Fires when a contextmenu event was fired onto an element that has
a contextmenu attribute.
Attribute Value Description
Ontoggle script Fires when the user opens or closes the <details> element.
Onwheel script Fires when the user scrolls the contents of an element by rolling the
mouse wheel up or down over an element.
Keyboard Events
Events that occur by the user interaction with the keyboard:
Clipboard Events
Events related to modification of the clipboard, that is copy, cut and paste:
Oncopy script Fires when the user copies the element or selection, adding it to the
system clipboard.
Oncut script Fires when the element or selection is removed from the document and
added to the system clipboard.
Onpaste script Fires when the user pastes data, transferring the data from the system
clipboard to the document.
Media Events
Events that occur when handling media elements that are embedded inside the HTML
documents, such as <audio> and <video> elements:
Onabort script Fires when playback is aborted, but not due to an error.
Oncanplay script Fires when enough data is available to play the media, at least for a
couple of frames, but would require further buffering.
Oncanplaythroug script Fires when entire media can be played to the end without requiring to
h stop for further buffering.
Oncuechange script Fires when the text track cue in a <track> element changes.
Onemptied script Fires when the media element is reset to its initial state, either
because of a fatal error during load, or because the load() method is
called to reload it.
Onerror script Fires when an error occurs while fetching the media data.
Onloadeddata script Fires when media data is loaded at the current playback position.
onloadedmetadata script Fires when metadata of the media (like duration and dimensions) has
finished loading.
Onplay script Fires when playback of the media starts after having been paused i.e.
when the play() method is requested.
Attribute Value Description
Onplaying script Fires when the audio or video has started playing.
Onprogress script Fires periodically to indicate the progress while downloading the
media data.
Onratechange script Fires when the playback rate or speed is increased or decreased, like
slow motion or fast forward mode.
Onsuspend script Fires when the loading of the media is intentionally stopped.
Ontimeupdate script Fires when the playback position changed, like when the user fast
forwards to a different playback position.
Onvolumechange script Fires when the volume is changed, or playback is muted or unmuted.
Onwaiting script Fires when playback stops because the next frame of a video resource
is not available.
HTML HTML5
HTML Doctype declaration is lengthy. DOCTYPE declaration in HTML5 is simple.
Audio and video are not HTML parts. Audio and video are HTML5 part.
It is possible to draw a vector with the help of other Vector graphics are a part of HTML5, e.g.,
technologies like Silverlight, Flash, VML, etc. canvas, SVG.
It is impossible to get the actual Geolocation of a JS Geolocation API in HTML5 enables you to
person browsing any website. identify the location of the user browsing any
website.
HTML offers local storage instead of cookies. Html5 uses cookies to store data.
In HTML, it is not possible to draw basic shapes. In Html5, it is possible to draw basic shapes.
It allows you to run JavaScript in a browser. It enables you to run JavaScript code in the
background.
You can use HTML with all old browsers. You can use HTML5 with all new browsers.
You can use browser cache as temporary storage. You can use application (database and web
storage) Cache as temporary storage.
There is no process to handlestructurally incorrect HTML5 supports persistent error handling via
HTML codes. the improvised error handling process.
Attributes like async, charset, and ping are not present Attributes of async, ping, charset, and are a part
in HTML. of HTML5.
HTML does not allow drag and drop effects HTML5 allows drag and drop effects.
Offer new attributes like tabinex, id, tabinex, etc. These are certain attributes which are applied to
HTML 5 elements.
HTML 5 supports <video> tag also. The HTML video tag is used for streaming video files such
as a movie clip, song clip on the web page.
Currently, there are three video formats supported for HTML video tag:
1. mp4
2. webM
3. ogg
yes no no
Internet Explorer
yes no no
Apple Safari
Let's see the code to play mp4 file using HTML video tag.
<!DOCTYPE>
<html>
<body>
<video controls>
<source src="movie.mp4" type="video/mp4">
</video>
</body>
</html>
Attributes of HTML Video Tag:
Attribute Description
controls It defines the video controls which is displayed with play/pause buttons.
poster It specifies the image which is displayed on the screen when the video is not
played.
autoplay It specifies that the video will start playing as soon as it is ready.
loop It specifies that the video file will start over again, every time when it is completed.
preload It specifies the author view to upload video file when the page loads.
Let's see the example of video tag in HTML where are using height, width, autoplay, controls
and loop attributes.
<!DOCTYPE>
<html>
<body>
<video width="320" height="240" controls autoplay loop>
</video>
</body>
</html>
Output:
HTML audio tag is used to define sounds such as music and other audio clips. Currently there
are three supported file format for HTML 5 audio tag.
1. mp3
2. wav
3. ogg
HTML5 supports <video> and <audio> controls. The Flash, Silverlight and similar technologies
are used to play the multimedia items.
This table defines that which web browser supports which audio file format.
yes no no
Internet Explorer
yes yes no
Apple Safari
<!DOCTYPE>
<html>
<body>
<audio controls>
<source src="koyal.mp3" type="audio/mpeg">
</audio>
</body>
</html>
Attribute Description
controls It defines the audio controls which is displayed with play/pause buttons.
autoplay It specifies that the audio will start playing as soon as it is ready.
loop It specifies that the audio file will start over again, every time when it is completed.
preload It specifies the author view to upload audio file when the page loads.
Here we are going to use controls, autoplay, loop and src attributes of HTML audio tag.
<!DOCTYPE>
<html>
<body>
</body>
</html>
The HTML element is used to draw graphics on the fly, via scripting (usually JavaScript). The
element is only a container for graphics. You must use a script to actually draw the graphics.
Canvas has several methods for drawing paths, boxes, circles, text, and adding images.
A canvas is a rectangle like area on an HTML page. It is specified with canvas element. By
default, the <canvas> element has no border and no content, it is like a container.
<!DOCTYPE>
<html>
<body>
<canvas id="myCanvas" width="300" height="200" style="border:2px solid;">
</canvas>
</body>
</html>
output:
Supporting Browsers:
Coordinates (0,0) defines the upper left corner of the canvas. The parameters (0,0,200,100) is
used for fillRect() method. This parameter will fill the rectangle start with the upper-left corner
(0,0) and draw a 200 * 100 rectangle.
1. <canvas id="myCanvas" width="250" height="150" style="border:1px solid #c3c3c3;">
2. </canvas>
3. <script>
4. var c = document.getElementById("myCanvas");
5. var cctx = c.getContext("2d");
6. ctx.fillStyle = "#FF0000";
7. ctx.fillRect(0,0,200,100);
8. </script>
If you want to draw a straight line on the canvas, you can use the following two methods.
If you draw a line which starting point is (0,0) and the end point is (200,100), use the stroke
method to draw the line.
10. Output:
Drawing Circle on Canvas
If you want to draw a circle on the canvas, you can use the arc() method:
To sketch circle on HTML canvas, use one of the ink() methods, like stroke() or fill().
Output:
There are property and methods used for drawing text on the canvas.
font property: It is used to define the font property for the text.
fillText(text,x,y) method: It is used to draw filled text on the canvas. It looks like bold font.
strokeText(text,x,y) method: It is also used to draw text on the canvas, but the text is unfilled.
Let's see fillText() method example.
Output:
HELLO WORLD
SVG
The Scalable Vector Graphics (SVG) is an XML-based image format that is used to define
two-dimensional vector-based graphics for the web. Unlike raster image (Ex .jpg, .gif, .png,
etc.), a vector image can be scaled up or down to any extent without losing the image quality.
An SVG image is drawn out using a series of statements that follow the XML schema — that
means SVG images can be created and edited with any text editor, such as Notepad. There are
several other advantages of using SVG over other image formats like JPEG, GIF, PNG, etc.
<!DOCTYPE html>
<html>
<body>
<svg width="100" height="100">
<circle cx="50" cy="50" r="40" stroke="yellow" stroke-width="4" fill="red" />
</svg>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<body>
<svg width="200" height="100">
</svg>
</body>
</html>
output:
<!DOCTYPE html>
<html>
<body>
style="fill:red;stroke:yellow;stroke-width:5;fill-rule:nonzero;" />
</svg>
</body>
</html>
Web Storage
The Web Storage is one of the great features of HTML5. With the Web Storage feature, web
applications can locally store data within the browser on the client side. It stores data in the form
of key/value pair on the browser. Web Storage sometimes also known as DOM storage.
Storing data with the help of web storage is similar to cookies, but it is better and faster than
cookies storage.
o Web Storage can use storage space upto 5MB per domain. (The browser software may
prompt the user if the space limit is reached).
o It will not send data to the server side, hence it is faster than cookies storage.
o The data stored by local Storage never expires, but cookies data expires after some time
or session.
o Web Storage is more secure than cookies.
o Local Storage: Local Storages uses Windows. localStaorage object which stores data
and available for every page. But data persist even if the browser is closed and reopened
(Stores data with no Expiration).
o Session Storage: Session Storage uses Windows.sessionStorage object which stores data
for one session and data will be lost if the window or browser tab will be closed.
HTML web storage provides two objects for storing data on the client:
Before using web storage, check browser support for localStorage and sessionStorage:
The localStorage object stores the data with no expiration date. The data will not be deleted
when the browser is closed, and will be available the next day, week, or year.
Example:
<!DOCTYPE html>
<html>
<body>
<div id="result"></div>
<script>
// Check browser support
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
} else {
</script>
</body>
</html>
Output: Smith
Example 2:
<!DOCTYPE html>
<html>
<head>
<style>
body{
color: green;
text-align: center;
font-size: 30px;
margin-top: 30px;
font-style: italic;
</style>
</head>
<body>
<script>
if(typeof(Storage)!=="undefined") {
localStorage.setItem("name","Harshita");
localStorage.setItem("Country", "India");
else{
</script>
</body>
</html>
The sessionStorage object is equal to the localStorage object, except that it stores the data for
only one session. The data is deleted when the user closes the specific browser tab.
The following example counts the number of times a user has clicked a button, in the current
session:
<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {
if (sessionStorage.clickcount) {
sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
} else {
sessionStorage.clickcount = 1;
} else {
</script>
</head>
<body>
<div id="result"></div>
<p>Click the button to see the counter increase.</p>
<p>Close the browser tab (or window), and try again, and the counter is reset.</p>
Output:
Click me!
Close the browser tab (or window), and try again, and the counter is reset.
As we have seen the session storage data will automatically be deleted, when you close the
browser but the data saved by local storage will remain in the browser even if you close it.
Hence to delete the local storage data, you need to call two methods:
Example:
<!DOCTYPE html>
<html>
<head>
<style>
body{
color: green;
text-align: center;
font-size: 30px;
margin-top: 30px;
font-style: italic;
</style>
</head>
<body>
<div id="output"></div>
<script>
if(typeof(Storage)!=="undefined") {
localStorage.setItem("name","Harshita");
localStorage.setItem("Country", "India");
else{
function remove() {
localStorage.removeItem("name");
</script>
</body>
</html>
Output:
Remove item
Hii, my name is undefined and i belongs to India
HTML Drag and Drop (DnD) is a feature of HTML5. It is a powerful user interface concept
which is used to copy, reorder and delete items with the help of mouse. You can hold the mouse
button down over an element and drag it to another location. If you want to drop the element
there, just release the mouse button.
Drag and drop is a very common feature. It is when you "grab" an object and drag it to a
different location. HTML 5 DnD is supported by all the major browsers like Chrome, Firefox 3.5
and Safari 4.
1 dragstart
Fires when the user starts dragging of the object.
dragenter
2 Fired when the mouse is first moved over the target element while a drag is occurring. A
listener for this event should indicate whether a drop is allowed over this location. If there
are no listeners, or the listeners perform no operations, then a drop is not allowed by
default.
dragover
3 This event is fired as the mouse is moved over an element when a drag is occurring.
Much of the time, the operation that occurs during a listener will be the same as the
dragenter event.
dragleave
4
This event is fired when the mouse leaves an element while a drag is occurring. Listeners
should remove any highlighting or insertion markers used for drop feedback.
5 drag
Fires every time the mouse is moved while the object is being dragged.
drop
6 The drop event is fired on the element where the drop was occurred at the end of the drag
operation. A listener would be responsible for retrieving the data being dragged and
inserting it at the drop location.
7 dragend
Fires when the user releases the mouse button while dragging an object.
dataTransfer.dropEffect [ = value ]
1 Returns the kind of operation that is currently selected.
This attribute can be set, to change the selected operation.
The possible values are none, copy, link, and move.
dataTransfer.effectAllowed [ = value ]
dataTransfer.types
3
Returns a DOMStringList listing the formats that were set in the dragstart event. In
addition, if any files are being dragged, then one of the types will be the string "Files".
4 dataTransfer.clearData ( [ format ] )
Removes the data of the specified formats. Removes all data if the argument is omitted.
5 dataTransfer.setData(format, data)
Adds the specified data.
6 data = dataTransfer.getData(format)
Returns the specified data. If there is no such data, returns the empty string.
7 dataTransfer.files
Returns a FileList of the files being dragged, if any.
dataTransfer.setDragImage(element, x, y)
8
Uses the given element to update the drag feedback, replacing any previously specified
feedback.
9 dataTransfer.addElement(element)
Adds the given element to the list of elements used to render the drag feedback.
<html>
<head>
#boxA, #boxB {
float:left;padding:10px;margin:10px; -moz-user-select:none;
</style>
function dragStart(ev) {
ev.dataTransfer.effectAllowed = 'move';
ev.dataTransfer.setData("Text", ev.target.getAttribute('id'));
ev.dataTransfer.setDragImage(ev.target,0,0);
return true;
</script>
</head>
<body>
<center>
<p>Drag Me</p>
</div>
<div id = "boxB">Dustbin</div>
</center>
</body>
</html>
Output:
Drag Me
Dustbin
Output:
Drag and drop HTML5 demo
Try to move the purple box into the pink box.
Drag Me
Dustbin
Stages during Drag and Drop operations:
If you want to make an element draggable, set the draggable attribute to "true" on the element.
For example:
2) What to drag:
3) Where to Drop:
4) Do the Drop:
HTML5 Geolocation
The Geolocation is one of the best HTML5 API which is used to identify the user's
geographic location for the web application.
This new feature of HTML5 allows you to navigate the latitude and longitude coordinates of
the current website's visitor. These coordinates can be captured by JavaScript and send to the
server which can show your current location on the website
Most of the geolocation services use Network routing addresses such as IP addresses, RFID,
WIFI and MAC addresses or internal GPS devices to identify the user's location.
User privacy:
The user's location is the privacy concern, so geolocation API protects the user's privacy by
taking the user's permission before getting the location. Geolocation API sends a notification
prompt box which user can allow or deny, and if the user allows then only his location will be
identified.
The HTML Geolocation API is used to get the geographical position of a user.
Since this can compromise privacy, the position is not available unless the user approves it.
Geolocation object
The Geolocation API is work with the navigation.geolocation object. Its read-only property
returns a Geolocation object which identifies the location of the user and can generate a
customized result based on user location.
Syntax:
geo=navigator. geolocation;
If this object is present, then you can get the geolocation services.
Geolocation Methods:
The Geolocation API uses three methods of Geolocation interface which are given following:
Methods Description
getCurrentPosition() It identifies the device or the user's current location and returns a
position object with data.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Geolocation API</title>
</head>
<body>
<div id="location"></div>
<script>
var x= document.getElementById("location");
function getlocation() {
if(navigator.geolocation){
else
}
</script>
</body>
</html>
Click me
The example below returns the latitude and longitude of the user's position:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
else {
function showPosition(position) {
</script>
</body>
</html>
Try it
Latitude: 17.6028245
Longitude: 78.48654909999999
Example explained:
The example above is a very basic Geolocation script, with no error handling.
The second parameter of the getCurrentPosition() method is used to handle errors. It specifies a
function to run if it fails to get the user's location:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
function showPosition(position) {
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
break;
case error.POSITION_UNAVAILABLE:
break;
case error.TIMEOUT:
break;
case error.UNKNOWN_ERROR:
break;
</script>
</body>
</html>
Output:
Try It
Displaying the Result in a Map:
To display the result in a map, you need access to a map service, like Google Maps.
In the example below, the returned latitude and longitude is used to show the location in a
Google Map (using a static image):
Example:
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude;
Location-specific Information
Property Returns
coords.altitude The altitude in meters above the mean sea level (returned if available)
watchPosition() - Returns the current position of the user and continues to return updated
position as the user moves (like the GPS in a car).
clearWatch() - Stops the watchPosition() method.
The example below shows the watchPosition() method. You need an accurate GPS device to test
this (like smartphone):
Example:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
function showPosition(position) {
</script>
</body>
</html>
Output
CSS3 has been split into "modules". It contains the "old CSS specification" (which has been split
into smaller pieces).
Selectors
Box Model
Backgrounds and Borders
Image Values and Replaced Content
Text Effects
2D/3D Transformations
Animations
Multiple Column Layout
User Interface
Features of CSS3:
The features of the CSS3 are as follows:
1. Selectors
Selectors allow the designer to select on more precise levels of the web page. They are structural
pseudo-classes that perform partial matches to help match attribute and attribute values. New
selectors target a pseudo-class to style the elements targeted in the URL. Selectors also include a
checked pseudo-class to style checked elements such as checkboxes and radio buttons.
2. Text Effects and Layout
With CSS3, we can change the justification of text, whitespace adjustment of the document, and
achieve a visually pleasing effect) and positioning drop-caps (large decorative capital letter at the
starting of a paragraph).
footers. There are additional properties for printing Generated Content as well, like properties for
5. Multi-Column Layout
This feature includes properties to allow designers to present their content in multiple columns
Advantages of CSS3
It is easy to customize a web page as it can be done by merely altering a modular file.
Graphics are easier in CSS3, thus making it easy to make the site appealing.
i) Inline Styles:
Inline styles are used to apply the unique style rules to an element by putting the CSS rules
directly into the start tag. It can be attached to an element using the style attribute.
The style attribute includes a series of CSS property and value pairs. Each "property: value" pair
is separated by a semicolon (;), just as you would write into an embedded or external style
sheets. But it needs to be all in one line i.e. no line break after the semicolon, as shown here:
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
</body>
</html>
Embedded or internal style sheets only affect the document they are embedded in.
Embedded style sheets are defined in the <head> section of an HTML document using
the <style> element. You can define any number of <style> elements in an HTML document but
they must appear between the <head> and </head> tags.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
p { color: #fff; }
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
iii) External Style Sheets:
An external style sheet is ideal when the style is applied to many pages of the website.
An external style sheet holds all the style rules in a separate document that you can link from any
HTML file on your site. External style sheets are the most flexible because with an external style
sheet, you can change the look of an entire website by changing just one file.
An external style sheet can be linked to an HTML document using the <link> tag. The <link> tag
goes inside the <head> section.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
i) Static Positioning:
A static positioned element is always positioned according to the normal flow of the page.
HTML elements are positioned static by default. Static positioned elements are not affected by
the top, bottom, left, right, and z-index properties.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.box{
color: #fff;
background: #7dc765;
padding: 20px;
.container{
padding: 50px;
margin: 50px;
position: relative;
.container p{
line-height: 50px;
</style>
</head>
<body>
<div class="container">
<div class="box">
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius
quam at, luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante.
Vestibulum id metus ac nisl bibendum scelerisque non non purus. Suspendisse varius nibh non
aliquet sagittis. In tincidunt orci sit amet elementum vestibulum. Vivamus fermentum in arcu in
aliquam. Quisque aliquam porta odio in fringilla. Vivamus nisl leo, blandit at bibendum eu,
tristique eget risus. Integer aliquet quam ut elit suscipit, id interdum neque porttitor. Integer
faucibus ligula.</p>
<p>Quis quam ut magna consequat faucibus. Pellentesque eget nisi a mi suscipit tincidunt.
Ut tempus dictum risus. Pellentesque viverra sagittis quam at mattis. Suspendisse potenti.
Aliquam sit amet gravida nibh, facilisis gravida odio. Phasellus auctor velit at lacus blandit,
commodo iaculis justo viverra. Etiam vitae est arcu. Mauris vel congue dolor. Aliquam eget mi
mi. Fusce quam tortor, commodo ac dui quis, bibendum viverra erat. Maecenas mattis lectus
enim, quis tincidunt dui molestie euismod. Curabitur et diam tristique, accumsan nunc eu.</p>
</div>
</body></html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.box{
position: absolute;
top: 200px;
left: 100px;
color: #fff;
width: 60%;
background: #4cafdf;
padding: 20px;
.container{
padding: 50px;
margin: 50px;
position: relative;
.container p{
line-height: 50px;
</style>
</head>
<body>
<div class="container">
<div class="box">
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius
quam at, luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante.
Vestibulum id metus ac nisl bibendum scelerisque non non purus. Suspendisse varius nibh non
aliquet sagittis. In tincidunt orci sit amet elementum vestibulum. Vivamus fermentum in arcu in
aliquam. Quisque aliquam porta odio in fringilla. Vivamus nisl leo, blandit at bibendum eu,
tristique eget risus. Integer aliquet quam ut elit suscipit, id interdum neque porttitor. Integer
faucibus ligula.</p>
<p>Quis quam ut magna consequat faucibus. Pellentesque eget nisi a mi suscipit tincidunt.
Ut tempus dictum risus. Pellentesque viverra sagittis quam at mattis. Suspendisse potenti.
Aliquam sit amet gravida nibh, facilisis gravida odio. Phasellus auctor velit at lacus blandit,
commodo iaculis justo viverra. Etiam vitae est arcu. Mauris vel congue dolor. Aliquam eget mi
mi. Fusce quam tortor, commodo ac dui quis, bibendum viverra erat. Maecenas mattis lectus
enim, quis tincidunt dui molestie euismod. Curabitur et diam tristique, accumsan nunc eu.</p>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of Setting background-size of an Element</title>
<style>
.box {
width: 250px;
height: 150px;
background: url("/examples/images/sky.jpg") no-repeat;
background-size: contain;
border: 6px solid #333;
}
</style>
</head>
<body>
<div class="box"></div>
<p><strong>Note:</strong> The original size of the background image is 500x300
pixels, but using the background-size CSS property we are still able to show the
complete image inside the smaller box.</p>
</body>
</html>
ii) CSS3 background-clip Property:
The background-clip property can be used to specify whether an element's background extends
into the border or not. The background-clip property can take the three values: border-
box, padding-box, content-box.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example of CSS3 Background Clipping</title>
<style>
.box {
width: 250px;
height: 150px;
padding: 10px;
border: 6px dashed #333;
background: orange;
}
.clip1 {
background-clip: border-box;
}
.clip2 {
background-clip: padding-box;
}
.clip3 {
background-clip: content-box;
}
</style>
</head>
<body>
<h2>Default Background Behavior</h2>
<div class="box"></div>
<h2>Background Clipping Using border-box</h2>
<div class="box clip1"></div>
<h2>Background Clipping Using padding-box</h2>
<div class="box clip2"></div>
<h2>Background Clipping Using content-box</h2>
<div class="box clip3"></div>
</body>
</html>
iii) CSS3 background-origin Property:
The background-origin property can be used to specify the positioning area of the background
images. It can take the same values as background-clip property: border-box, padding-
box, content-box.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.box {
width: 250px;
height: 150px;
padding: 10px;
background-size: contain;
background-origin: content-box;
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
iv) CSS3 Multiple Backgrounds:
CSS3 gives you ability to add multiple backgrounds to a single element. The backgrounds are
layered on the top of one another. The number of layers is determined by the number of comma-
separated values in the background-image or background shorthand property.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.box {
width: 100%;
height: 500px;
</style>
</head>
<body>
<div class="box"></div>
</body></html>
BootStrap
Bootstrap: Bootstrap 4 is the newest version of Bootstrap. Bootstrap can be defined as free and
open-source frameworks that can be used to create responsive, mobile-first, front-end web pages.
Advantages of Bootstrap:
1. The first and foremost advantage of using Bootstrap is that it is very easy to use and
implement. If a person has some basic knowledge of HTML and CSS, that user can easily
use Bootstrap.
2. The fact that Bootstrap can adapt to the size of any phone, tablet, desktop and so on is
also very interesting feature.
3. Bootstrap 4 is also useful because it is compatible with all modern browsers which
include Google Chrome, Firefox, Internet Explorer 10+, Edge, Safari, and Opera.
4. It also produces less cross-browser bugs.
5. It is light weighted and consequently it can be widely used as a framework for creating
responsive sites.
6. Lastly, Bootstrap 4 is a very simple and yet very effective grid system.
Usages of Bootstrap 4:
Disadvantages:
1.In many cases, Bootstrap cannot be considered very practical for businesses that need a
big amount of investment.
2.Moreover, Bootstrap 4 can take a lot of time to create a website. Therefore, it is not a
very bright idea to use bootstrap 4 when there is no investment.
3.A person using Bootstrap 4 is not likely to earn any money even after investment.
4.And this is one of the reasons why a user can very easily end up in a lot of debt.
Environment Setup
Bootstrap 4 is the latest version of Bootstrap. In this section, it is shown how to download and
setup Bootstrap 4.
a) The first method that can be used is to start using Bootstrap 4 by inserting it from the CDN
which stands for Content Delivery Network.
Using CDN: The Bootstrap 4 can be used in the website by inserting it from the CDN which is
short for - Content Delivery Network.
The code given below can be used to compile the Bootstrap's CDN of CSS and JS in the project.
<!-- Compiled and Minified Bootstrap CSS --><link rel = "stylesheet" href = "https://
maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity = "sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" cro
ssorigin = "anonymous"><!-- jQuery Library --><script src = "https://code.jquery.com/jquery-
3.2.1.slim.min.js" integrity = "sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/
Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin = "anonymous"></script><!-- P
opper --><script src = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/
popper.min.js" integrity = "sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/
ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin = "anonymous"></script><!-- Compil
ed and Minified Bootstrap JavaScript --><script src = "https://maxcdn.bootstrapcdn.com/
bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/
JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"></script>
In this process, also insert the CDN versions of jQuery and Popper.js which is used for the
purpose of using the different JavaScript components, for example - modals, tooltips, popovers,
and so on. This needs to be before the minified Bootstrap JavaScript, if the compiled version
of JavaScript is being used.
There are some components that extensively require the jQuery. Following are some of these
components -
Downloading Bootstrap 4:
Download - By choosing this option, a user can download the pre-compiled and minified
versions of Bootstrap's CSS and JavaScript. No documentation or original source code files are
included. However, this does not consist of the documentation, the source files, or any other
optional JavaScript dependencies such as jQuery and Popper.js.
Download Source - By choosing this option, a person can get the latest Bootstrap SCSS,
JavaScript source code and documentation files. Moreover, this option also needs some
additional tooling such as:
a )Sass compiler like Libsass or Ruby Sass is supported for compiling the CSS in the website.
Precompiled Bootstrap 4:
Once the compiled version Bootstrap 4 is downloaded, extract the ZIP file, and you will see the
following file/directory structure -
1. bootstrap/
2. ├── css/
3. │ ├── bootstrap.css
4. │ ├── bootstrap.css.map
5. │ ├── bootstrap.min.css
6. │ ├── bootstrap.min.css.map
7. │ ├── bootstrap-theme.css
8. │ ├── bootstrap-theme.css.map
9. │ ├── bootstrap-theme.min.css
10. │ └── bootstrap-theme.min.css.map
11. ├── js/
12. │ ├── bootstrap.js
13. │ └── bootstrap.min.js
14. └── fonts/
15. ├── glyphicons-halflings-regular.eot
16. ├── glyphicons-halflings-regular.svg
17. ├── glyphicons-halflings-regular.ttf
18. ├── glyphicons-halflings-regular.woff
19. └── glyphicons-halflings-regular.woff2
There are compiled CSS and JS (bootstrap.*), as well as compiled and minified CSS and JS
(bootstrap.min.*).
The Bootstrap source code download includes the precompiled CSS, JavaScript, and font assets,
along with source Less, JavaScript, and documentation. More specifically, it includes the
following and more -
1. bootstrap/
2. ├── less/
3. ├── js/
4. ├── fonts/
5. ├── dist/
6. │ ├── css/
7. │ ├── js/
8. │ └── fonts/
9. └── docs/
10. └── examples/
a. The files under the js/ and scss/ are the source code responsible for Bootstrap, CSS and
JavaScript.
b. The dist/ folder consists of everything that is listed in the pre-compiled download section
that is given above.
c. The docs/examples/ only consists of the source code for Bootstrap documentation and
examples of Bootstrap usage respectively.
d. The less/ in the source code given above is basically responsible for the source code for
the icon fonts in Bootstrap 4.
e. Apart from that, the other included files provide support for other important components
such as the packages, the information about the license, and anything related to
development.
Bootstrap Templates
Navbar
Navigation Bars:A navigation bar is a navigation header that is placed at the top of the page:
i) Basic Navbar:
With Bootstrap, a navigation bar can extend or collapse, depending on the screen size.
A standard navigation bar is created with the .navbar class, followed by a responsive collapsing
class: .navbar-expand-xl|lg|md|sm (stacks the navbar vertically on extra large, large, medium or
small screens).
To add links inside the navbar, use a <ul> element with class="navbar-nav". Then
add <li> elements with a .nav-item class followed by an <a> element with a .nav-link class:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-light">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
</ul>
</nav>
<br>
<div class="container-fluid">
<h3>Basic Navbar Example</h3>
<p>A navigation bar is a navigation header that is placed at the top of the page.</p>
<p>The navbar-expand-xl|lg|md|sm class determines when the navbar should stack
vertically (on extra large, large, medium or small screens).</p>
</div>
</body>
</html>
ii) Vertical Navbar:
Link 1
Link 2
Link 3
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
The following example will center the navigation bar on medium, large and extra large screens.
On small screens it will be displayed vertically and left-aligned (because of the .navbar-expand-
sm class):
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-sm bg-light justify-content-center">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Link 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link 3</a>
</li>
</ul>
</nav>
<br>
<div class="container-fluid">
<h3>Centered Navbar</h3>
<p>Use the .justify-content-center class to center the navigation bar.</p>
<p>In this example, the navbar will be centered on medium, large and extra large
screens. On small screens it will be displayed vertically and left-aligned (because of
the .navbar-expand-sm class).</p>
</div>
</body>
</html>
iv) Colored Navbar:
Use any of the .bg-color classes to change the background color of the navbar (.bg-primary, .bg-
success, .bg-info, .bg-warning, .bg-danger, .bg-secondary, .bg-dark and .bg-light)
Tip: Add a white text color to all links in the navbar with the .navbar-dark class, or use
the .navbar-light class to add a black text color.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h3>Colored Navbar</h3>
<p>Use any of the .bg-color classes to add a background color to the navbar.</p>
<p>Tip: Add a white text color to all links in the navbar with the .navbar-dark class,
or use the .navbar-light class to add a black text color.</p>
</div>
<nav class="navbar navbar-expand-sm bg-light navbar-light">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</nav>
The .navbar-brand class is used to highlight the brand/logo/project name of your page:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<h3>Brand / Logo</h3>
<p>The .navbar-brand class is used to highlight the brand/logo/project name of your
page.</p>
</div>
</body>
</html>
vi) Collapsing The Navigation Bar: Very often, especially on small screens, you want to hide
the navigation links and replace them with a button that should reveal them when clicked on.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<span class="navbar-toggler-icon"></span>
</button>
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
</div>
</nav>
<br>
<div class="container">
<h3>Collapsible Navbar</h3>
<p>In this example, the navigation bar is hidden on small screens and replaced by a button in
the top right corner (try to re-size this window).</p>
<p>Only when the button is clicked, the navigation bar will be displayed.</p>
<p>Tip: You can also remove the .navbar-expand-md class to ALWAYS hide navbar links and
display the toggler button.</p>
</div>
</body>
</html>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<li class="nav-item">
</li>
<li class="nav-item">
</li>
Dropdown link
</a>
<div class="dropdown-menu">
</div>
</li>
</ul>
</nav>
<br>
<div class="container">
</div>
</body>
</html>
viii) Navbar Forms and Buttons: Add a <form> element with class="form-inline" to group
inputs and buttons side-by-side:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
</form>
</nav>
<br>
<div class="container">
<h3>Navbar Forms</h3>
<p>Use the .form-inline class to align form elements side by side inside the navbar.</p>
</div>
</body>
</html>
ix) Navbar Text: Use the .navbar-text class to vertical align any elements inside the navbar that
are not links (ensures proper padding and text color).
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
</li>
</ul>
<span class="navbar-text">
Navbar text
</span>
</nav>
<br>
<div class="container">
<h3>Navbar Text</h3>
<p>Use the .navbar-text class to vertical align any elements inside the navbar that are not links
(ensures proper padding).</p>
</div>
</body>
</html>
x)Fixed Navigation Bar: The navigation bar can also be fixed at the top or at the bottom of the
page.A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the
page scroll. The .fixed-top class makes the navigation bar fixed at the top:
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body style="height:1500px">
<ul class="navbar-nav">
<li class="nav-item">
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</ul>
</nav>
<p>A fixed navigation bar stays visible in a fixed position (top or bottom) independent of the
page scroll.</p>
</div>
</body>
</html>
Typography
i) <h1> - <h6>:
Bootstrap 4 styles HTML headings (<h1> to <h6>) with a bolder font-weight and an increased
font-size:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
</div>
</body>
</html>
Display headings are used to stand out more than normal headings (larger font-size and lighter
font-weight), and there are four classes to choose from: .display-1, .display-2, .display-
3, .display-4
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Display Headings</h1>
<p>Display headings are used to stand out more than normal headings (larger font-size and
lighter font-weight):</p>
</div>
</body>
</html>
iii) <small>:
In Bootstrap 4 the HTML <small> element is used to create a lighter, secondary text in any
heading:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<p>The small element is used to create a lighter, secondary text in any heading:</p>
</body>
</html>
iv) <mark>:
Bootstrap 4 will style the HTML <mark> element with a yellow background color and some
padding:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Highlight Text</h1>
</div>
</body>
</html>
v) <abbr>:
Bootstrap 4 will style the HTML <abbr> element with a dotted border bottom:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Abbreviations</h1>
</body>
</html>
vi) <blockquote>:
Add the .blockquote class to a <blockquote> when quoting blocks of content from another
source:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Blockquotes</h1>
<blockquote class="blockquote">
<p>For 50 years, WWF has been protecting the future of nature. The world's leading
conservation organization, WWF works in 100 countries and is supported by 1.2 million
members in the United States and close to 5 million globally.</p>
</blockquote>
</div>
</body>
</html>
vii) <dl>:
Bootstrap 4 will style the HTML <dl> element in the following way:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Description Lists</h1>
<dl>
<dt>Coffee</dt>
<dt>Milk</dt>
</dl>
</div>
</body>
</html>
viii) <code>:
Bootstrap 4 will style the HTML <code> element in the following way:
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Code Snippets</h1>
</div>
</body>
</html>
ix) <kbd>:
Bootstrap 4 will style the HTML <kbd> element in the following way:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Keyboard Inputs</h1>
<p>To indicate input that is typically entered via the keyboard, use the kbd element:</p>
</div>
</body>
</html>
X) <pre>:
Bootstrap 4 will style the HTML <pre> element in the following way:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<pre>
is displayed in a fixed-width
line breaks.
</pre>
</div>
</body>
</html>
All textual <input>, <textarea>, and <select> elements with class .form-control have a width of
100%.
Form Layouts:
i) Stacked Form:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Stacked form</h2>
<form action="/action_page.php">
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" placeholder="Enter email"
name="email">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
</div>
<label class="form-check-label">
</label>
</div>
</form>
</div>
</body>
</html>
ii)Inline Form:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Inline form</h2>
<p>Make the viewport larger than 576px wide to see that all of the form elements are inline and
left-aligned. On small screens, the form groups will stack horizontally.</p>
<label for="email">Email:</label>
<label for="pwd">Password:</label>
<div class="form-check">
<label class="form-check-label">
</label>
</div>
</form>
</div>
</body>
</html>
You can also use columns (.col) to control the width and alignment of form inputs without using
spacing utilities. Just remember to put them inside a .row container.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Form Grid</h2>
<p>Create two form elements that appear side by side with .row and .col:</p>
<form action="/action_page.php">
<div class="row">
<div class="col">
</div>
<div class="col">
</div>
</div>
</form>
</div>
</body>
</html>
iv) Form Validation: You can use different validation classes to provide valuable feedback to
users. Add either .was-validated or .needs-validation to the <form> element, depending on
whether you want to provide validation feedback before or after submitting the form. The input
fields will have a green (valid) or red (invalid) border to indicate what's missing in the form. You
can also add a .valid-feedback or .invalid-feedback message to tell the user explicitly what's
missing, or needs to be done before submitting the form.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Form Validation</h2>
<div class="form-group">
<label for="uname">Username:</label>
<div class="valid-feedback">Valid.</div>
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd" placeholder="Enter password"
name="pswd" required>
<div class="valid-feedback">Valid.</div>
</div>
<label class="form-check-label">
<div class="valid-feedback">Valid.</div>
</label>
</div>
</form>
</div>
</body>
</html>
Tables: A basic Bootstrap 4 table has a light padding and horizontal dividers.
i) Striped Rows:
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Striped Rows</h2>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The .table-bordered class adds borders on all sides of the table and cells:
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Bordered Table</h2>
<p>The .table-bordered class adds borders on all sides of the table and the cells:</p>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The .table-hover class adds a hover effect (grey background color) on table rows:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Hover Rows</h2>
<p>The .table-hover class enables a hover state (grey background on mouse over) on table
rows:</p>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
v) Black/Dark Table:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Black/Dark Table</h2>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Example: </thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The .table-hover class adds a hover effect (grey background color) on table rows:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<p>The .table-hover class adds a hover effect (grey background color) on table rows:</p>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Borderless Table</h2>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The .table-sm class makes the table smaller by cutting cell padding in half:
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Small Table</h2>
<p>The .table-sm class makes the table smaller by cutting cell padding in half:</p>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john@example.com</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
x) Responsive Tables:
The .table-responsive class adds a scrollbar to the table when needed (when it is too big
horizontally):
Example:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></
script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Responsive Table</h2>
<div class="table-responsive">
<thead>
<tr>
<th>#</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>City</th>
<th>Country</th>
<th>Sex</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Anna</td>
<td>Pitt</td>
<td>35</td>
<td>New York</td>
<td>USA</td>
<td>Female</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>