Web Dev
Web Dev
Internet?
"A global network
of networks."
(It's just a bunch of connected computers)
Hey
1101010101011010100
0111010101010101111
1101010101011010100
0111010101010101111
THE INTERNET IS THE INFRASTRUCTURE
THAT CARRIES THINGS LIKE:
EMAIL
THE WEB
FILE SHARING
ONLINE GAMING
STREAMING SERVICES
THE WEB
The World Wide Web is an
information system where
THE INTERNET documents and others
Global network of resources are available
interconnected computers over the Internet.
that communicate via
TCP/IP (don't worry about Documents are transferred
that for now). via HTTP.
Network of networks.
HTTP REQUESTS
Foundation of communication Request -> I would like this
on the World Wide Web information please
"Hyper Text Transfer Protocol" Response -> Ok, here you go!
WEB SERVER
A computer* that can satisfy requests on the Web.
* "server" is also used to refer to the software running on the computer
Hello Reddit,
please give me
/r/chickens OK!
CLIENT
The computer that accesses a server
Hello Reddit,
please give me
/r/chickens OK!
A SERVER YOUR BROWSER
SOMEWHERE
Opening Tag
<p>I am a paragraph</p>
Closing Tag
HTML SKELETON
We write our HTML in a standard "skeleton"
LIVING STANDARD
The HTML standard is a document that
describes how HTML should work.
ROLE OF BROWSERS
The standard describes the rules of HTML, but
browsers actually have to do the work and
implement HTML according to those rules.
What is HTML5?
HTML5?
HTML5 is the latest evolution of the standard
that defines HTML. It includes new elements
& features for browsers to implement,
INLINE ELEMENTS BLOCK ELEMENTS
EARLY USAGE
In the early days of the web, tables were
commonly used to create page layouts.
Today, you should only use the table element
when you are creating an actual data table.
TABLES
To create a table, you'll use 5-10 different
elements! It can be tricky to remember them
all, but don't panic!
HTML TABLES
"WTF why are there so
many elements just to
make a table??"
ELEMENTS <table>
<td>
<tr>
<th>
<thead>
<tbody>
<tfoot>
<colgroup>
<caption>
HTML Forms
CREATING
FORMS
The <form> element itself is a shell or
container that doesn't have any visual
impact.
We then fill the form with a collection of
inputs, checkboxes, buttons, etc.
Us
ern
ch
arl ame
Pa i19 :
12 sswo 99
1jj rd
Bir
12 thd
/1
2/
ate
d 91 :
hjh
j
<form>
19 :
76
The form element "represents a document
section containing interactive controls for
submitting information."
The action attribute specifies WHERE the
Send this data to: form data should be sent.
www,myserver.com The method attribute specifies which HTTP
method should be used (don't worry about
this for now)
<input>
The input element is used to create a
variety of different form controls.
We have 20+ possible types of inputs,
ranging from date pickers to checkboxes.
CSS
THERE'S A LOT!
CSS is very easy to get the hang of, but it can
be intimidating because of how many
properties we can manipulate.
CSS RULES
(almost) everything you do in CSS
follows this basic pattern:
selector {
property: value;
}
CSS RULES
Make all <h1> elements purple
h1 {
color: purple;
}
CSS RULES
Make all image elements
100 pixels wide & 200 pixels tall
img {
width: 100px;
height: 200px;
}
FANCIER!
Select every other text input
and give it a red border:
input[type="text"]:nth-of-type(2n){
border:2px solid red;
}
border border-blockborder-block-color border-block-end border-
block-end-color border-block-end-style border-block-end-width
border-block-start border-block-start-color border-block-start-
Styles
Write your styles in a .css file, and then
include the using a <link> in the head of your
html document. Recommended!
<link>
CSS
Colors
NAMED
COLORS
Hotpink Mediumorchid
Firebrick
Darkkhaki Gold
MediumAquamarine
Lightskyblue
Tomato
A typical computer can display
~16,000,000
different colors
RGB
Red, Green, Blue
Channels
Each channel
ranges from 0-255
rgb(255,0,0)
rgb(0,0,255)
rgb(173, 20, 219)
rgb(0,0,0)
Hex
Still red, green, and
blue channels
Each ranges from
0-255 BUT
represented with
hexadecimal
Decimal
0,1,2,3,4,
5,6,7,8,9
Hexadecimal
0,1,2,3,4,
5,6,7,8,9,
A,B,C,D,E,F
#ffff00
red green blue
#0f5679
red green blue
CSS Text
Properties
text-align
font-weight
text-decoration
line-height
letter-spacing
FONT
SIZE
Relative Absolute
- EM - PX
- REM - PT
- VH - CM
- VW - IN
- % - MM
- AND MORE!
FONT FAMILY
Absolute Units
PX - BY FAR THE MOST
COMMONLY USED ABSOLUTE UNIT
1px does not necessarily equal the width
of exactly one pixel!
ROOT EMS
Relative to the root html element's
font-size. Often easier to work with.
selector {
property: value;
}
CSS RULES
Everything you do in CSS
follows this basic pattern:
selector {
property: value;
}
CSS RULES
Make all <h1> elements purple
h1 {
color: purple;
}
FANCIER!
Select every other text input
and give it a red border:
input[type="text"]:nth-of-type(2n){
border:2px solid red;
}
UNIVERSAL SELECTOR
Select everything!
* {
color: black;
}
ELEMENT SELECTOR
Select all images
img {
width: 100px;
height: 200px;
}
SELECTOR LIST
Select all h1's and h2's
h1,h2 {
color: magenta;
}
CLASS SELECTOR
Select elements with class of 'complete'
.complete {
color: green;
}
ID SELECTOR
Select the element with id of 'logout'
#logout {
color: orange;
height: 200px;
}
DESCENDANT SELECTOR
Select all <a>'s that are nested inside an <li>
li a {
color: teal;
}
ADJACENT SELECTOR
Select only the paragraphs that are
immediately preceded by an <h1>
h1 + p {
color: red;
}
DIRECT CHILD
Select only the <li>'s that are direct
children of a <div> element
div > li {
color: white;
}
ATTRIBUTE SELECTOR
Select all input elements where the
type attribute is set to "text"
input[type="text"] {
width: 300px;
color: yellow;
}
PSEUDO CLASSES
keyword added to a selector that
specifies a special state of the
selected element(s)
:active
:checked
:first
:first-child
:hover
:not()
:nth-child()
:nth-of-type()
PSEUDO ELEMENTS
Keyword added to a selector that lets
you style a particular part of
selected element(s)
::after
::before
::first-letter
::first-line
::selection
What happens when
conflicting styles
target the same
elements?
THE CASCADE
The order your styles are declared in
and linked to matters!
Purple wins!
SPECIFICITY
Specificity is how the browser decides
which rules to apply when multiple
rules could apply to the same element.
THE CSS
BOX MODEL
The Box Model
BORDER
PADDING
CONTENT
BOX
MARGIN
Width & Height
WIDTH
HEIGHT
Border
Border Properties (the important ones)
Padding
vertical | horizontal
padding: 5px 10px;
CSS
UNITS
Relative Absolute
- EM - PX
- REM - PT
- VH - CM
- VW - IN
- % - MM
- AND MORE!
Absolute Units
PX - BY FAR THE MOST
COMMONLY USED ABSOLUTE UNIT
1px does not necessarily equal the width
of exactly one pixel!
ROOT EMS
Relative to the root html element's
font-size. Often easier to work with.
CSS FLEXBOX
You'll love it!
WHAT IS IT?
Flexbox is a one-dimensional layout
method for laying out items in rows
or columns
IT'S NEW(ISH)
The Basics Flexbox is a recent addition to CSS,
included to address common
layout frustations
WHY 'FLEX'?
Flexbox allows us to distribute
space dynamically across elements
of an unknown size, hence the
term "flex"
The Flex Model
MAIN AXIS
CROSS AXIS
FLEX DIRECTION
flex-direction: row;
FLEX DIRECTION
flex-direction: row-reverse;
FLEX DIRECTION
flex-direction: column;
flex-direction: column-reverse;
FLEX WRAP
flex-wrap: wrap;
JUSTIFY CONTENT
justify-content: flex-start;
JUSTIFY CONTENT
justify-content: flex-end;
JUSTIFY CONTENT
justify-content: center;
JUSTIFY CONTENT
justify-content: space-between;
JUSTIFY CONTENT
justify-content: space-around;
ALIGN ITEMS
align-items: flex-start;
ALIGN ITEMS
align-items: flex-end;
ALIGN ITEMS
align-items: center;
ALIGN ITEMS
align-items: stretch;
ALIGN CONTENT
align-content:space-between;
ALIGN CONTENT
align-content:flex-start;
ALIGN CONTENT
align-content:flex-end;
ALIGN CONTENT
align-content:center;
ALIGN SELF
align-self: flex-end;
FLEX-BASIS
Defines the initial size of an
element before additional space is
distributed.
FLEX-SHRINK
If items are larger than the
container, they shrink according to
flex-shrink.
THE PROBLEM
As mobile devices and tablets
became widely available,
developers had a problem...how do
we create websites that look good
on all screen sizes?
ONE APPROACH
RESPONSIVE Early on, it was common to create
separate stylesheets for different
devices, or even completely
DESIGN different websites for each size.
QUERIES
QUERIES
Bootstrap
"THE WORLD’S MOST POPULAR CSS FRAMEWORK"
Web Developer Bootcamp
JavaScript
Basics
VALUES & VARIABLES
PLEASE GIVE ME
GOOGLE.COM/SEARCH?Q=CHICKENS
HANG ON
Number
String
Boolean
Null
Undefined
// creates a comment
(the line is ignored)
NaN
NOT A NUMBER
// creates a comment
(the line is ignored)
WHAT DOES THIS
EVALUATE TO??
4 + 3 * 4 / 2
WHAT DOES THIS
EVALUATE TO??
4 + 3 * 4 /
(13 % 5) ** 22
WHAT DOES THIS
EVALUATE TO??
Variables
VARIABLES ARE LIKE
LABELS FOR VALUES
N
Up um We can store a value and give it
vo
72 te
s
a name so that we can:
Refer back to it later
Use that value to do...stuff
Or change it later one
BASIC SYNTAX
This does!
CONST
const works just like
let, except you CANNOT
change the value
NOT ALLOWED!
YOU'RE IN TROUBLE!!
I'M TELLING MOM!!!
WHY USE CONST?
So do single quotes
So do single quotes
Boolean
Logic
MAKING DECISIONS WITH JAVASCRIPT
COMPARISONS
SOME EXAMPLES
&& || !
AND
Both sides must be true, for the entire thing to be true
AND
Both sides must be true, for the entire thing to be true
OR
If one side is true, the entire thing is true
OR
If one side is true, the entire thing is true
NOT
!expression returns true if expression is false
Web Developer Bootcamp
JS Arrays
OUR FIRST DATA STRUCTURE
ARRAYS
Ordered collections of values.
List of comments on IG post
Collection of levels in a game
Songs in a playlist
Creating Arrays
PLEASE DROP BY AND SEE ME!
ARRAYS ARE INDEXED
Doc Dopey Bashful Grumpy Sneezy Sleepy Happy
0 1 2 3 4 5 6
Each element has a corresponding index
(counting starts at 0)
Arrays Are Indexed
Modifying Arrays
ARRAY METHODS
AND
ARRAYS
WHY DO PEOPLE USE CONST WITH ARRAYS??
THE VALUES CAN CHANGE
AS LONG AS THE REFERENCE REMAINS THE SAME
myEggs
THE VALUES CAN CHANGE
AS LONG AS THE REFERENCE REMAINS THE SAME
myEggs
THE VALUES CAN CHANGE
AS LONG AS THE REFERENCE REMAINS THE SAME
myEggs
THE VALUES CAN CHANGE
AS LONG AS THE REFERENCE REMAINS THE SAME
myEggs
NESTED ARRAYS
We can store arrays inside other arrays!
NESTED
ARRAYS
Web Developer Bootcamp
JS Objects
OUR SECOND DATA STRUCTURE!
OBJECTS
Objects are collections of
properties. age: 20
pursy:
donnybrook:
having a puckered
uprooad & disorder
appearance
fantod: remonstrate:
emotional outburst argue in protest
ALL TYPES WELCOME!
VALID KEYS
All keys are
converted to
strings *
* Except for Symbols, which we haven't covered yet
ACCESSING DATA
UPDATING
& ADDING
PROPERTIES
ARRAYS + OBJECTS
The Web Developer Bootcamp
Js Loops
REPEAT STUFF. REPEAT STUFF. REPEAT STUFF.
LOOPS
Loops allow us to repeat code
"Print 'hello' 10 times
Sum all numbers in an array
There are multiple types:
for loop
while loop
for...of loop
for...in loop
For
Loops
Buckle Up!
For Loop Syntax
for (
[initialExpression];
[condition];
[incrementExpression]
)
Our First For Loop
Start i at 50
Subtract 10 each
iteration
Keep going as
long as i >= 0
Infinite Loops
Looping Over Arrays
No Internet
Explorer Support
For...Of
JavaScript
Functions
THE LAST "BIG" TOPIC!
FUNCTIONS
Reusable procedures
Functions allow us to write
reusable, modular code
We define a "chunk" of code that
we can then execute at a later
point.
We use them ALL THE TIME
2 STEP PROCESS
DEFINE RUN
DEFINE
function funcName(){
//do something
}
DEFINE
RUN
funcName(); //run once
grumpus()
NO INPUTS
greet() "Hi!"
greet() "Hi!"
ARGUMENTS
We can also write functions that accept
inputs, called arguments
ARGUMENTS
greet('Tim') "Hi Tim!"
avg(3,2,5,6) 4
We've seen this before
No inputs
Arguments!
GREET TAKE 2
"33 and 33
are equal"
RETURN
Built-in methods return values
when we call them.
We can store those values:
NO RETURN!
Our functions print values out, but do
NOT return anything
FNIoR S T R E T U R N
w we can capture a return
!
value in a variable!
RETURN
The return statement ends function
execution AND specifies the value to be
returned by that function
FUNCTIONS
IN DETAIL
Important things
you should know
about functions
SCOPE
Variable "visibility"
The location where a variable
is defined dictates where we
have access to that variable
FUNCTION SCOPE
bird is scoped to
birdWatch function
BLOCK SCOPE
DIFFERENT
RESULT???
The value of this depends on
the invocation context of
the function it is used in.
GOALS
Use the new arrow function syntax
Understand and use these methods:
forEach
map
filter
find
reduce
some
every
FOREACH
Accepts a callback
function.
Calls the function
once per element
in the array.
MAP
Creates a new array with the
results of calling a callback on
every element in the array
MAP
ARROW
FUNCTIONS!
ARROW
FUNCTIONS
"syntactically compact alternative"
to a regular function expression
ARROW
FUNCTIONS
IMPLICIT RETURN
All these functions do the same thing:
FIND
returns the value of the first element in the array that
satisfies the provided testing function.
FILTER
Creates a new array with all elements that pass the test
implemented by the provided function.
EVERY
tests whether all elements in the array pass the
provided function. It returns a Boolean value.
SOME
Similar to every, but returns true if ANY of the
array elements pass the test function
REDUCE
Executes a reducer function on
each element of the array,
resulting in a single value.
SUMMING AN ARRAY
FINDING MAX VAL
INITIAL VALUE
TALLYING
DEFAULT
PARAMS
The Old Way
DEFAULT
PARAMS
The New Way
SPREAD
SPREAD
Spread syntax allows an iterable such as an
array to be expanded in places where zero or
more arguments (for function calls) or
elements (for array literals) are expected,
or an object expression to be expanded in
places where zero or more key-value pairs
(for object literals) are expected.
SPREAD
For Function Calls
Expands an iterable
(array, string, etc.)
into a list of arguments
SPREAD
In Array Literals
Create a new array using
an existing array. Spreads
the elements from one
array into a new array.
SPREAD
In Object Literals
Copies properties
from one object into
another object literal.
REST
It looks like spread,
but it's not!
THE ARGUMENTS OBJECT
Available inside every
function.
It's an array-like object
Has a length property
Does not have array
methods like push/pop
Contains all the arguments
passed to the function
Not available inside of
arrow functions!
REST
PARAMS
Collects all remaining
arguments into an
actual array
DESTRUCTURING
A short, clean syntax to 'unpack':
Values from arrays
Properties from objects
Into distinct variables.
A R R A Y
Destructuring
OD eBs t rJu cEt u rC
ing
T
PD eAs t rR A M
ucturing
THE
DOM
DOCUMENT
OBJECT
M ODEL
WHAT IS IT?
The DOM is a JavaScript
representation of a webpage.
It's your JS "window" into the
contents of a webpage
It's just a bunch of objects that
you can interact with via JS.
HTML+CSS Go In... JS Objects Come Out
I'm an
object!
DOCU
MENT
BODY
Me too!
H1 UL
LI LI
DOCUMENT
The document object is our entry
BODY
classList innerText
getAttribute() textContent
setAttribute() innerHTML
appendChild() value
append() parentElement
prepend() children
removeChild() nextSibling
remove() previousSibling
createElement style
EVENTS
Responding to
user inputs
and actions!
A SMALL TASTE
clicks mouse wheel
drags double click
drops
copying
hovers
pasting
scrolls
form audio start
submission screen resize
key presses printing
focus/blur
addEventListener
Specify the event type and a callback to run
CALL STACK
The mechanism the JS interpreter uses to
keep track of its place in a script that calls
multiple functions.
Let's see...
where was I?
LAST
THING
IN...
FIRST
THING
OUT...
HOW IT WORKS
When a script calls a function, the interpreter adds it to the call
stack and then starts carrying out the function.
Any functions that are called by that function are added to the
call stack further up, and run where their calls are reached.
When the current function is finished, the interpreter takes it off
the stack and resumes execution where it left off in the last code
listing.
isRightTriangle(3,4,5)
square(3)+square(4)
=== square(5)
square(3)
multiply(3,3)
isRightTriangle(3,4,5)
square(3)+square(4)
=== square(5)
multiply(3,3)
9
square(3)
multiply(3,3)
isRightTriangle(3,4,5)
square(3)+square(4)
=== square(5)
square(3)
9
isRightTriangle(3,4,5)
square(3)+square(4)
=== square(5)
isRightTriangle(3,4,5)
9+square(4) === square(5)
square(4)
multiply(4,4)
isRightTriangle(3,4,5)
9+square(4) === square(5)
multiply(4,4)
16
square(4)
multiply(4,4)
isRightTriangle(3,4,5)
9+square(4) === square(5)
square(4)
16
isRightTriangle(3,4,5)
9+square(4) === square(5)
isRightTriangle(3,4,5)
9+16 === square(5)
square(5)
multiply(5,5)
isRightTriangle(3,4,5)
9+16 === square(5)
multiply(5,5)
25
square(5)
multiply(5,5)
isRightTriangle(3,4,5)
9+16 === square(5)
square(5)
25
isRightTriangle(3,4,5)
9+16 === square(5)
isRightTriangle(3,4,5)
9+16 === 25
isRightTriangle(3,4,5)
true
true
JS IS
SINGLE
THREADED
WHAT DOES
THAT MEAN?
At any given point in time, that
single JS thread is running at
most one line of JS code.
Can you please send
me all movies that
match the query "Bat"
Can you please send
me all movies that
match the query "Bat"
S
BATE L
E
MOT
AN
BATM
THIS TAKES TIME
IS OUR APP
GOING TO
GRIND TO
A HALT?
What happens when
something takes a
long time?
Fortunately...
We have a workaround
CALLBACKS???!
THE
BROWSER
DOES THE
WORK!
OK BUT HOW?
Browsers come with Web APIs that
are able to handle certain tasks in
the background (like making
requests or setTimeout)
OKEEEDOKEEE
> I print first!
> I print second!
> I print first!
Will do!
Thanks, browser!
> I print second!
Time's Up!!!
Make sure you run
that callback now!!
> I print first!
"Hyper Text Transfer Protocol" Response -> Ok, here you go!
PLEASE GIVE ME
GOOGLE.COM/SEARCH?Q=CHICKENS
PLEASE GIVE ME
API.CRYPTONATOR.COM/API/TICKER/BTC-USD
price is 11227.76
AJAX
ASYNCHRONOUS
JAVASCRIPT
AND
XML
AJAJ
ASYNCHRONOUS
JAVASCRIPT
AND
JSON
JSON
Java
Script
Object
Notation
POST
MAN
XMLHttpRequest
The "original" way of sending
requests via JS.
Does not support promises,
so...lots of callbacks!
WTF is going on with the weird
capitalization?
Clunky syntax that I find
difficult to remember!
XMLHttpRequest
Fetch API
The newer way of making
requests via JS
Supports promises!
Not supported in Internet
Explorer :(
FETCH
AXIOS
A LIBRARY FOR
MAKING HTTP
REQUESTS
TERMINAL
SETUP
Mac
Open up the built-in terminal app
PC
Enable Windows Subsystem
(follow the linked tutorial)
Speed!
Develop Faster
The terminal takes some getting
used to, but it can be MUCH faster
than using a GUI.
Access
With Great Power...
The terminal provides a "mainline"
into the heart of our computer,
giving us access to areas we
normally don't interact with.
Tools!
Many of the tools we need are
installed and used via the
command line. We don't have
much of a choice!
Confusing
Terminology
Terminal?
Shell?
Command Line?
Console?
Bash?
Terminal
A TEXT-BASED INTERFACE TO YOUR COMPUTER.
ORIGINALLY A PHYSICAL OBJECT, BUT NOW WE
USE SOFTWARE TERMINALS
Shell
THE PROGRAM RUNNING ON THE TERMINAL.
A QUICK ANALOGY!
TERMINAL
SHELL
List
Use ls to list the contents of your current directory
P
W
D
Print Working Directory
Prints the path to the working directory
(where you currently are)
C
D
Change Directory
Use cd to change and move between folders
C
D
cd ..
Use cd .. to "back up" one directory
t
o
u
c
h
Touch
Use touch to create a file (or multiple)
Yes, the name is weird...
m
k
d
i
r
rm
rm will delete a file or files
It permanently removes them!
r
m
rm -rf
use rm -rf to delete a directory
(r = recursive, f = force)
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
WEB DEVELOPER BOOTCAMP
PMACTOOB REPOLEVED BEW /SJ EDON OT NOITCUDORTNI
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SJ EDON OT NOITCUDORTNI
WHAT IS NODE?
"A JAVASCRIPT RUNTIME"
WHAT DO PEOPLE
BUILD WITH IT?
Web Servers
Command Line Tools
Native Apps (VSCode is a Node app!)
Video Games
Drone Software
A Whole Lot More!
NODE JS VS
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SJ EDON OT NOITCUDORTNI
CLIENT-SIDE JS
WEB DEVELOPER
BOOTCAMP
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SJ EDON OT NOITCUDORTNI
NPM
NODE PACKAGE MANAGER
WHAT IS EXPRESS?
OUR FIRST FRAMEWORK!
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
FRAMEWORKS
LIBRARY FRAMEWORK
When you use a library, you are in charge! With frameworks, that control is inverted.
You control the flow of the application The framework is in charge, and you are
code, and you decide when to use the merely a participant! The framework tells
library. you where to plug in the code.
WEB DEVELOPER
BOOTCAMP
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
TEMPLATING
WEB DEVELOPER
BOOTCAMP
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
GET POST
WEB DEVELOPER
BOOTCAMP
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
REST WEB DEVELOPER BOOTCAMP
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
WTF IS REST?
REPRESENTATIONAL
STATE TRANSFER
WTF IS REST?
REPRESENTATIONAL
STATE TRANSFER
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
THIS IS JUST ONE APPROACH TO RESTFUL ROUTING:
PMACTOOB REPOLEVED BEW /SSERPXE OT NOITCUDORTNI
WHAT IS MONGO?
OUR FIRST DATABASE!
DATABASE?
INSTEAD OF JUST SAVING TO A
FILE?
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
PMACTOOB REPOLEVED BEW /OGNOM OT NOITCUDORTNI
NOSQL
WEB DEVELOPER
BOOTCAMP
POPULAR
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
DATABASES
PMACTOOB REPOLEVED BEW /OGNOM OT NOITCUDORTNI
WEB DEVELOPER
BOOTCAMP
EREH TUP OT TAHW WONK T'NOD I ?SIHT GNIDAER UOY ERA YHW
WHY ARE WE
PMACTOOB REPOLEVED BEW /OGNOM OT NOITCUDORTNI
LEARNING MONGO?
Express middleware are functions that run during the request/response lifecycle.
MIDDLEWARE
Middleware are just functions
REQUEST RESPONSE
Each middleware has access to the request and response objects
Middleware can end the HTTP request by sending back a
response with methods like res.send()
OR middleware can be chained together, one after another by
calling next()
ERRORS!
REQUEST RESPONSE
WEB DEVELOPER
BOOTCAMP
!SEIKOOC RETTUB NWORB YLLAICEPSE ,SEIKOOC TAE OT EVOL I
COOKIES
WHAT ARE THEY?
!!!SEIKOOC EVOL I
!!!SEIKOOC EVOL I
Cookies are little bits of information that are stored in a
user's browser when browsing a particular website.
!!!SEIKOOC EVOL I
It's not very practical (or secure) to store a lot of data
client-side using cookies. This is where sessions come in!
WEB DEVELOPER
BOOTCAMP
.HTUA ROF EMIT S'TI .HTAERB PEED
AUTHENTICATION
.HTUA ROF EMIT S'TI
.HTAERB PEED
We typically authenticate with a username/password
combo, but we can also use security questions, facial
recognition, etc.
AUTHORIZATION
.HTUA ROF EMIT S'TI
.HTAERB PEED
Generally, we authorize after a user has been authenticated.
"Now that we know who you are, here is what you are
allowed to do and NOT allowed to do"
.HTUA ROF EMIT S'TI .HTAERB PEED
# 1
NEVER STORE PASSWORDS
R U L E
.HTUA ROF EMIT S'TI .HTAERB PEED
R U L E # 1
NEVER STORE PASSWORDS
.HTUA ROF EMIT S'TI
.HTAERB PEED
},
{
username: 'geckoGuy',
password: 'lizard987'
}
SERVER
CLIENT DATABASE
.HTUA ROF EMIT S'TI
.HTAERB PEED
{
username: 'geckoGuy',
password: 'lizard987'
}
SERVER
CLIENT DATABASE
.HTUA ROF EMIT S'TI
.HTAERB PEED
{
username: 'geckoGuy',
password: 'lizard987'
}
HASHING
.HTUA ROF EMIT S'TI
.HTAERB PEED
through a hashing function first and
then store the result in the database.
HASHING
FUNCTIONS
Hashing functions are functions that map input data of
some arbitrary size to fixed-size output values.
D70FF0AB9A23EC5DBA9075
'I LOVE CHICKENS' B0E4DEDE8C2972BA933D6D
5ADF3A42ABB6E0D7A2DA
07123E1F482356C415F6844
'LOL' 07A3B8723E10B2CBBC0B8F
CD6282C49D37C9C1ABC
SERVER DATABASE
CLIENT {
username: 'kittycatluvr',
LOG ME IN WITH:
password:'d70ff0ab9a23ec5dba9075b0e4de
Username: 'geckoGuy'
de8c2972ba933d6d5adf3a42abb6e0d7a2da'
Password: 'lizard987' },
{
username: 'geckoGuy',
password:'07123e1f482356c415f684407a3b87
23e10b2cbbc0b8fcd6282c49d37c9c1abc'
}
SERVER DATABASE
CLIENT {
username: 'kittycatluvr',
LOG ME IN WITH:
password:'d70ff0ab9a23ec5dba9075b0e4de
Username: 'geckoGuy'
de8c2972ba933d6d5adf3a42abb6e0d7a2da'
Password: 'lizard987' },
{
username: 'geckoGuy',
password:'07123e1f482356c415f684407a3b87
23e10b2cbbc0b8fcd6282c49d37c9c1abc'
}
'LIZARD987'
SERVER DATABASE
CLIENT {
username: 'kittycatluvr',
LOG ME IN WITH:
password:'d70ff0ab9a23ec5dba9075b0e4de
Username: 'geckoGuy'
de8c2972ba933d6d5adf3a42abb6e0d7a2da'
Password: 'lizard987' },
{
username: 'geckoGuy',
password:'07123e1f482356c415f684407a3b87
23e10b2cbbc0b8fcd6282c49d37c9c1abc'
}
07123E1F482356C415F6844
'LIZARD987' 07A3B8723E10B2CBBC0B8F
CD6282C49D37C9C1ABC
SERVER DATABASE
CLIENT {
username: 'kittycatluvr',
LOG ME IN WITH:
password:'d70ff0ab9a23ec5dba9075b0e4de
Username: 'geckoGuy'
de8c2972ba933d6d5adf3a42abb6e0d7a2da'
Password: 'lizard987' },
{
username: 'geckoGuy',
password:'07123e1f482356c415f684407a3b87
23e10b2cbbc0b8fcd6282c49d37c9c1abc'
}
IT'S A MATCH!
07123E1F482356C415F6844
'LIZARD987' 07A3B8723E10B2CBBC0B8F
CD6282C49D37C9C1ABC
CRYPTOGRAPHIC
.HTUA ROF EMIT S'TI
.HTAERB PEED
2. Small change in input yields large change in the output
3. Deterministic - same input yields same output
4. Unlikely to find 2 outputs with same value
5. Password Hash Functions are deliberately SLOW
.HTUA ROF EMIT S'TI .HTAERB PEED
AN EXTRA SAFEGUARD
S A L T S
.HTUA ROF EMIT S'TI .HTAERB PEED
PASSWORD SALTS
.HTUA ROF EMIT S'TI
.HTAERB PEED
It helps ensure unique hashes and
mitigate common attacks
B C R Y P T
OUR HASH FUNCTION!
SERVER
CLIENT
DATA STORE
I have a cookie for you! {
id: 4,
Session ID is 4
shoppingCart: [
{item: 'carrot', qty:2},
{item: 'celery', qty:5},
{item: 'taser;', qty:99},
]
}
DATA STORE
{
id: 3,
shoppingCart: [
{item: 'lime', qty:1},
{item: 'la croix', qty:99}, SERVER
{item: 'lemon', qty:2},
]
}, CLIENT
{
id: 4,
shoppingCart: [
{item: 'carrot', qty:2}, Your session ID is 4
{item: 'celery', qty:5},
{item: 'taser;', qty:99},
]
},
{
id: 5,
shoppingCart: [
{item: 'apple', qty:2},
{item: 'onion', qty:5},
{item: 'pear;', qty:9},
]
}
HTML
CheatSheet
In this Cheatsheet, we will cover the basics of HTML tags,
elements, and attributes. We will provide examples to help you
understand how these elements work and how to use them in your
own web development projects. Whether you are a beginner or an
experienced developer, this PDF can serve as a useful reference
guide.
HTML
HTML (Hypertext Markup Language) is a standard markup
language used to create web pages. It is used to structure and
format content on the web, including text, images, and other
multimedia elements. HTML consists of a series of elements that
are represented by tags, which are used to define the structure
and content of a webpage.
HTML is an essential part of the web development process and is
used to create the structure and content of websites. It is a
fundamental skill for web developers and is used to create the
majority of websites on the internet.
HTML COMPONENTS
<!DOCTYPE html>
<html lang="en">
<head>
<title> Code Help HTML Cheat Sheet </title>
</head>
<body> .... </body>
</html>
3|Page
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Code Help HTML Cheat Sheet</title>
<style>
*{
font-size: 40px;
}
</style>
<script>
alert ('message');
</script>
</head>
4|Page
You use the <p> tag to create a paragraph.
We also have the <span> tag. This is similar to <div> but you use
it as an inline container.
5|Page
There's the <br/> tag, which we use to insert line breaks in the
document. This tag does not require a closing tag.
IMAGES IN HTML
In HTML, we use the <img/> tag to insert images into the
document.
6|Page
• border specifies the thickness of the borders around the
image. If no border is added, it is set to 0.
LINKS IN HTML
The <a> tag, also referred to as the anchor tag, is used to
establish hyperlinks that link to other pages (external web pages
included) or to a particular section within the same page.
8|Page
• The href attribute specifies the URL that the link will take the
user to when clicked.
• The download attribute specifies that the target or resource
clicked is a downloadable file.
• The target attribute specifies where the linked document or
resource should be opened. This could be in the same
window or a new window.
LISTS IN HTML
• The <ol> tag defines an ordered list.
• The <ul> tag defines an unordered list.
• The <li> tag is used to create items in the list.
9|Page
FORMS IN HTML
The <form> element is used to create a form in HTML. Forms are
used to gather user input.
10 | P a g e
Other input elements that can be used in forms include:
11 | P a g e
TABLES IN HTML
The <table> tag defines a HTML table.
<table>
<thead>
<tr>
<th> Name </th>
<th> CGPA </th>
</tr>
</thead>
<tbody>
<tr>
<td> Koushik Sadhu </td>
<td> 9.66 </td>
</tr>
<tr>
<td> Pranay Gupta </td>
<td> 9.72 </td>
</tr>
</tbody>
<tfoot>
<tr>
<td> Nidhi Gupta </td>
<td> 10 </td>
</tr>
</tfoot>
</table>
Tags introduced in HTML5
12 | P a g e
TAGS IN HTML
The following tags were introduced in HTML5:
13 | P a g e
<header>
<h1> Welcome to CodeHelp! </h1>
</header>
<nav>
<ul>
<li><a href="#">About Us</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<article>
<h1> About CodeHelp </h1>
<p> This is all about CodeHelp. </p>
<aside>
<p> Book your seat now. </p>
</aside>
</article>
14 | P a g e
CHARACTER AND SYMBOLS
In HTML documents, some symbols may not be directly available
on the keyboard. However, there are several ways to include
these symbols in a document. These include using the symbol's
entity name, decimal value, or hexadecimal value.
<!DOCTYPE html>
<html lang="en">
<head>
<title> Code Help HTML Cheat Sheet </title>
</head>
<body>
<p> Copyright Symbol: © </p>
<p> Dollar Symbol: $ </p>
<p> Ampersand Symbol: & </p>
<p> Greater than Symbol: > </p>
<p> Less than Symbol: < </p>
</body>
</html>
15 | P a g e
CSS CheatSheet
In this Cheatsheet, we will cover the basics of CSS properties. We
will provide examples to help you understand how these properties
work and how to use them in your own web development projects.
Whether you are a beginner or an experienced developer, this PDF
can serve as a useful reference guide.
CSS
CSS (Cascading Style Sheets) is a stylesheet language used for
describing the look and formatting of a document written in HTML
(Hypertext Markup Language).
CSS is used to define the layout, font, color, and other visual
aspects of a webpage, and it helps to separate the content of a
webpage from its presentation. CSS allows you to apply styles to
multiple HTML elements at once, and it makes it easy to maintain
and update the styling of a webpage.
You can use CSS to specify styles for different devices, such as
desktop computers, tablets, and mobile phones, which makes it
easier to create responsive designs that look good on any device.
To use CSS, you can include a stylesheet in your HTML document
using a <link> element, or you can use inline styles in your HTML
elements using the style attribute.
You can also use CSS to style elements in other documents, such
as XML or SVG, and you can use CSS in combination with other
technologies, such as JavaScript, to create dynamic and
interactive webpages.
2|Page
FONT PROPERTIES IN CSS
The font has many properties that you can change, such as its
face, weight, and style, which allow you to alter the appearance of
your text.
• Font-Family: Specifies the font family of the text.
p{
font-family: Times, serif, Arial, Helvetica, sans-serif;
font: 15px Helvetica, sans-serif, Arial;
font-size: 15px;
font-weight: bold;
font-style: italic;
font-variant: small-caps;
}
3|Page
TEXT PROPERTIES IN CSS
CSS has a lot of properties for formatting text.
p{
text-align: center;
text-decoration: underline;
letter-spacing: 5px;
text-transform: uppercase;
word-spacing: 8px;
text-indent: 40px;
line-height: 40%;
text-shadow: 4px 4px #ff0000;
}
4|Page
BACKGROUND PROPERTIES IN CSS
5|Page
body {
background-image: url(‘codeHelp.png’);
background-size: auto;
background -position: center;
background -repeat: no-repeat;
background -color: #ffffff;
background -attachment: fixed;
background -origin: content-box;
background : url(‘codeHelp.png’);
}
The border properties enable you to alter the style, radius, color,
and other characteristics of the buttons or other elements within
the document.
6|Page
• Border: A shorthand property for border-width, border-style
and border-color.
div {
border-width: 4px;
border-style: solid;
border-radius: 4px;
border-color: #000000;
border: 20px dotted coral;
border-spacing: 20px;
}
7|Page
• Height: It sets the height of an element.
p{
padding: 10px 20px 10px 20px;
visibility: hidden;
display: inline-block;
height: auto;
width: 100px;
float: right;
clear: left;
margin: 20px 10px 20px 10px;
overflow: scroll;
}
8|Page
COLORS PROPERTIES IN CSS
The color property can be used to add color to various objects.
{
color: rgb(0, 0, 0);
outline-color: #000000;
caret-color: coral;
opacity: 0.8;
}
9|Page
LAYOUT PROPERTIES IN CSS
It defines the appearance of the content within a template.
10 | P a g e
{
box-align: start;
box-direction: normal;
box-flex: normal;
box-orient: inline;
box-sizing: margin-box;
box-pack: justify;
min-width: 200px;
max-width: 400px;
min-height: 100px;
max-height: 1000px;
}
{
border-spacing: 4px;
border-collapse: separate;
empty-cells: show;
caption-side: bottom;
table-layout: auto;
}
{
column-gap: 4px;
column-rule-width: medium;
column-rule-color: #000000;
column-rule-style: dashed;
column-count: 20;
column-span: all;
column-width: 4px;
}
13 | P a g e
{
list-style-image: url(‘codeHelp.png’);
list-style-position: 10px;
list-style-type: square;
marker-offset: auto;
}
14 | P a g e
• Animation-Play-State: It specifies whether the animation is
running or paused.
{
animation-name: anime;
animation-delay: 4ms;
animation-duration: 10s;
animation-timing-function: ease;
animation-iteration-count: 5;
animation-fill-mode: both;
animation-play-state: running;
animation-direction: normal;
}
{
transition-property: none;
transition-delay: 4ms;
transition-duration: 10s;
transition-timing-function: ease-in-out;
}
CSS FLEXBOX
Flexbox is a CSS layout system that makes it easy to align and
distribute items within a container using rows and columns. It
allows items to "flex" and adjust their size to fit the available
space, making responsive design simpler to implement. Flexbox
makes formatting HTML elements more straightforward and
efficient.
PARENT PROPERTIES:
16 | P a g e
• Justify-Content: It specifies the alignment between the
items inside a flexible container when the items do not use all
available space.
{
display: flex;
flex-direction: row | row-reverse | column | column-reverse;
flex-wrap: nowrap | wrap | wrap-reverse;
flex-flow: column wrap;
justify-content: flex-start | flex-end | center | space-between | space-
around | space-evenly | start | end | left | right ... + safe | unsafe;
align-items: stretch | flex-start | flex-end | center | baseline | first
baseline | last baseline | start | end | self-start | self-end + ... safe |
unsafe;
align-content: flex-start | flex-end | center | space-between | space-
around | space-evenly | stretch | start | end | baseline | first baseline |
last baseline + ... safe | unsafe;
}
17 | P a g e
CHILD PROPERTIES:
{
order: 2; /* By default it is 0 */
flex-grow: 5; /* By default it is 0 */
flex-shrink: 4; /* By default it is 1 */
flex-basis: | auto; /* By default it is auto */
align-self: auto | flex-start | flex-end | center | baseline | stretch;
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ];
}
18 | P a g e
CSS GRID
The Grid layout is a 2-dimensional system in CSS that allows for
the creation of complex and responsive web design layouts with
consistent results across different browsers. It makes it easier to
build these types of layouts.
PARENT PROPERTIES:
19 | P a g e
• Grid-Gap: It is a shorthand property for the grid-row-gap
and grid-column-gap properties.
20 | P a g e
{
display: grid | inline-grid;
grid-template-columns: 10px 10px 10px;
grid-template-rows: 5px auto 10px;
grid-template: none | <grid-template-rows> / <grid-template-
columns>;
column-gap: <line-size>;
row-gap: <line-size>;
grid-column-gap: <line-size>;
grid-row-gap: <line-size>;
gap: <grid-row-gap> <grid-column-gap>;
grid-gap: <grid-row-gap> <grid-column-gap>;
align-items: start | end | center | stretch;
justify-content: start | end | center | stretch | space-around | space-
between | space-evenly;
align-content: start | end | center | stretch | space-around | space-
between | space-evenly;
grid-auto-columns: <track-size>;
grid-auto-rows: <track-size>;
grid-auto-flow: row | column | row dense | column dense;
}
21 | P a g e
CHILD PROPERTIES:
22 | P a g e
{
grid-column-start: <number> | <name> | span <number> | span <name>
| auto;
grid-column-end: <number> | <name> | span <number> | span <name> |
auto;
grid-row-start: <number> | <name> | span <number> | span <name> |
auto;
grid-row-end: <number> | <name> | span <number> | span <name> |
auto;
grid-column: <start-line> / <end-line> | <start-line> / span <value>;
grid-row: <start-line> / <end-line> | <start-line> / span <value>;
grid-area: <name> | <row-start> / <column-start> / <row-end> /
<column-end>;
align-self: start | end | center | stretch;
}
23 | P a g e
Bootstrap
Cheat Sheet
If you plan to pick up some coding skills,
Bootstrap 4 is a solid choice!
Why? .active
It is the gold
standard of front-end Bootstrap has built-in It’s open-source and Plus, it’s super versatile
development: classes, meaning you has major community and can be used to
don’t have to code support. create any type of
most elements from website in no time.
scratch.
What is Bootstrap?
Bootstrap 4 is a popular
framework for front-end website
development.
Bootstrap.js
A JavaScript/JQuery library that powers up certain components of Bootstrap such as animation, scrolling, and
interactivity.
<script src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js”
integrity=”sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo”
crossorigin=”anonymous”></script>
<script src=”https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js”
integrity=”sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6”
crossorigin=”anonymous”></script>
Glyphicons
Glyphs are elemental symbols with typography, such as the English Pound symbol (£). Bootstrap has a huge list of
embedded glyph icons that are available for free.
less/ - a preprocessor style sheet for CSS that eliminate repetitive coding tasks
sass/ - a newer version of the preprocessor that is more popular
js/ - simply refers to the source code JavaScript, which allows Bootstrap components to work
fonts/ - these are icon fonts that come with the download
dist/ - a folder that contains precompiled files for drop-in use in website development
Note: Bootstrap also requires jQuery installation for Bootstrap’s JavaScript plugins. jQuery is a feature-rich component of
the JavaScript library, and it whittles down lots of JavaScript code and wraps them into actions you can accomplish with
a single line.
<script src=”https://code.jquery.com/jquery.js”></script>
To install plug-ins:
<script src=”js/bootstrap.min.js”></script>
XS SM MD LG
PHONE TABLET LAPTOP DESKTOP
Min:
@media (min-width: @screen-sm-min) // >= 768px (small tablet)
@media (min-width: @screen-md-min) // >= 992px (medium laptop)
@media (min-width: @screen-lg-min) // >= 1200px (large desktop)
Max:
@media (max-width: @screen-xs-max) { // < 768px (xsmall phone)
@media (max-width: @screen-sm-max) { // < 992px (small tablet)
@media (max-width: @screen-md-max) { // < 1200px (medium laptop)
.alert-secondary
Add a secondary alert (less important message) in light gray color.
<div class=”alert alert-secondary” role=”alert”>I’m a secondary alert</div>
.alert-success
This will alert a user that their action has been successful
<div class=”alert alert-success” role=”alert”>Success alert!</div>
.alert-warning
This will send a message of an upcoming action.
<div class=”alert alert-warning” role=”alert”>Warning! Warning!</div>
.alert-danger
A danger alert is similar to a warning alert, but for more negative actions (e.g., getting locked out after too many password
fails)
<div class=”alert alert-danger” role=”alert”> You are in grave danger, my friend!</
div>
.alert-link
So you want to add another message and a link to that message in the original alert? You can embed that message and
in the same color.
<div class=”alert alert-success”> <strong>Success!</strong> You should <a href=”#”
class=”alert-link”>read this cool message</a>. </div>
.alert-dismissible
Provides an option to close the alert after reading it.
<div class=”alert alert-success alert-dismissible”> <a href=”#” class=”close” data-
dismiss=”alert” aria-label=”close”>×</a><strong>Success! You did well</strong>
</div>
.alert-heading
Add a quick header to your alert. (e.g., “shipping address” or “billing address”). It could relate to an entire page or just a
piece of content within that page.
<div class=”alert alert-info”>
<h4 class=”alert-heading”><i class=”fa fa-info”></i>
Badge
Use badges to display extra information next to a category, button, or other element. You can create and style them
with other context elements (e.g., .badge-warning). Also, badges will scale to match the size of the parent element (e.g.
headings). Lastly, you can use badges as a part of buttons or links to provide counters.
Example:Headings
Suppose you have a number of headings and you are adding a badge. That badge will adjust in size to match the
heading.
<h1>Example heading <span class=”badge badge-secondary”>New</span></h1>
<h2>Example heading <span class=”badge badge-secondary”>New</span></h2>
.badge-pill
Use this command to modify the shape of your badges, making them more rounded.
<span class=”badge badge-pill badge-light”>Light</span>
.badge-primary + .badge-secondary
You may want to add a badge to primary (more important) and secondary (less important) messages.
<span class=”badge badge-primary”>Primary</span>
<span class=”badge badge-badge-secondary”>Secondary</span>
.badge-transparent
Suppose you want to make a button transparent to make it stand out from the rest. With Bootcamp 4, you do not have to
use in-line styling. Instead, use the following command:
<button class=”btn bg-transparent”></button>
.Breadcrumbs
Breadcrumbs are navigational components that will help users move from page to page without getting lost and give
them the way to pedal back to a previous page.
<nav aria-label=”breadcrumb”>
<ol class=”breadcrumb”>
<li class=”breadcrumb-item active” aria-current=”page”>Home</li>
</ol>
</nav>
<nav aria-label=”breadcrumb”>
<ol class=”breadcrumb”>
<li class=”breadcrumb-item”><a href=”#”>Home</a></li>
<li class=”breadcrumb-item active” aria-current=”page”>Library</li>
</ol>
</nav>
<nav aria-label=”breadcrumb”>
<ol class=”breadcrumb”>
<li class=”breadcrumb-item”><a href=”#”>Home</a></li>
<li class=”breadcrumb-item active” aria-current=”page”>Library</li>
<li class=”breadcrumb-item active” aria-current=”page”>Data</li>
</ol>
</nav>
.buttons
As the name hints, .button command lets you create and style … a button.
.button-primary + .button-secondary
A primary button is commonly used for a user action; a secondary button may then be used to close out.
<button type=”button” class=”btn btn-primary”>Primary</button>
<button type=”button” class=”btn btn-secondary”>Secondary</button>
.btn-outline
Choose a button outline following these snippet samples:
<button type=”button” class=”btn btn-outline-primary”>Primary</button>
.btn-lg + .btn-sm
Change the size of your buttons.
<button type=”button” class=”btn btn-primary btn-lg”>I’m the large button</button>
<button type=”button” class=”btn btn-primary btn-sm”>I’m a small button</button>
.btn-block
Group your buttons into a block. All grouped buttons will span the full width of a parent.
<button type=”button” class=”btn btn-primary btn-lg btn-block”>Block level button</
button>
.active
By default, all buttons will be displayed as pressed - with a dark border, darker background and inset shadow - when
active.
You don’t need to add a class to <button>s as they use a pseudo-class.
But, if for some reason, you need to force that same active look, use the following code snippet:
<a href=”#!” class=”btn btn-primary btn-lg active” role=”button” aria-
pressed=”true”>Primary link</a>
Note: You can also add the disabled Boolean attribute to any button to make it look inactive.
<button type=”button” class=”btn btn-lg btn-primary” disabled>Disabled button</
button>
Button Group
Use this element to make a group of similarly-sized buttons without coding each separately.
.btn-group
<div class=”btn-group” role=”group” aria-label=”Basic example”>
<button type=”button” class=”btn btn-secondary”>Left</button>
<button type=”button” class=”btn btn-secondary”>Middle</button>
<button type=”button” class=”btn btn-secondary”>Right</button>
</div>
.btn-group-vertical
Style a vertical group of buttons:
<div class=”btn-group-vertical” role=”group” aria-label=”Basic example”>
<button type=”button” class=”btn btn-secondary”>Left</button>
<button type=”button” class=”btn btn-secondary”>Middle</button>
<button type=”button” class=”btn btn-secondary”>Right</button>
</div>
.btn-group (Nested)
You can also create nested buttons with drop down menus.
<div class=”btn-group” role=”group” aria-label=”Button group with nested dropdown”>
<button type=”button” class=”btn btn-secondary”>1</button>
<button type=”button” class=”btn btn-secondary”>2</button>
.btn-toolbar
Arrange button groups into a toolbar to make more complex components. You can apply different utility classes for
additional styling.
<div class=”btn-toolbar” role=”toolbar” aria-label=”Toolbar with button groups”>
<div class=”btn-group” role=”group” aria-label=”First group”>
<button type=”button” class=”btn btn-secondary”>1</button>
<button type=”button” class=”btn btn-secondary”>2</button>
<button type=”button” class=”btn btn-secondary”>3</button>
</div>
<div class=”btn-group” role=”group” aria-label=”Second group”>
<button type=”button” class=”btn btn-secondary”>5</button>
<button type=”button” class=”btn btn-secondary”>6</button>
</div>
<div class=”btn-group” role=”group” aria-label=”Third group”>
<button type=”button” class=”btn btn-secondary”>8</button>
</div>
</div>
.btn-group-toggle
Install Bootstrap Toggle plugin to modify checkboxes into toggles. You can then add data-toggle=”buttons” to a button
group with modified buttons to enable their toggling behavior via JavaScrip. Afterwards, use .btn-group-toggle to style
different inputs within your buttons.
<div class=”btn-group-toggle” data-toggle=”buttons”>
<label class=”btn btn-secondary active”>
<input type=”checkbox” checked autocomplete=”off”> Checked
</label>
</div>
Cards
Cards are flexible containers with options for headers/footers, colors and display options, and more. They replaced
several earlier components (panels, wells, and thumbnails) from Bootstrap 3.
.card-body
The main element of the card. Use it to add a padded section within your card.
<div class=”card”>
<div class=”card-body”>
Your awesome text
</div>
</div>
.card-title
Code a title for your card. Add this to a <h*> tag.
<h4 class=”card-title”>Big title</h4>
.card-subtitle
You can also add subtitles to every card for some extra fanciness.
<h6 class=”card-subtitle mb-2 text-muted”>Fancy card subtitle</h6>
.card-link
Embed a link inside your card. Add this class to an <a> tag.
<a href=”#!” class=”card-link”>Link to something fun</a>
.card-text
Add some words to your card. As many or as few as you want.
<p class=”card-text”>
Roses are red, violets are blue,
I’m learning Bootstrap,
What about you?
</p>
.card-img-top
You can also enclose an image to your card. This snippet will add one atop of it.
<div class=”card”>
<img class=”card-img-top” src=”/images/pathToYourImage.png” alt=”Card image cap”>
<div class=”card-body”> What an epic image!</div>
</div>
.card-img-bottom
Or you can have the image displayed as a bottom of the card. Your call.
<div class=”card”>
<div class=”card-body”> Look at that pic!</div>
<img class=”card-img-bottom” src=”/images/pathToYourImage.png” alt=”Card image
cap”>
</div>
.card-img-overlay
Use an image as a background and overlay all the texts.
<div class=”card”>
<img class=”card-img” src=”/images/pathToYourImage.png” alt=”Card image”>
<div class=”card-img-overlay”>
<p class=”card-text”>I’m text that has a background image!</p>
</div>
</div>
.card-header
Place a custom header at the top of your card. It will be displayed above all the titles and subtitles.
<div class=”card”>
<div class=”card-header”>
Some big header!
</div>
.card-footer
Also, you can code a footer for your card to communicate some extra info. It will go right after the .card-body.
<div class=”card”>
<div class=”card-body”>
<p class=”card-text”>Some more card content</p>
</div>
<div class=”card-footer”>
Updated 2 days ago
</div>
</div>
.card-group
Play around with card layout and build a group of cards.A group will act as a single, attached element, with every card
having the same width and height. You can also apply display: flex; to improve sizing.
Note: Group card layouts are not responsive!
<div class=”card-group”>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>Card number one</h4>
<p class=”card-text”>I’m the first card in the group, displaying some cool
info.</p>
</div>
</div>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>Card number two</h4>
<p class=”card-text”>I’m the middle card in the group and probably I offer the
best deal</p>
</div>
</div>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>Card three</h4>
<p class=”card-text”>I’m the third card trying to be as cool as the first
one.</p>
</div>
</div>
</div>
.card-columns
You can organize your cards into Masonry-like columns. This allows you to build some creative patterns using only CSS.
NB: If your cards are breaking across columns, set them to display: inline-block.
<div class=”card-columns”>
<div class=”card”>
<div class=”card-body”>
<!-- Card content -->
</div>
</div>
<div class=”card p-3”>
<!-- Card content -->
</div>
<div class=”card”>
<div class=”card-body”>
<!-- Card content -->
</div>
</div>
<div class=”card bg-primary p-3 text-center”>
<!-- Card content -->
</div>
</div>
.card-deck
Assemble a set of non-attached cards with equal height and width.
<div class=”card-deck”>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>Some title</h4>
<p class=”card-text”>Your texts </p>
</div>
</div>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>Another card</h4>
<p class=”card-text”>Even more texts that someone will need to write.</p>
</div>
</div>
<div class=”card”>
<div class=”card-body”>
<h4 class=”card-title”>I’m a card too!</h4>
<p class=”card-text”>Some words to add and arrange</p>
</div>
</div>
</div>
Carousel
Set up a slideshow to cycle through a series of slides, text, or images. Built with CSS 3D and some JS. You can add
images, text or custom markup, as well as add or remove previous/next controls.
.carousel-fade
Add this cool fade out effect for a slide before the next one.
<div id=”carouselFadeExampleIndicators” class=”carousel slide carousel-fade” data-
ride=”carousel”>
<div class=”carousel-inner” role=”listbox”>
<div class=”carousel-item active”>
<img class=”d-block w-100” src=”#” data-src=”holder.js/900x400?theme=social”
alt=”First slide”>
</div>
<div class=”carousel-item”>
<img class=”d-block w-100” src=”#” data-src=”holder.
js/900x400?theme=industrial” alt=”Second slide”>
</div>
</div>
<a class=”carousel-control-prev” href=”#carouselFadeExampleIndicators”
role=”button” data-slide=”prev”>
<span class=”carousel-control-prev-icon” aria-hidden=”true”></span>
<span class=”sr-only”>Previous</span>
</a>
<a class=”carousel-control-next” href=”#carouselFadeExampleIndicators”
role=”button” data-slide=”next”>
<span class=”carousel-control-next-icon” aria-hidden=”true”></span>
<span class=”sr-only”>Next</span>
</a>
</div>
.carousel-indicators
Add control and support for next/previous and indicators such as slide number.
<div id=”carouselExampleIndicators” class=”carousel slide” data-ride=”carousel”>
<ol class=”carousel-indicators”>
<li data-target=”#carouselExampleIndicators” data-slide-to=”0” class=”active”></
li>
<li data-target=”#carouselExampleIndicators” data-slide-to=”1”></li>
</ol>
<div class=”carousel-inner” role=”listbox”>
<div class=”carousel-item active”>
<img class=”d-block w-100” src=”#” data-src=”holder.js/900x400?theme=social”
alt=”First slide”>
</div>
<div class=”carousel-item”>
<img class=”d-block w-100” src=”#” data-src=”holder.
js/900x400?theme=industrial” alt=”Second slide”>
</div>
</div>
<a class=”carousel-control-prev” href=”#carouselExampleIndicators” role=”button”
data-slide=”prev”>
<span class=”carousel-control-prev-icon” aria-hidden=”true”></span>
<span class=”sr-only”>Previous</span>
</a>
<a class=”carousel-control-next” href=”#carouselExampleIndicators” role=”button”
data-slide=”next”>
<span class=”carousel-control-next-icon” aria-hidden=”true”></span>
<span class=”sr-only”>Next</span>
</a>
</div>
.carousel-caption
Add a funky caption to each or several slides.
<div class=”bd-example”>
<div id=”carouselExampleCaptions” class=”carousel slide” data-ride=”carousel”>
<ol class=”carousel-indicators”>
<li data-target=”#carouselExampleCaptions” data-slide-to=”0” class=”active”>
</li>
.collapse
Hide your content.
<div class=”collapse” id=”collapseExample”>
<div class=”card card-body”>
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh
helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
.collapse show
Display the collapsed content.
<div id=”demo” class=”collapse show”> Some text you’ve decided to hide </div>
.collapse.options
Activate content as collapsible element; accepts optional objects
$(‘#myCollapsible’).collapse({
toggle: false
})
.accordion
An extension of collabsaple behavior to cards. You can use this feature to create an accordion.
Note: You must use .accordion as a wrapper
Accordion Snippet Example with 2 group items
<div id=”accordion” role=”tablist”>
<div class=”card”>
<div class=”card-header” role=”tab” id=”headingOne”>
<h5 class=”mb-0”>
<a data-toggle=”collapse” href=”#collapseOne” aria-expanded=”true” aria-
controls=”collapseOne”>
Collapsible Group Item #1
</a>
</h5>
</div>
Custom Forms
Bootstrap 4 has several customized form elements that replace the browser defaults.
.custom-checkbox
As the name implies, you can build a custom checkbox for your form.
<div class=”custom-control custom-checkbox”>
<input type=”checkbox” class=”custom-control-input” id=”customCheck1”>
<label class=”custom-control-label” for=”customCheck1”>I have a cool custom
checkbox</label>
</div>
.custom-radio
…and you can style a custom radio too!
<div class=”custom-control custom-radio”>
<input type=”radio” id=”customRadio1” name=”customRadio” class=”custom-control-
input”>
<label class=”custom-control-label” for=”customRadio1”>Give this custom radio a
toggle</label>
</div>
.custom-switch
Lastly, you can also create a stylish custom switch.
<div class=”custom-control custom-switch”>
<input type=”checkbox” class=”custom-control-input” id=”customSwitch1”>
<label class=”custom-control-label” for=”customSwitch1”>Toggle this switch
element</label>
</div>
.custom-select
Use this command to add a custom select menu.
<select class=”custom-select”>
<option selected>Open this select menu</option>
<option value=”1”>One</option>
<option value=”2”>Two</option>
<option value=”3”>Three</option>
</select>
.custom-file
Customize user file upload. To do so, add .custom-file class around the input with type=”file”. Then add the .custom-file-
input to it.
<div class=”custom-file”>
<input type=”file” class=”custom-file-input” id=”customFile”>
<label class=”custom-file-label” for=”customFile”>Choose file</label>
</div>
.custom-range
Design a custom range menu.
<label for=”customRange1”>Basic range</label>
<input type=”range” class=”custom-range” id=”customRange1”>
<label class=”mt-3” for=”customRange3”>Range with steps</label>
<input type=”range” class=”custom-range” min=”0” max=”5” step=”0.5”
id=”customRange3”>
Dropdowns
Use this plugin to create contextual overlays for displaying lists of user links. It’s a handy option for creating menus.
Dropdowns are built through Popper.js, part of a third-party library. Thus, Make sure you include popper.min.js before
Bootstrap’s own JavaScript. Or you can just use bootstrap.bundle.min.js/ bootstrap.bundle.js. Both contain Popper.js.
Quick styling tip: all dropdowns in Bootstrap are toggled by clicking, not hovering.
.dropdown
Add a simple dropdown menu with buttons.
<div class=”dropdown”>
<button class=”btn btn-secondary dropdown-toggle”
type=”button” id=”dropdownMenu1” data-toggle=”dropdown”
aria-haspopup=”true” aria-expanded=”false”>
Dropdown
</button>
<div class=”dropdown-menu” aria-labelledby=”dropdownMenu1”>
<a class=”dropdown-item” href=”#!”>Action</a>
<a class=”dropdown-item” href=”#!”>Another action</a>
</div>
</div>
.dropdown-toggle-split
Create split button dropdowns with proper spacing around the dropdown caret.
<div class=”btn-group”>
<button type=”button” class=”btn btn-secondary”>Dropdown</button>
<button type=”button” class=”btn btn-secondary dropdown-toggle dropdown-toggle-
split” data-toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
<span class=”sr-only”>Toggle Dropdown</span>
</button>
<div class=”dropdown-menu”>
<a class=”dropdown-item” href=”#!”>Action</a>
<a class=”dropdown-item” href=”#!”>Another action</a>
</div>
</div>
.dropup
Did you know that you can style a menu coming up rather than down? Now you do!
<!-- Default dropup button -->
<div class=”btn-group dropup”>
<button type=”button” class=”btn btn-secondary dropdown-toggle” data-
toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
Dropup
</button>
<div class=”dropdown-menu”>
<!-- Dropdown menu links -->
</div>
</div>
.dropright
Provide the menu to the right of the button.
<!-- Default dropright button -->
<div class=”btn-group dropright”>
<button type=”button” class=”btn btn-secondary dropdown-toggle” data-
toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
Dropright
</button>
<div class=”dropdown-menu”>
<!-- Dropdown menu links -->
</div>
</div>
.dropleft
…And you can also display the menu on the left.
<!-- Default dropleft button -->
<div class=”btn-group dropleft”>
<button type=”button” class=”btn btn-secondary dropdown-toggle” data-
toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
Dropleft
</button>
<div class=”dropdown-menu”>
<!-- Dropdown menu links -->
</div>
</div>
.dropdown-item-text
Add non-interactive dropdown items to your menu.
<div class=”dropdown-menu”>
<span class=”dropdown-item-text”>Plain text</span>
<a class=”dropdown-item” href=”#”>Clickable action</a>
<a class=”dropdown-item” href=”#”>Another action</a>
<a class=”dropdown-item” href=”#”>Whatever else you need</a>
</div>
.dropdown-item disabled
You can also choose to disable any menu item(s).
<div class=”dropdown-menu”>
<a class=”dropdown-item” href=”#”>Active link</a>
<a class=”dropdown-item disabled” href=”#”>Disabled link</a>
<a class=”dropdown-item” href=”#”>One more link</a>
</div>
.dropdown-divider
Add a simple divider between menu elements to draw extra attention.
<div class=”dropdown-divider”></div>
.dropdown-menu-right
Align the entire menu to the right
<div class=”btn-group”>
<button type=”button” class=”btn btn-secondary dropdown-toggle” data-
toggle=”dropdown” aria-haspopup=”true” aria-expanded=”false”>
This dropdown’s menu is right-aligned
</button>
<div class=”dropdown-menu dropdown-menu-right”>
<button class=”dropdown-item” type=”button”>Action</button>
<button class=”dropdown-item” type=”button”>Another action</button>
<button class=”dropdown-item” type=”button”>Something else here</button>
</div>
</div>
Forms
You can easily build attractive forms and code custom styles, layouts and additional elements. In Bootstrap 4, forms
also received some new input controls such as number election, email verification and others, along with a bunch of new
responsive classes.
Example of .form-group
<form>
<div class=”form-group”>
<label for=”exampleInputEmail1”>Email address</label>
<input type=”email” class=”form-control” id=”exampleInputEmail1” aria-
describedby=”emailHelp” placeholder=”Provide email”>
</div>
<div class=”form-group”>
<label for=”exampleInputPassword1”>Your password</label>
<input type=”password” class=”form-control” id=”exampleInputPassword1”
placeholder=”Password”>
</div>
<div class=”form-group form-check”>
<input type=”checkbox” class=”form-check-input” id=”exampleCheck1”>
<label class=”form-check-label” for=”exampleCheck1”>Remember me</label>
</div>
<button type=”submit” class=”btn btn-primary”>Submit</button>
</form>
.form-control
Use this class to style all textual form controls such as user input, titles, etc.
<form>
<div class=”form-group”>
<label for=”exampleFormControlInput1”>Email address</label>
<input type=”email” class=”form-control” id=”exampleFormControlInput1”
placeholder=”[email protected]”>
</div>
.form-control-file
Add this class whenever you need to provide the user with an option to upload a file to the form.
<input type=”file” class=”form-control-file” id=”exampleFormControlFile1”>
.form-control-plaintext
Use this class to correctly display <input readonly> elements in your form. It will replace the default form field styling with
plain text, while keeping the correct margin and padding.
<form>
<div class=”form-group row”>
<label for=”staticEmail” class=”col-sm-2 col-form-label”>Email</label>
<div class=”col-sm-10”>
<input type=”text” readonly class=”form-control-plaintext” id=”staticEmail”
value=”[email protected]”>
</div>
</div>
<div class=”form-group row”>
<label for=”inputPassword” class=”col-sm-2 col-form-label”>Pass</label>
<div class=”col-sm-10”>
<input type=”password” class=”form-control” id=”inputPassword”
placeholder=”Password”>
</div>
</div>
</form>
.form-control-range
Set horizontally scrollable range inputs for your form.
<form>
<div class=”form-group”>
<label for=”formControlRange”>Some range input</label>
<input type=”range” class=”form-control-range” id=”formControlRange”>
</div>
</form>
.form-check
Add checkboxes to your form.
<div class=”form-check”>
<input class=”form-check-input” type=”checkbox” value=”” id=”defaultCheck1”>
<label class=”form-check-label” for=”defaultCheck1”>
My first checkbox
</label>
</div>
Note: You can also add radio buttons instead of checkboxes using form-check-input”
type=”radio”.
.form-check-inline
Create a horizontal list of checkboxes.
<div class=”form-check form-check-inline”>
<input class=”form-check-input” type=”checkbox” id=”inlineCheckbox1”
value=”option1”>
<label class=”form-check-label” for=”inlineCheckbox1”>1</label>
</div>
<div class=”form-check form-check-inline”>
<input class=”form-check-input” type=”checkbox” id=”inlineCheckbox2”
value=”option2”>
<label class=”form-check-label” for=”inlineCheckbox2”>2</label>
</div>
Input Group
Input group element lets you create more interactive and attractive form controls. Use it to add texts, icons or buttons on
both sides of the input field.
.input-group-prepend
Provide additional texts in front of the input.
<form>
<div class=”input-group mb-3”>
<div class=”input-group-prepend”>
<span class=”input-group-text”>@</span>
</div>
<input type=”text” class=”form-control” placeholder=”Name”>
</div>
.input-group-append
…Or list them behind the input.
<div class=”input-group mb-3”>
<input type=”text” class=”form-control” placeholder=”Password”>
<div class=”input-group-append”>
<span class=”input-group-text”>@example.com</span>
</div>
</div>
</form>
.input-group-text
Use this class to style specified texts.
<div class=”input-group mb-3”>
<input type=”text” class=”form-control” placeholder=”1000” aria-label=”Amount
(rounded to the nearest dollar)” aria-describedby=”basic-addon”>
<div class=”input-group-append”>
<span class=”input-group-text” id=”basic-addon”>.00</span>
</div>
</div>
Jumbotron
A flexible component that will help you create big boxes to command more attention to featured content or message. In
Bootstrap, jumbotron looks like a grey box with rounded corners that automatically enlarges all the font sizes and texts
inside of it.
You can add any HTML and other Bootstrap classes inside a jumbotron.
.jumbotron
<div class=”jumbotron”>
<h1 class=”display-3”>Hey, awesome you!</h1>
<p class=”lead”>This is a simple hero unit, showing that anyone can be a real
hero!.</p>
<hr class=”my-2”>
<p>Use utility classes for typography and spacing</p>
<p class=”lead”>
<a class=”btn btn-primary btn-lg” href=”#!” role=”button”>Ready for action</a>
</p>
</div>
.jumbotron-fluid
Slightly changes the look of jumbotron and makes it full-page wide without rounded corners.
<div class=”jumbotron jumbotron-fluid”>
<div class=”container”>
<h1 class=”display-3”>Fluid jumbotron</h1>
<p class=”lead”>I’m taking up the entire horizontal space on the page.</p>
</div>
</div>
List Group
Use list groups to display series of content, with lots of options for styling and layouts.
.list-group - Example
Create a basic list group with several items.
<ul class=”list-group”>
<li class=”list-group-item”>Milk</li>
<li class=”list-group-item”>Tea</li>
<li class=”list-group-item”>Toffees</li>
</ul>
.list-group-item active
Add .active class to highlight the current active selection in the list.
<ul class=”list-group”>
<li class=”list-group-item active”>I want this</li>
<li class=”list-group-item”>Not this</li>
<li class=”list-group-item”>Or this</li>
</ul>
.list-group-item disabled
Show that one of the list items is not available/disaibled. Some active elements (e.g. links) will require custom JavaScript
on top of .disable to become fully inactive.
<ul class=”list-group”>
<li class=”list-group-item disabled”>This product is out of stock</li>
<li class=”list-group-item”>But we have this!</li>
<li class=”list-group-item”>And also this cool thing</li>
</ul>
.list-group-item-action
Add more interactivity to your list by adding styling effects (disabeled, hover, active, etc.) to individual items.
<div class=”list-group”>
<a href=”#” class=”list-group-item list-group-item-action active”>
Our prime choice for you!
</a>
<a href=”#” class=”list-group-item list-group-item-action”>Some good offer</a>
<a href=”#” class=”list-group-item list-group-item-action”>Also an option</a>
<a href=”#” class=”list-group-item list-group-item-action”>Something else on the
list</a>
<a href=”#” class=”list-group-item list-group-item-action disabled” tabindex=”-1”
aria-disabled=”true”>And this one’s not available</a>
</div>
.list-group-flush
Change the look of our list by removing borders and rounded corners. All the items will be placed edge-to-edge.
<ul class=”list-group list-group-flush”>
<li class=”list-group-item”>Chai Latte</li>
<li class=”list-group-item”>Matcha Latte</li>
<li class=”list-group-item”>Earl Grey Tea</li>
<li class=”list-group-item”>Vanilla Rooibos</li>
<li class=”list-group-item”>Mate</li>
</ul>
.list-group-horizontal
You can also set your list up horizontally rather than vertically. You can also code the list group to become horizontal
starting at a certain breakpoint’s min-width using .list-group-horizontal-{sm|md|lg|xl}.
NB: You can’t use horizontal list groups with flush list groups at the same time.
<ul class=”list-group list-group-horizontal”>
<li class=”list-group-item”>Trains</li>
<li class=”list-group-item”>Planes</li>
<li class=”list-group-item”>Rockets</li>
</ul>
.list-group-item
(light, dark primary, secondary, transparent, white, warning, success, info, danger)
Apply standard styles to individual list items.
<ul class=”list-group”>
<li class=”list-group-item”>All the colors that I have </li>
<li class=”list-group-item list-group-item-primary”>Light blue</li>
<li class=”list-group-item list-group-item-secondary”>Light gray</li>
<li class=”list-group-item list-group-item-success”>Green</li>
<li class=”list-group-item list-group-item-danger”>Red</li>
<li class=”list-group-item list-group-item-warning”>Yellow</li>
<li class=”list-group-item list-group-item-info”>Teal</li>
<li class=”list-group-item list-group-item-light”>White</li>
<li class=”list-group-item list-group-item-dark”>Gray</li>
</ul>
Media Object
Bootstrap 4 lets you build complex, repetitive components featuring texts and some media. Media objects are a cool tool
to build tweet-like elements and featured boxes. Also, they are ridiculously easy to use as they require just two classes.
.media
Use the .media wrapping and .media-body around the content to create a single media object. Here is a sample for a
heading.
<div class=”media”>
<img class=”d-flex mr-3” data-src=”holder.js/64x64?theme=sky” alt=”Some nice
placeholder image”>
<div class=”media-body”>
<h5 class=”mt-0”>Your heading</h5>
A key message you want to share with the world!
</div>
</div>
.media-body
A class specifying what would be inside of your object. You can code different alignments for your content. The default is
top, but you can align in the middle or end.
<div class=”media”>
<img src=”...” class=”align-self-start mr-3” alt=”...”>
<div class=”media-body”>
<h5 class=”mt-0”>Top-aligned media</h5>
<p>Read the texts describing the picture above</p>
</div>
Nested Media
You also have the option to include more than one media object. Objects are nested by beginning at left margin and
tabbing each new object in.
Nav
.nav is a base class that helps you build all sorts of navigation components, even with style overrides. You have lots of
options for customization.
.nav example
<ul class=”nav”>
<li class=”nav-item”>
<a class=”nav-link disabled” href=”#”>You can’t click this disabled link</a>
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#”>Click this instead</a>
</li>
</ul>
.nav-items
A class to specify a new item in the navigation menu.
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#”>Some item</a>
</li>
.nav justify-content-center
Align your nav horizontally in the center.
<ul class=”nav justify-content-center”>
<li class=”nav-item”>
<a class=”nav-link active” href=”#”>Active</a>
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#”>Link</a>
</li>
</ul>
.nav justify-content-end
Or justify your content to the right.
<ul class=”nav justify-content-end”>
<li class=”nav-item”>
<a class=”nav-link active” href=”#”>Active</a>
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#”>Link</a>
</li>
</ul>
.nav-tabs
Add some cool tabs to your navigation menu.
.nav-pills
Alternatively, you can style the menu components as pills.
.Nav-justified
Equalize the widths of all tabs/pills by adding .nav-justified to .nav, .nav-tabs, or .nav, .nav-pills.
Justified Nav Elements Example
<ul class=“nav nav-pills nav-justified”>
<li class=“active”><a href=“#”>Home</a></li>
<li><a href=“#”>HTML</a></li>
<li><a href=“#”>CSS</a></li>
<li><a href=“#”>PHP</a></li>
<li><a href=“#”>Java</a></li>
</ul>
.nav-fill
Instead of justifying, you can also force your menu items to fill in all the available space using this command. However, all
the items will not have the same width.
<ul class=”nav nav-pills nav-fill”>
<li class=”nav-item”>
<a class=”nav-link active” href=”#!”>Active</a>
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#!”>This link is looooong</a>
</li>
<li class=”nav-item”>
<a class=”nav-link” href=”#!”>Short Link</a>
</li>
</ul>
Navbar
Navbar is a responsive navigation header with lots of flexibility and support for branding, forms, links, and more.
.navbar-brand
Navbars come pre-furnished with support for some sub-components. This element will make your text stand out more. It
was pre-designed to accommodate a product or company name.
<nav class=”navbar navbar-light bg-light”>
<a class=”navbar-brand” href=”#!”>Your Company Name</a>
</nav>
.navbar-text
Use this class to add centered text strings vertically and horizontal spacing
<nav class=”navbar navbar-light bg-light”>
<span class=”navbar-text”>
I’m a navbar text with an inline element
</span>
</nav>
.navbar-toggler
Program different navigation toggling behaviors (e.g. keep items active or collapse them).
<nav class=”navbar navbar-expand-lg navbar-light bg-light”>
<button class=”navbar-toggler navbar-toggler-right” type=”button” data-
toggle=”collapse” data-target=”#navbarTogglerDemo02” aria-controls=”navbarTogglerDemo02”
aria-expanded=”false” aria-label=”Toggle navigation”>
<span class=”navbar-toggler-icon”></span>
</button>
<a class=”navbar-brand” href=”#!”>Navbar</a>
.form-inline
Place a form (e.g. search bar) in nav heading.
.collapse.navbar-collapse
Group and collapse navbar contents by a parent breakpoint.
<nav class=”navbar navbar-expand-lg navbar-light bg-light”>
<a class=”navbar-brand” href=”#”>Navbar</a>
<button class=”navbar-toggler” type=”button” data-toggle=”collapse” data-target=”#
navbarSupportedContent” aria-controls=”navbarSupportedContent” aria-expanded=”false”
aria-label=”Toggle navigation”>
<span class=”navbar-toggler-icon”></span>
</button>
Modals consist of HTML, CSS, and JavaScript. And you can display one modal window at a time only, as Bootstrap
creators deem nested models as a poor UX practice.
Modal Example
<div class=”modal” tabindex=”-1” role=”dialog”>
<div class=”modal-dialog” role=”document”>
<div class=”modal-content”>
<div class=”modal-header”>
<h5 class=”modal-title”>Give it a title</h5>
<button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<div class=”modal-body”>
<p>Add some modal body text here.</p>
</div>
<div class=”modal-footer”>
<button type=”button” class=”btn btn-primary”>Agree</button>
<button type=”button” class=”btn btn-secondary” data-
dismiss=”modal”>Disagree</button>
</div>
</div>
</div>
</div>
.modal-dialog-centered
You can choose to center all content vertically.
<div class=”modal” tabindex=”-1” role=”dialog”>
<div class=”modal-dialog modal-dialog-centered” role=”document”>
<div class=”modal-content”>
<div class=”modal-header”>
<h5 class=”modal-title” id=”exampleModalCenterTitle”>Modal title</h5>
<button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<div class=”modal-body”>
.modal-dialog-scrollable
When you need to pack in more content into a modal (e.g. a lengthy privacy policy), you can add this class to make it
scroll it independently from the page.
<div class=”modal” id=”exampleModalScrollable” tabindex=”-1” role=”dialog” aria-labe
lledby=”exampleModalScrollableLabel” aria-hidden=”true”>
<div class=”modal-dialog modal-dialog-scrollable” role=”document”>
<div class=”modal-content”>
<div class=”modal-header”>
<h5 class=”modal-title” id=”exampleModalCenteredLabel”>Modal title</h5>
<button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<div class=”modal-body”>
This is a super long terms & conditions agreement that you’ll agree to without actually reading it.
</div>
<div class=”modal-footer”>
<button type=”button” class=”btn btn-secondary” data-dismiss=”modal”>Close</
button>
<button type=”button” class=”btn btn-primary”>Save changes</button>
</div>
</div>
</div>
</div>
.modal fade
Enabled fading for the content.
<div class=”modal fade” id=”exampleModal3” tabindex=”-1” role=”dialog” aria-
labelledby=”exampleModal3Label” aria-hidden=”true”>
<div class=”modal-dialog” role=”document”>
<div class=”modal-content”>
<div class=”modal-header”>
<h5 class=”modal-title” id=”exampleModal3Label”>Modal title</h5>
<button type=”button” class=”close” data-dismiss=”modal” aria-label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<div class=”modal-body”>
Gotta right at least something here.
</div>
<div class=”modal-footer”>
<button type=”button” class=”btn btn-secondary” data-dismiss=”modal”>Close</
button>
<button type=”button” class=”btn btn-primary”>Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Small modal -->
<button type=”button” class=”btn btn-primary” data-toggle=”modal” data-target=”.bd-
example-modal-sm”>
Small modal
</button>
NOTE: Bootstrap offers a demo of all of these components at the Modal page. They are worth a look.
Paginators
If you know HTML, paginators are nothing new to you. With Bootstrap you have several options for styling them.
.page-item disabled
You can choose to disable one of the pagination elements or several ones.
<nav aria-label=”...”>
<ul class=”pagination”>
<li class=”page-item disabled”>
<a class=”page-link” href=”#” tabindex=”-1” aria-disabled=”true”>Previous</a>
</li>
<li class=”page-item”><a class=”page-link” href=”#”>1</a></li>
<li class=”page-item active” aria-current=”page”>
<a class=”page-link” href=”#”>2 <span class=”sr-only”>(current)</span></a>
</li>
<li class=”page-item”><a class=”page-link” href=”#”>3</a></li>
<li class=”page-item”>
<a class=”page-link” href=”#”>Next</a>
</li>
</ul>
</nav>
.page-item active
active indicates the current stage by highlighting it with blue.
<nav aria-label=”...”>
<ul class=”pagination”>
<li class=”page-item disabled”>
<a class=”page-link” href=”#!” tabindex=”-1”>Previous</a>
</li>
<li class=”page-item”><a class=”page-link” href=”#!”>1</a></li>
<li class=”page-item active”>
<a class=”page-link” href=”#!”>2 <span class=”sr-only”>(current)</span></a>
</li>
<li class=”page-item”><a class=”page-link” href=”#!”>3</a></li>
<li class=”page-item”>
<a class=”page-link” href=”#!”>Next</a>
</li>
</ul>
</nav>
.pagination-lg
Make your pagination bigger and bolder.
<nav aria-label=”...”>
<ul class=”pagination pagination-lg”>
<li class=”page-item disabled”>
<a class=”page-link” href=”#!” tabindex=”-1”>Previous</a>
</li>
<li class=”page-item”><a class=”page-link” href=”#!”>1</a></li>
<li class=”page-item”><a class=”page-link” href=”#!”>2</a></li>
<li class=”page-item”><a class=”page-link” href=”#!”>3</a></li>
<li class=”page-item”>
<a class=”page-link” href=”#!”>Next</a>
</li>
</ul>
</nav>
.pagination-sm
Or make it petite and less visible in size.
<nav aria-label=”...”>
<ul class=”pagination pagination-sm”>
<li class=”page-item disabled”>
<a class=”page-link” href=”#!” tabindex=”-1”>Previous</a>
</li>
<li class=”page-item”><a class=”page-link” href=”#!”>1</a></li>
<li class=”page-item”><a class=”page-link” href=”#!”>2</a></li>
<li class=”page-item”><a class=”page-link” href=”#!”>3</a></li>
<li class=”page-item”>
<a class=”page-link” href=”#!”>Next</a>
</li>
</ul>
</nav>
Popovers
Popover plugin enables you to create a pop-up box with content and other elements, activated whenever a user clicks on
the element. Popovers are similar to tooltips, but fit more content.
Things to Know Before You Begin:
• You have to add the attribute, data-toggle=“popover” to an element to create a popover.
• You must use the title attribute to specify header text
• Use the data-content attribute to specify what content is to be displayed in the body of the popover.
<a href=”#” data-toggle=”popover” title=”Popover Header” data-content=”Some content
inside the popover”>Toggle popover</a>
Popover
Here’s the code that will enable popovers on your page:
<script>
$(document).ready(function(){
$(‘[data-toggle=”popover”]’).popover();
});
</script>
Popover on right
<button type=”button” class=”btn btn-secondary” data-container=”body” data-
toggle=”popover” data-placement=”right” data-content=”Vivamus sagittis lacus vel
augue laoreet rutrum faucibus.”>
Popover on right
</button>
Popover on bottom
<button type=”button” class=”btn btn-secondary” data-container=”body” data-
toggle=”popover” data-placement=”bottom” data-content=”Vivamus
sagittis lacus vel augue laoreet rutrum faucibus.”>
Popover on bottom
</button>
Popover on left
<button type=”button” class=”btn btn-secondary” data-container=”body” data-
toggle=”popover” data-placement=”left” data-content=”Vivamus sagittis lacus vel
augue laoreet rutrum faucibus.”>
Popover on left
</button>
.popover-dismiss
Provide users with the option to close a popover when they click on the element the second time.You can arrange for the
popover to dismiss when user clicks outside the element too: Use the data-trigger=”focus” attribute.
By default, the popover is closed when you click on the element again. However, you can use the data-trigger=”focus”
attribute which will close the popover when clicking outside the element:
<a href=”#” title=”Dismissible popover” data-toggle=”popover” data-trigger=”focus”
data-content=”Click anywhere in the document to close this popover”>Click me</a>
Progress
Develop a custom progress bar and add additional styling elements such as animation and text labels if you like.
.progress
The class for setting up a basic progress bar. It acts as a wrapper, indicating the max value of your progress bar.
<div class=”progress”>
<div class=”progress-bar” role=”progressbar” style=”width: 41%” aria-valuenow=”41”
aria-valuemin=”0” aria-valuemax=”100”></div>
</div>
.progress-bar
Use this command to specify the current progress.
<div class=”progress”>
<div class=”progress-bar” role=”progressbar” style=”width: 55%” aria-valuenow=”55”
aria-valuemin=”0” aria-valuemax=”100”></div>
</div>
.progress-bar-striped
Add some stripes to the progress bar section.
<div class=”progress”>
<div class=”progress-bar progress-bar-striped” role=”progressbar” style=”width:
10%” aria-valuenow=”10” aria-valuemin=”0” aria-valuemax=”100”></div>
</div>
.progress-bar-animated
No get those stripes moving, barber’s pole style.
<div class=”progress”>
<div class=”progress-bar progress-bar-striped progress-bar-animated”
role=”progressbar” aria-valuenow=”75” aria-valuemin=”0” aria-valuemax=”100”
style=”width: 75%”></div>
</div>
<div class=”progress”>
<div class=”progress-bar” role=”progressbar” style=”width: 15%” aria-valuenow=”15”
aria-valuemin=”0” aria-valuemax=”100”></div>
<div class=”progress-bar bg-success” role=”progressbar” style=”width: 30%” aria-
valuenow=”30” aria-valuemin=”0” aria-valuemax=”100”></div>
<div class=”progress-bar bg-info” role=”progressbar” style=”width: 20%” aria-
valuenow=”20” aria-valuemin=”0” aria-valuemax=”100”></div>
</div>
Spinner
Use this plugin to add that animated spinner. Spinners are built with HTML and CSS only, without any JS. But…you may
need JavaScript for some styling options e.g. to toggle their visibility. Also, you have sveral nice options to choose from.
.spinner-border
Build a black and white loading indicator.
<div class=”spinner-border” role=”status”>
<span class=”sr-only”>Loading...</span>
</div>
.spinner-border-primary (-secondary, -light, -dark, -warning, -success, -info, -danger)
Or add a colorful border, using the standard Bootstrap styling attributes.
<div class=”spinner-border text-primary” role=”status”> <span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-secondary” role=”status”> <span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-success” role=”status”> <span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-danger” role=”status”><span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-warning” role=”status”> <span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-info” role=”status”><span class=”sr-
only”>Loading...</span> </div>
<div class=”spinner-border text-light” role=”status”><span class=”sr-
only”>Loading...</span></div>
<div class=”spinner-border text-dark” role=”status”><span class=”sr-
only”>Loading...</span> </div>
Growing Spinner
Create a pulsating spinner that increases and reduces in size. A funky alternative to the spinning spinner :). Again, it can
be designed in several colors.
<div class=”spinner-grow text-primary” role=”status”> <span class=”sr-
only”>Loading...</span> </div>
Table
Bootstrap offers an easy-peasy way to create tables. Add base class .table to an
<table> and add-on extra custom styles.
NB: All table styles are inherited in Bootstrap 4. Every nested table will be styled just as the parent.
.table - example
<table class=”table”>
<thead>
<tr>
<th scope=”col”>#</th>
<th scope=”col”>First</th>
<th scope=”col”>Last</th>
<th scope=”col”>Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr>
<th scope=”row”>3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
.table-dark
Create a table with a dark background and light texts.
<table class=”table table-dark”>
<thead>
<tr>
<th scope=”col”>#</th>
<th scope=”col”>Nickname</th>
<th scope=”col”>Followers</th>
<th scope=”col”>Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Minimark</td>
<td>5,000</td>
<td>@minik</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Gigi_B</td>
<td>24K</td>
<td>@gig</td>
</tr>
<tr>
<th scope=”row”>3</th>
<td>Birdie</td>
<td>50K</td>
<td>@bi)rdi</td>
</tr>
</tbody>
</table>
<tr>
<th scope=”row”>2</th>
<td>#6</td>
<td>Return of the Jedi</td>
<td>9/10</td>
</tr>
<tr>
<th scope=”row”>3</th>
<td>#9</td>
<td>Rise of the Skywalker</td>
<td>6/10</td>
</tr>
</tbody>
</table>
<table class=”table”>
<thead class=”thead-light”>
<tr>
<th scope=”col”>#</th>
<th scope=”col”>Episode</th>
<th scope=”col”>Title</th>
<th scope=”col”>Raiting</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>#2</td>
<td>Revenge of the Sith</td>
<td>7/10</td>
</tr>
<tr>
<th scope=”row”>3</th>
<td>#5</td>
<td>The Empire Strikes Back</td>
<td>10/10</td>
</tr>
</tbody>
</table>
.table-striped
Add this class to within the <tbody> to make your table zebra-stripey.
<table class=”table table-striped”>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Darth</td>
<td>Vader</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Ray</td>
<td>Just Ray</td>
</tr>
</tbody>
</table>
.table-bordered
Style borders for all the cells and table sides.
<table class=”table table-bordered”>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Lil</td>
<td>Kim</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Kanye</td>
<td>West</td>
</tr>
</tbody>
</table>
.table-borderless
Ditch the borders to give your table a minimalistic flair.
<table class=”table table-borderless”>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Indiana</td>
<td>Jones</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Han</td>
<td>Solo</td>
</tr>
</tbody>
</table>
.table-hover
Add a hover state on table rows.
<table class=”table table-hover”>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Mark</td>
<td>Twain</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Henry</td>
<td>James</td>
</tr>
</tbody>
</table>
.table-sm
Minify your table. This class will cut the cell padding in half.
<table class=”table table-sm”>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<th scope=”row”>1</th>
<td>Amy</td>
<td>Winehouse</td>
</tr>
<tr>
<th scope=”row”>2</th>
<td>Kurt</td>
<td>Cobain</td>
</tr>
</tbody>
</table>
<tr class=”table-active”>...</tr>
<tr class=”table-primary”>...</tr>
<tr class=”table-secondary”>...</tr>
<tr class=”table-success”>...</tr>
<tr class=”table-danger”>...</tr>
<tr class=”table-warning”>...</tr>
<tr class=”table-info”>...</tr>
<tr class=”table-light”>...</tr>
<tr class=”table-dark”>...</tr>
Toasts
A plugin that allows you to add “push notifications” with Flexbox - very easy to position and align. use these as an
alternative to alerts.
.toast - example
<div class=”toast” role=”alert” aria-live=”assertive” aria-atomic=”true”>
<div class=”toast-header”>
<img src=”...” class=”rounded mr-2” alt=”...”>
<strong class=”mr-auto”>Bootstrap</strong>
<small>11 mins ago</small>
<button type=”button” class=”ml-2 mb-1 close” data-dismiss=”toast” aria-
label=”Close”>
<span aria-hidden=”true”>×</span>
</button>
</div>
<div class=”toast-body”>
Kudos, I’m a toast message!
</div>
</div>
Tooltips
Tooltips are small text pop-ups that provide users with some additional context on the button or another website
element. In Bootstrap 4, tooltips use Popper.js library for positioning. That’s why to use them you must include popper.
min.js before bootstrap.js or use bootstrap.bundle.min.js / bootstrap.bundle.js.
Enable Tooltips
$(function () {$(‘[data-toggle=”tooltip”]’).tooltip()})
Tooltip on right
<button type=”button” class=”btn btn-secondary” data-toggle=”tooltip” data-
placement=”right” title=”Tooltip on right”></button>
Tooltip on bottom
<button type=”button” class=”btn btn-secondary” data-toggle=”tooltip” data-
placement=”bottom” title=”Tooltip on bottom”></button>
Tooltip on left
<button type=”button” class=”btn btn-secondary” data-toggle=”tooltip” data-
placement=”left” title=”Tooltip on left”>
For more advanced customizations and JavaScript methods, check the official Tooltip documentation.
Breakpoints
For most components, layouts and grid systems Bootstrap uses the following breakpoint values:
Extra small < 544px
Small ≥ 544px
Medium ≥ 768px
Large ≥ 992px
Extra large ≥ 1200px
.container-fluid
Scale your container to span over the entire viewpoint.
<div class=”container-fluid”>
<!-- A fluid container that uses the full width -->
</div>
Column Sizes
Select among xs, sm, md, lg. Again, when you add columns, they have to fit the screen sizes of all devices or users will be
frustrated
Here’s the code snippet - just change the size element
<div class=”container”>
<div class=”row”>
<div class=”col-xl-2”>
<!-- Content -->
</div>
<div class=”col-xl-2”>
<!-- Content -->
</div>
<div class=”col-xl-8”>
<!-- Content -->
</div>
</div>
</div>
.no-gutters
The standard space between columns is 15px on each side. But you can remove it.
<div class=”container”>
<div class=”row no-gutters”>
<div class=”col-12 col-sm-6 col-md-8”>.col-12 .col-sm-6 .col-md-8</div>
<div class=”col-6 col-md-4”>.col-6 .col-md-4</div>
</div>
</div>
.text-lowercase
<p class=”text-lowercase”>lowercased text.</p>
.text-uppercase
<p class=”text-uppercase”>uppercased text.</p>
.text-capitalize
<p class=”text-capitalize”>capitalized text.</p>
.text-truncate
<p class=”text-truncate”>truncated text.</p>
.text-nowrap
<p class=”text-nowrap”>No Wrap Text.</p>
.text-monoscape
<p class=”text-monospace”>This is in monospace</p>
.text-hide
<h1 class=”text-hide”>Custom heading</h1>
.text-decoration-none
<p class=”text-decoration-none”>this text is not decorated</p>
.initialism
Add a smaller font-size to style abbreviations.
Lead
When you want to add emphasis to a specific paragraph of content, you can make the font a bit larger and even thinner,
so that the paragraph stands out visually.
<p class=”lead”>This is the info you should really pay attention to!</p>
Blockquote
If you are inserting a quote that is a bit lengthy, this will class allow you to set it off from the rest of the text.
<blockquote class=”blockquote”>
<p class=”mb-0”>Some cool quote that you’ve found</p>
</blockquote>
Blockquote Footer
Add the source of a quote by adding the footer element.
<blockquote class=”blockquote”>
<p class=”mb-0”>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<footer class=”blockquote-footer”>Someone famous in
<cite title=”Source Title”>Source Title</cite>
</footer>
</blockquote>
.text-break
This prevents super-long texts from breaking the look of your other design elements.
<p class=”text-break”>mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm</p>
Floats
.float-left - floats item left - all sizes
<div class=”float-left”>Float left on all viewport sizes</div>
<div class=”float-sm-left”>Float left on viewports sized SM (small) or wider</div>
<div class=”float-md-left”>Float left on viewports sized MD (medium) or wider</div>
<div class=”float-lg-left”>Float left on viewports sized LG (large) or wider</div>
<div class=”float-xl-left”>Float left on viewports sized XL (extra-large) or wider</
div>
Flex
You can easily and quickly manage your layouts, alignments, sizings, navs, displays, colors, alignment, and much more
with this single Bootstrap utility tool.
Flex - sm-lg-md-xl
Size all of your elements using predetermined sizes and be fully responsive.
.Flex-fill
This utility forces all elements to occupy an equal width while taking up all the available horizontal space.
<div class=”d-flex text-white”>
<div class=”p-2 flex-fill bg-primary”>Flex item</div>
<div class=”p-2 flex-fill bg-success”>Flex item</div>
<div class=”p-2 flex-fill bg-primary”>Flex item</div>
</div>
.Flex-grow-*
One of the flex items will fill all the available space, while ensuring that others also have minimally sufficient space.
<div class=”d-flex text-white”>
<div class=”p-2 flex-grow-1 bg-primary”>Flex item</div>
<div class=”p-2 bg-success”>Flex item</div>
<div class=”p-2 bg-primary”>Third flex item</div>
</div>
.Flex-shrink-*
Activate the item’s ability to shrink to the most minimal size to fill in the available space.
.flex justify-content
Add this class when you want to justify text on right or left, and when you want that justification to start and end.
.flex align-items
Specify when the alignment begins and when it ends for a list of items.
.flex align-self-start
You can also override a containers alignment for a selected item within that container
Alignment
How and where do you want to align your content, buttons, etc. - right, left, center?
.align-baseline
<div class=”align-self-baseline”>Aligned flex item</div>
Borders
Borders add elegance to a site. Use them for emphasis or aesthetics
.border
<span class=”border border-dark”>Hello World</span>
.fixed-top, .fixed-bottom
Place an element at the top or bottom of the viewport, from edge to edge.
.shadow-none
<div class=”shadow-none p-3 mb-5 bg-light rounded”>No shadow</div>
.shadow-sm
<div class=”shadow-sm p-3 mb-5 bg-light rounded”>Small Shadow shadow</div>
.shadow-lg
<div class=”shadow-lg p-3 mb-5 bg-white rounded”>Larger shadow</div>
Invisible
<div class=”invisible”>...</div>
JavaScript
JavaScript is a programming language that is widely used in web
development. It is a client-side scripting language, which means
that it is executed on the client side (in a web browser) rather than
on the server side. JavaScript is used to create interactive web
pages and is an essential component of modern web development.
It is a high-level, dynamically typed language that is interpreted,
which means that it is not compiled into machine code before it is
run. JavaScript is used to add functionality to websites, such as
handling user events (such as clicks and form submissions),
animating page elements, and making asynchronous requests to
servers. It is a versatile language that can be used for a wide
range of applications, from simple scripts that add simple
interactivity to websites to complex single-page applications.
On page script:
<script src="filename.js"></script>
2|Page
Delay - 1 second timeout:
setTimeout(function () {
}, 1000);
Functions:
function addNumbers(a, b) {
return a + b; ;
x = addNumbers(1, 2);
Output:
3|Page
Comments:
Variables:
var v; // variable
var b = "CodeHelp"; // string
Strict mode:
4|Page
Values:
Basic Operators:
a = b + c - d; // Addition, Subtraction.
a = b * (c / d); // Multiplication, Division.
x = 10 % 4; // Modulo, 10 / 4 Remainder = 2.
Bitwise Operators:
5|Page
Arithmetic Operators:
x * (y + z) // grouping
x=4 // assignment
x == y // equals
x != y // unequal
x += y // x = x + y
x || y // logical OR
x != y // not equal
typeof x // type of x
6|Page
Objects:
lastName: "Sadhu",
age: 20,
height: 175,
};
Strings:
var a = "Codehelp";
var b = 'I don\'t \n know'; // \n new line.
a.slice(3, 6); // cut out "ehe", negative values count from behind.
7|Page
Numbers and Math:
var pi = 3.14;
pi.toFixed(0); // returns 3
Number.POSITIVE_INFINITY // Infinity
Math.round(4.5); // 5
Math.ceil(3.14); // 4 - rounded up
Math.sin(0); // 0 - sine
Math.exp(1); // 2.7182pow(E,x)
8|Page
Array:
for (var i = 0; i < flowers.length; i++) { // Accessing array element using loop.
console.log(flowers[i]);
Array Methods:
9|Page
Regular Expressions:
var a = str.search(/CheatSheet/i);
Modifiers:
Patterns:
• \ Escape character
• \d find a digit
• \s find a whitespace character
• \b find match at beginning or end of a word
• n+ contains at least one n
• n* contains zero or more occurrences of n
• n? contains zero or one occurrences of n
• ^ Start of string
• $ End of string
• \uxxxx find the Unicode character
• . Any single character
• (x | y) x or y
• ( ... ) Group section
• [xyz] In range (x, y or z)
• [0-9] any of the digits between the brackets
• [^xyz] Not in range
• \s White space
10 | P a g e
• a? Zero or one of a
• a* Zero or more of a
• a*? Zero or more, ungreedy
• a+ One or more of a
• a+? One or more, ungreedy
• a{2} Exactly 2 of a
• a{2,} 2 or more of a
• a{,10} Up to 10 of a
• a{1,6} 1 to 6 of a
• a{4,6}? 4 to 6 of a
• [:punct:] Any punctuation symbol
• [:space:] Any space character
• [:blank:] Space or tab
If–Else Statements:
11 | P a g e
Switch Statement:
text = "Monday";
break;
case 2: // if (day == 2)
text = "Tuesday";
break;
case 3: // if (day == 3)
text = "Wednesday";
break;
case 4: // if (day == 4)
text = "Thursday";
break;
case 5: // if (day == 5)
text = "Friday";
break;
case 6: // if (day == 6)
text = "Saturday";
break;
case 7: // if (day == 7)
text = "Sunday";
break;
default: // else....
12 | P a g e
For Loop:
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum + = a[i];
html = "";
While Loop:
var i = 1; // initialize
while (i < 20) { // enters the cycle if statement is true
13 | P a g e
Do While Loop:
var i = 1; // initialize
do { // enters loop at least once
Break Statement:
if (i == 10) {
Continue Statement:
continue; // skips
14 | P a g e
Dates:
15 | P a g e
Global Functions:
Events:
• Mouse Events:
o onclick
o oncontextmenu
o ondblclick
o onmousedown
o onmouseenter
o onmouseleave
o onmousemove
o onmouseover
o onmouseout
o onmouseup
16 | P a g e
• Keyboard Events:
o onkeydown
o onkeypress
o onkeyup
• Frame Events:
o onabort
o onbeforeunload
o onerror
o onhashchange
o onload
o onpageshow
o onpagehide
o onresize,
o onscroll
o onunload
• Form Events:
o onblur
o onchange
o onfocus
o onfocusin
o onfocusout
o oninput
o oninvalid
o onreset
o onsearch
o onselect
o onsubmit
17 | P a g e
• Drag Events:
o ondrag
o ondragend
o ondragenter
o ondragleave
o ondragover
o ondragstart
o ondrop
• Clipboard Events:
o oncopy
o oncut
o onpaste
• Media Events:
o onabort
o oncanplay
o oncanplaythrough
o ondurationchange
o onended
o onerror
o onloadeddata
o onloadedmetadata
o onloadstart
o onpause
o onplay
o onplaying
o onprogress
o onratechange
o onseeked
o onseeking
o onstalled
o onsuspend
18 | P a g e
o ontimeupdate
o onvolumechange
o onwaiting
• Animation Events:
o Animationend
o Animationiteration
o Animationstart
• Miscellaneous Events:
o transitioned
o onmessage
o onmousewheel
o ononline
o onoffline
o onpopstate
o onshow
o onstorage
o ontoggle
o onwheel
o ontouchcancel
o ontouchmove
Errors:
19 | P a g e
Throw error:
Input validation:
try {
x = Number(x);
} finally {
Error Names:
• RangeError: A number is "out of range".
• ReferenceError: An illegal reference has occurred.
• SyntaxError: A syntax error has occurred.
• TypeError: A type error has occurred.
• URIError: An encodeURI() error has occurred.
20 | P a g e
JSON: JavaScript Object Notation
'{"first":"Pranay","lastN":"Gupta" },' +
'{"first":"Shuvam","last":"Chodhury" }]}';
obj = JSON.parse(str);
console.log(obj.names[1].first);
// Send:
localStorage.setItem("testJSON", myJSON);
document.write(obj.name);
21 | P a g e
Promises:
function sum(a, b) {
resolve(a + b);
}, 1000);
});
myPromise.then((result) => {
})
})
.catch((err) => {
});
22 | P a g e
JavaScript and the DOM
HTML DOM
The DOM is an interface between scripting languages
and a web page’s structure. The browser creates a
Document Object Model or DOM for each webpage it
renders. The DOM allows scripting languages to access
and modify a web page. With the help of DOM,
JavaScript has the ability to create dynamic HTML.
1/5
The Document Object Model
The Document Object Model, or DOM is a
representation of a document (like an HTML page) as a
group of objects. While it is often used to represent
HTML documents, and most web browsers use
JavaScript interfaces to the DOM, it is language
agnostic as a model.
The DOM is tree-like and heirarchical, meaning that
there is a single top-level object, and other objects
descend from it in a branching structure.
2/5
The element.parentNode Property
The .parentNode property of an element can be <div id="parent">
used to return a reference to its direct parent node.
<p id ="first-child">Some child
.parentNode can be used on any node.
In the code block above, we are calling on the text</p>
parentNode of the #first-child element to get a <p id ="second-child">Some more child
reference to the #parent div element.
text</p>
</div>
<script>
const firstChild =
document.getElementById('first-child');
firstChild.parentNode; // reference to
the #parent div
</script>
3/5
The document Object
The document object provides a Javascript const body = document.body;
interface to access the DOM. It can be used for a
variety of purposes including referencing the
<body> element, referencing a specific element
with ID, creating new HTML elements, etc.
The given code block can be used to obtain the
reference to the <body> element using the
document object.
4/5
The element.onclick Property
The element.onclick property can be used to set a let element =
function to run when an element is clicked. For
document.getElementById('addItem');
instance, the given code block will add an <li>
element each time the element with ID addItem is element.onclick = function() {
clicked by the user. let newElement =
document.createElement('li');
document.getElementById('list').appendChi
ld(newElement);
};
5/5
NODE JS
CHEAT SHEET
Running Node.js
For running Node.js:
Command Comments
REPL stands for Read Eval Print Loop. This is the list of steps that happen
when you run the node command and then type some code.
For example, to have some code execute after 5 seconds we can use either
global.setTimeout or just setTimeout . The global keyword is optional.
setTimeout(() => {
console.log('hello');
}, 5000);
// OR...
Built-in Modules
Some modules like fs are built in to Node. These modules contain Node-specific
features.
process - information about the currently running process, e.g. process.argv for
arguments passed in or process.env for environment variables
Creating Modules
We can create our own modules by exporting a function from a file and importing it in
another module.
// In src/fileModule.js
function read(filename) { }
function write(filename, data) { }
module.exports = {
read,
write,
};
// In src/sayHello.js
Some Node modules may instead use the shorthand syntax to export functions.
// In src/fileModule.js
exports.read = function read(filename) { }
exports.write = function write(filename, data) { }
ECMAScript Modules
The imports above use a syntax known as CommonJS (CJS) modules. Node treats
JavaScript code as CommonJS modules by default. More recently, you may have seen
the ECMAScript module (ESM) syntax. This is the syntax that is used by TypeScript.
// In src/fileModule.mjs
function read(filename) { }
function write(filename, data) { }
export {
read,
write,
};
// In src/sayHello.mjs
import { write } from './response.mjs';
write('hello.txt', 'Hello world!');
We tell Node to treat JavaScript code as an ECMAScript module by using the .mjs file
extension. Pick one approach and use it consistently throughout your Node project.
Node.js Packages
Node developers often publicly share packages, that other developers can use to help
solve common problems. A package is a collection of Node modules along with a
package.json file describing the package.
To work with Node packages we use NPM. NPM includes two things:
1. The NPM registry with a massive collection of Node packages for us to use.
We can search the NPM registry for packages at www.npmjs.com. The NPM
tool will by default install packages from this NPM registry.
NPM Commands
Command Comments
npm install Install a package from the NPM registry at www.npmjs.com Equivalent to
<package> npm i <package>
npm install -g
Install a package globally.
<package>
npm update
Update an already installed package Equivalent to npm up <package>
<package>
npm uninstall Uninstall a package from your node_modules/ folder Equivalent to npm un
<package> <package>
package.json
Most Node applications we create include a package.json file, which means our Node
applications are also Node packages.
2. Scripts to automate tasks like starting, testing, and installing the current package.
node_modules
This folder lives next to your package.json file.
When you run npm install the packages listed as dependencies in your package.json
are downloaded from the NPM registry and put in the node_modules folder.
It contains not just your direct dependencies, but also the dependencies of those
dependencies. The entire dependency tree lives in node_modules.
package-lock.json
The package-lock.json file is automatically created by NPM to track the exact versions
of packages that are installed in your node_modules folder. Share your package-
lock.json with other developers on your team to ensure that everyone is running the
exact same versions of every package in the dependency tree.
celebrity.on('success', () => {
console.log('Congratulations! You are the best!');
});
Many features of Node are modelled with the EventEmitter class. Some examples
include the currently running Node process , a running HTTP server, and web sockets.
They all emit events that can then be listened for using a listener function like on() .
Backend Concepts
Client-server architecture
Your frontend is usually the client. Your backend is usually the server.
In a client-server architecture, clients get access to data (or "resources") from the
server. The client can then display and interact with this data.
The client and server communicate with each other using the HTTP protocol.
API
This is the set of functions or operations that your backend server supports. The
frontend interacts with the backend by using only these operations.
On the web, backend APIs are commonly defined by a list of URLs, corresponding
HTTP methods, and any queries and parameters.
CRUD
These are the basic operations that every API supports on collections of data. Your
API will usually save (or "persist") these collections of data in a database.
RESTful
RESTful APIs are those that follow certain constraints. These include:
Client-server architecture. Clients get access to resources from the server using
the HTTP protocol.
CRUD
HTTP method Example
Operation
Create POST POST /cards Save a new card to the cards collection
Express.js
GET Routes
POST Routes
Routers
// In src/cards.router.js
const cardsRouter = express.Router();
// In src/api.js
const cardsRouter = require('./cards.router');
api.use('/cards', cardsRouter);
This is just a reference. In the real world, every project will have differences in the
requirements and the ideal project structure.
Browsers follow the Same Origin Policy (SOP), which prevents requests being made
across different origins. This is designed to stop malicious servers from stealing
information that doesn't belong to them.
Cross Origin Resource Sharing (CORS) allows us to allow or whitelist other origins
that we trust, so that we can make requests to servers that don't belong to us. For
example, with CORS set up properly, https://www.mydomain.com could make a POST
request to https://www.yourdomain.com
pm2 .
Command Comments
pm2 start
Start server.js in cluster mode with 4 processes.
server.js -i 4
pm2 start Start server.js in cluster mode with the maximum number of processes to take full
server.js -i 0 advantage of your CPU.
pm2 logs —
Show older logs up to 200 lines long.
lines 200
pm2 monit Display a real-time dashboard in your terminal with statistics for all processes.
pm2 delete 0 Remove process with ID 0 from PM2's list of managed processes.
pm2 delete
Remove all processes from PM2's list.
all
pm2 reload Zero downtime reload of all processes managed by PM2. For updating and
all reloading server code already running in production.
EXPRESS
Express.js is a popular open-source web application framework for
Node.js, a JavaScript runtime that allows developers to build
scalable, high-performance server-side applications. It provides a
wide range of features and utilities for web application
development, such as routing, middleware, and template
rendering.
2|Page
INSTALLATION
BASIC ROUTING:
// GET
app.get('/', function (req, res) {
res.send('Hello World!')
})
// POST
app.post('/', function (req, res) {
res.send('POST request. body:', req.body)
})
// DELETE
app.delete('/:id', function (req, res) {
res.send('DELETE request for id:'. req.params.id)
})
3|Page
STATIC FILE SERVING:
app.use(express.static(__dirname + '/public'));
app._router.stack.forEach(function(r) {
if (r.route && r.route.path) {
console.log(r.route.path)
}
});
4|Page
ADDING ROUTES FROM: /routes/users.js
app.use('/user', require('./routes/user'));
REDIRECTS:
5|Page
React
CheatSheet
In this Cheatsheet, we will cover the basics of React. We will
provide examples to help you understand how React works and
how to use them in your own web development projects. Whether
you are a beginner or an experienced developer, this PDF can
serve as a useful reference guide.
REACT
React is a JavaScript library for building user interfaces. It was
developed and is maintained by Facebook and a community of
individual developers and companies. React allows developers to
build reusable UI components, manage the state of their
applications, and render dynamic updates efficiently.
2|Page
MANAGE STATE
useState
• Class way
const initialCount = 0;
class Counter extends Component {
constructor(props) {
super(props);
this.state = { count : initialCount };
}
render() {
return (
<div>
<p>You clicked {this.state.count} times</p>
<button
onClick = {() => this.setState(({count}) => ({ count: count + 1 }))}
>
Click me
</button>
</div>
);
}
}
3|Page
• Hook Way
useReducer
4|Page
const initialState = {count: 0};
function reducer(state, action) {
switch (action.type) {
case 'increment':
return {count: state.count + 1};
case 'decrement':
return {count: state.count - 1};
default:
throw new Error();
}
}
function Counter({initialState}) {
const [state, dispatch] = useReducer(reducer, initialState);
return (
<>
Count: {state.count}
<button onClick = {() => dispatch({type: 'increment'})}>+</button>
<button onClick = {() => dispatch({type: 'decrement'})}>+</button>
</>
);
}
useEffect(() => {
applyEffect(dependencies);
return () => cleanupEffect();
}, [dependencies]);
5|Page
• Class way
6|Page
• Hook Way
useLayoutEffect
useLayoutEffect(() => {
applyBlockingEffect(dependencies);
return cleanupEffect();
}, [dependencies]);
7|Page
useLayoutEffect is almost same as useEffect, but fires
synchronously after the render phase. Use this to safely read from
or write to the DOM
8|Page
USE THE CONTEXT API
useContext
• Class way
9|Page
• Hook Way
return ...
}
MEMOIZE EVERYTHING
useMemo
10 | P a g e
function RandomColoredLetter(props) {
const [color, setColor] = useState('#fff')
const [letter, setLetter] = useState('a')
const handleColorChange = useMemo(() => () =>
setColor(randomColor()), []);
const handleLetterChange = useMemo(() => () =>
setLetter(randomColor()), []);
return (
<div>
<ColorPicker handleChange={handleColorChange} color={color} />
<LetterPicker handleChange={handleLetterChange} letter={letter} />
<hr/>
<h1 style={{color}}>{letter}</h1>
</div>
)
}
useCallback
function RandomColoredLetter(props) {
const [color, setColor] = useState('#fff')
const [letter, setLetter] = useState('a')
const handleColorChange = useCallback(() => setColor(randomColor()), []);
const handleLetterChange = useCallback(() => setLetter(randomColor()), []);
return (
<div>
<ColorPicker handleChange={handleColorChange} color={color} />
<LetterPicker handleChange={handleLetterChange} letter={letter} />
<hr/>
<h1 style={{color}}>{letter}</h1>
</div>
)
}
11 | P a g e
USE REFS
useRef
But it also allows you to just hold a mutable value through any
render. Also, mutating the value of ref.current will not cause any
render.
useImperativeHandle
useImperativeHandle (
ref,
createHandle,
[dependencies]
)
12 | P a g e
useImperativeHandle allows you to customize the exposed interface
of a component when using a ref. The following component will
automatically focus the child input when mounted :
13 | P a g e
REUSABILITY
Extract reusable behaviour into custom hooks.
14 | P a g e
APIs
CheatSheet
In this Cheatsheet, we will cover the basics of API. We will provide
examples to help you understand how API’s work and how to use
them in your own web development projects. Whether you are a
beginner or an experienced developer, this PDF can serve as a
useful reference guide.
API
An API, or Application Programming Interface, is a set of rules and
protocols for building and interacting with software applications.
It allows different software systems to communicate with each
other, enabling them to share data and functionality. This allows
developers to access the functionality of a certain software
application or system without having to understand its underlying
code or implementation.
An example of an API is the Facebook API, which allows
developers to access and interact with the functionality of the
Facebook platform, such as posting status updates, retrieving
user information, and managing ad campaigns. Another example
is the Google Maps API, which allows developers to embed maps
and location-based functionality in their own websites and apps.
2|Page
The server responds with the requested data, which the API then
forwards to the initial requesting application. This process of
requests and responses all happens through the API. Unlike user
interfaces which are designed for human use, APIs are designed
for use by computers or applications.
3|Page
A request generally consists:
• An HTTP verb, which defines what kind of operation to
perform.
• A header, which allows the client to pass along information
about the request.
• A path to a resource.
• An optional message body containing data.
CRUD stands for Create, Read, Update, and Delete, which are the
four basic operations that can be performed on data in a
database. These operations are often used to interact with
databases through APIs (Application Programming Interfaces).
HTTP Verbs
5|Page
• PUT vs PATCH: PUT method uses the request URI to supply a
modified version of the requested resource which replaces
the original version of the resource, whereas the PATCH
method supplies a set of instructions to modify the resource.
These verbs are part of the HTTP protocol, and are commonly used
in RESTful (Representational State Transfer) APIs, which are built
on top of the HTTP protocol and are designed to be easily
consumed by web and mobile applications.
6|Page
HTTP Status Codes
Standard Classes:
• 100: Continue.
• 101: Switching Protocols.
• 102: Processing.
• 103: Early Hints.
7|Page
2xx: Successful responses
It indicates that the action requested by the client was received,
understood, and accepted.
• 200: OK.
• 201: Created.
• 202: Accepted.
• 203: Non-Authoritative Information.
• 204: No Content.
8|Page
4xx: Client error responses
This status code is intended for situations in which the error seems
to have been caused by the client.
These are just a few examples of the many HTTP status codes that
can be returned by an API. It's important to understand the
meaning of each code and to handle them appropriately in the
client application. The HTTP status codes are standardized and are
used as a way for the server to communicate with the client about
the outcome of a request.
9|Page
mongo DB
CheatSheet
In this Cheatsheet, we will cover the basics of mongo DB. We will
provide examples to help you understand how mongo DB work
and how to use them in your own web development projects.
Whether you are a beginner or an experienced developer, this PDF
can serve as a useful reference guide.
2|Page
ATOMIC/UPDATE OPERATOR
MongoDB COMMANDS
mongod
mongo
show dbs
3|Page
• To create a new database:
use students
db
db.dropDatbase()
show collections
show collections
db.createCollection('studentData')
• To delete a collection:
db.studentData.drop()
4|Page
• For inserting only one document into the collections (same
work as “ .insert() “):
db.studentData.insertOne({
name : "Travour",
email : "[email protected]",
age : 24
})
db.studentData.insertMany([
{name : "Harry", email : "[email protected]", age : 13},
{name : "Ronit", email : "[email protected]", age : 45},
{name : "Adesh", email : "[email protected]", age : 18}
])
db.studentData.find()
db.studentData.find().pretty()
db.studentData.find().limit(3).pretty()
5|Page
• For counting the number of document present in the
collections:
db.studentData.find().count()
db.studentData.find().sort({age : 1})
db.studentData.find().sort({age : -1})
db.studentData.find().limit(2).sort({age : -1}).pretty()
db.studentData.findOne({age : 18})
6|Page
• For updating a data based upon certain condition or filter:
(This will change the documents and fields without changing the previous state of
the document)
db.studentData.updateMany(
{age : {$lt : 19}} ,
{
$inc : {courseCount : -1},
$set {hobby : ["Painting", "Football"]}
})
7|Page
• To append new data to the array type field:
db.studentData.updateMany(
{age : {$lt : 19}} ,
{
$push : {hobby : "Swimming"}
})
db.studentData.deleteOne({age : 17})
db.studentData.deleteOne({}})
db.studentData.deleteMany({fblogged : "Yes"})
db.studentData.deleteMany({})
8|Page
• Converting the group of data into an Array:
db.studentData.findOne({name : "Adesh"}).email
db.studentData.findOne({name : "Adesh"}).age
db.studentData.findOne({name : "Adesh"}).hobby[1]
db.studentData.find(_id : studentid)
db.studentData.findOne(_id : studentid).email
db.studentData.find().forEach((student) =>
{printjson(student.email)})
9|Page
Git
GitHub CheatSheet
GIT
Git is a version control system that is used for tracking
changes in computer files and coordinating work on those
files among multiple people. It is a distributed version
control system, which means that it allows multiple users to
work on the same files simultaneously and keeps track of
changes made to the files by each user. Git is widely used
in software development and has become a standard tool
for collaborating on code.
git init
initialize an existing directory as a Git repository.
git status
show modified files in working directory, staged for your next
commit.
3|Page
git add [file]
add a file as it looks now to your next commit (stage).
git diff
diff of what is changed but not staged.
git branch
list your branches, a* will appear next to the currently active
branch.
git checkout
switch to another branch and check it out into your working
directory.
git log
show all commits in the current branch’s history.
4|Page
INSPECT & COMPARE
Examining logs, diffs and object information.
git log
show the commit history for the currently active branch.
git rm [file]
delete the file from project and stage the removal for commit.
5|Page
IGNORING PATTERNS
Preventing unintentional staging or committing of files.
logs/
*.notes
pattern*/
Save a file with desired patterns as .gitignore with either direct
string matches or wildcard globs.
git pull
fetch and merge any commits from the tracking remote branch.
6|Page
REWRITE HISTORY
Rewriting branches, updating commits and clearing history.
TEMPORARY COMMITS
Temporarily store modified, tracked files in order to change
branches.
git stash
Save modified and staged changes.
7|Page