HTML Basics for Front End Development
HTML Basics for Front End Development
b. Module 2:
Getting Started with html
i. Video 1:
The content focuses on the basics of HTML and its role in web development.
Understanding HTML
HTML (Hypertext Markup Language) is the foundational structure of web pages, similar to the
frame of a building.
It consists of elements and tags, with HTML files typically having a .html suffix.
Each HTML element has an opening tag and often a closing tag, which define the content within.
Elements can be nested, and some can be self-closing, like the line break tag(<br>).
HTML Standards
The HTML specification, maintained by the World Wide Web Consortium (W3C), outlines the rules
for HTML elements and tags.
The current version is HTML5, which standardizes how browsers interpret HTML documents to
display web pages.
ii. Video 2:
This video lecture focuses on the fundamental structure of an HTML document and guides you through
creating a simple webpage for a restaurant called Little Lemon.
The video explains that HTML documents can be viewed locally in a web browser without needing
to be hosted on a server.
It introduces the standard HTML structure, starting with the DOCTYPE declaration, followed by the
HTML root element, which contains the head and body elements.
The head element contains metadata about the document, such as the title displayed in the browser
tab and links to CSS files.
The body element holds the content of the webpage, including headings, paragraphs, images, and
videos.
The instructor demonstrates adding a main heading using the H1 tag and subheadings for menu items
using the H2 tag.
The video concludes with instructions on saving the HTML file and viewing it in a web browser,
encouraging practice with basic HTML tags.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Little Lemon - Our Menu</title>
</head>
<body>
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Chickpea, herbs, and spices.</p>
<h2>Pasta Salad</h2>
<p>Lettuce, vegetables, and mozzarella.</p>
</body>
</html>
Lists
You can add lists to your web pages. There are two types of lists in HTML.
Lists can be unordered using the <ul> tag. List items are specified using the <li> tag, for example:
<ul>
<li>Tea</li>
<li>Sugar</li>
<li>Milk</li>
</ul>
Lists can also be ordered using the <ol> tag. Again, list items are specified using the <li> tag.
<ol>
<li>Rocky</li>
<li>Rocky II</li>
<li>Rocky III</li>
</ol>
Div tags
A <div> tag defines a content division in a HTML document. It acts as a generic container and has no
effect on the content unless it is styled by CSS.
The following example shows a <div> element that contains a paragraph element:
<div>
<p>This is a paragraph inside a div</p>
</div>
As mentioned, the div has no impact on content unless it is styled by CSS. Let’s add a small CSS rule that
styles all divs on the page.
Don't worry about the meaning of the CSS just yet, you'll explore CSS further in a later lesson. In
summary, you're applying a rule that adds a border and some visual spacing to the element.
<style>
div {
border: 1px solid black;
padding: 2px;
}
</style>
<div>
<div>
<p>This is a paragraph inside stylized divs</p>
</div>
</div>
Div elements are an important part of building webpages. More advanced usage of div elements will be
explored in another course.
Comments
If you want to leave a comment in the code for other developers, it can be added as:
iii. Video 3
The course content focuses on how to create a website by linking multiple web pages together using
HTML.
The anchor tag (<a>) is used to create hyperlinks between web pages.
The href attribute specifies the file name to link to, allowing navigation from one page to another.
After saving changes, the [Link] file is opened in a web browser to test the link.
Clicking the link successfully opens the [Link] file, demonstrating the connection between
the pages.
Here are two examples illustrating how to link web pages using HTML:
2. <!DOCTYPE html>
3. <html>
4. <head>
5. <title>Our Location</title>
6. </head>
7. <body>
8. <h1>Our Location</h1>
10. </body>
</html>
11. In your main file ([Link]), add a link to the location page:
13. <html>
14. <head>
16. </head>
17. <body>
18. <h1>Welcome to Little Lemon</h1>
21. </body>
</html>
2. <!DOCTYPE html>
3. <html>
4. <head>
5. <title>Menu</title>
6. </head>
7. <body>
8. <h1>Menu</h1>
10. </body>
</html>
11. In your main file ([Link]), add a link to the menu page:
These examples show how to create separate HTML files and link them together using anchor tags,
allowing users to navigate between different pages of your website.
iv. Video 4:
In this course content, you will learn how to effectively add images to HTML documents using the image
tag.
The image tag (IMG) is used to link to image files, creating a placeholder for images on a web
page.
The source (src) attribute specifies the path to the image file, such as "[Link]" and
"[Link]".
Setting Image Dimensions
You can control the size of images by adding width and height attributes directly in the image tag.
For example, setting width to 240 pixels and height to 135 pixels ensures images are displayed at
the desired size.
Including a short description for images using the alternative text (alt) attribute is essential for
accessibility.
This text is not visible on the site but is read by assistive technologies, enhancing user experience
for those with disabilities.
By mastering these concepts, you can enhance the visual appeal and accessibility of your web pages.
Here are two examples of how to use the image tag in HTML:
These examples demonstrate how to properly include images in your HTML documents while ensuring
they are accessible.
v. Video 5:
The content focuses on how to create and style an HTML table to display prices for a website.
Populate the first row with a dish name (e.g., Falafel) and its price (e.g., $10).
Repeat for additional rows, such as Pasta Salad with its price.
Apply simple CSS by adding a border to the table for visual clarity.
Future lessons will cover more advanced styling techniques.
Here are two examples of how to create an HTML table for displaying prices:
<table>
<tr>
<th>Dish</th>
<th>Price</th>
</tr>
<tr>
<td>Falafel</td>
<td>$10</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$12</td>
</tr>
</table>
<table>
<tr>
<th>Dish</th>
<th>Price</th>
</tr>
<tr>
<td>Falafel</td>
<td>$10</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$12</td>
</tr>
<tr>
<td>Grilled Chicken</td>
<td>$15</td>
</tr>
<tr>
<td>$11</td>
</tr>
</table>
Here’s an example of how to style an HTML table using CSS to add borders and improve its appearance:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
table {
width: 50%;
th, td {
th {
</style>
</head>
<body>
<table>
<tr>
<th>Dish</th>
<th>Price</th>
</tr>
<tr>
<td>Falafel</td>
<td>$10</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$12</td>
</tr>
<tr>
<td>Grilled Chicken</td>
<td>$15</td>
</tr>
<tr>
<td>$11</td>
</tr>
</table>
</body>
</html>
border-collapse: collapse;: Merges the borders of adjacent cells into a single border.
border: 1px solid #000;: Adds a solid black border around each cell.
padding: 10px;: Provides space inside each cell for better readability.
background-color: #f2f2f2;: Sets a light gray background for the header cells.
This example creates a visually appealing table with clear lines and spacing, making it easy to read. You
can adjust the styles as needed!
vi. Video 6:
This course item focuses on the creation and functionality of HTML forms, which are essential for user
interaction on websites.
HTML forms allow users to input data, such as credit card details during online shopping.
Forms are defined using the <form> tag, with an optional action attribute to specify where to
send the data.
Input fields are created using the <input> tag, with various types like text, password, checkbox,
and radio buttons.
Labels can be added using the <label> tag to enhance user experience.
Additional Input Elements
For multi-line text, the <textarea> tag is used, and for dropdown lists, the <select> tag
with <option> tags is utilized.
Different input types cater to various user needs, improving form usability.
Here are two examples of HTML forms that illustrate different input types:
<label for="username">Username:</label>
<label for="password">Password:</label>
</form>
<label for="email">Email:</label>
<label for="gender">Gender:</label>
<label for="male">Male</label>
<label for="female">Female</label>
<input type="submit" value="Register">
</form>
vii. Video 7:
The content focuses on the Document Object Model (DOM) and its role in web development.
The DOM is a tree structure that represents the objects in an HTML document, allowing
JavaScript to interact with and manipulate web pages.
Each HTML element is represented as an object in the DOM, starting from the root html object,
which contains head and body objects.
JavaScript can access and modify HTML attributes and content, enabling dynamic updates to
web pages, such as changing a digital clock or responding to user actions.
Developers can add, delete, or animate DOM objects, enhancing user experience on websites.
Common uses include updating content, responding to user interactions (like clicks), and
animating elements for visual effects.
Libraries like React rely on the DOM to create interactive user experiences, showcasing its
importance in modern web development.
viii. Video 8:
The content focuses on the importance of web accessibility in web development, emphasizing the need
for inclusive design.
Web accessibility ensures that everyone, including individuals with disabilities, can access and
interact with websites.
It encompasses various disabilities, including visual, auditory, cognitive, and physical
impairments.
Assistive Technologies
Assistive technologies like screen readers and speech recognition software help users with
disabilities navigate the web.
Subtitles and video scripts support those with audio and visual disabilities.
CSS Basics
i. Video 1:
🚀 How to use:
1. Install the Live Server extension from the VS Code Extensions tab.
2. Open your HTML file.
3. Right-click and choose "Open with Live Server" or click “Go Live” at the bottom-right of VS
Code.
4. Your page will open in the browser (e.g., [Link]
5. Edit and save to see changes instantly.
Shows a preview of your webpage directly inside VS Code (no external browser).
Updates in real time inside the editor.
Does not use a full development server like Live Server.
Great for quick edits or learning HTML/CSS.
📌 Use Cases:
🚀 How to use:
Understanding CSS
CSS is compared to the paint and decorations of a building, while HTML is the structure. CSS
controls how HTML elements are displayed in a web browser.
A CSS rule consists of a selector, which targets HTML elements, and a declaration block that
contains property-value pairs.
The selector specifies which HTML elements to style, such as changing the color of all <h1> tags.
Each declaration in the block includes a property (like color) and a value (like blue), which defines
how the selected elements appear.
To apply CSS, a stylesheet (e.g., [Link]) must be linked in the HTML file's head section using
the <link> tag.
Specificity rules dictate which CSS rules apply when multiple rules target the same element, with
ID selectors taking precedence over type selectors.
Practical Application
The content encourages practicing CSS by creating and styling HTML documents, emphasizing
the importance of understanding selectors and declaration blocks.
Here are two examples of CSS styling for HTML elements:
Example 1: Styling All <h1> Elements
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example 1</title>
</head>
<body>
<h1>Welcome to My Website</h1>
</body>
</html>
[Link]
h1 {
}
Result: All <h1> elements will display blue text on a light gray background.
Example 2: Styling a Specific <h1> Element with an ID
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example 2</title>
</head>
<body>
</body>
</html>
[Link]
#header-one {
}
Result: The <h1> element with the ID "header-one" will display green text, overriding the
general <h1> styling if it exists.
In CSS, a selector and a declaration are key components of a CSS rule. Here’s a brief explanation of
each:
Selector
The selector specifies which HTML element(s) you want to style. It can target elements by their
type, class, ID, or other attributes.
Example: In the rule #header-one { ... }, #header-one is the selector that targets the HTML
element with the ID "header-one".
Declaration
The declaration consists of one or more property-value pairs that define the styles to be applied
to the selected element(s).
Each declaration is enclosed in curly braces {} and ends with a semicolon ;.
Example: In the rule #header-one { color: green; font-size: 24px; }, color: green; and font-size:
24px; are declarations. Here, color and font-size are properties, and green and 24px are their
respective values.
Complete Example
#header-one {
In this example:
Selector: #header-one
Declarations:
o color: green;
o font-size: 24px;
</div>
<h1>Archives</h1>
<div>
</div>
<p>Subscribe for more news</p>
</div>
<p>The weather will be sunny</p>
<h1>Today's Weather</h1>
<h1>Latest News</h1>
<div>
<div id="blog">
CSS
#blog h1 {
color: blue;
}
The CSS rule will select all h1 elements that are contained within the element with the ID blog.
The CSS rule will not apply to the h1 element containing the text Archives.
The structure of a descendant selector is a CSS selector, followed by a single space character,
followed by another CSS selector.
Multiple descendants can also be selected. For example, to select all h1 elements that are
descendants of div elements which are descendants of the blog element, the selector is
specified as follows.
CSS
#blog div h1 {
color: blue;
}
Child Selectors
Child selectors are more specific than descendant selectors. They only select elements that are
immediate descendants (children) of a selector (the parent).
For example, you have the following HTML structure:
HTML
<div id="blog">
<h1>Latest News</h1>
<div>
<h1>Today's Weather</h1>
<p>The weather will be sunny</p>
</div>
<p>Subscribe for more news</p>
</div>
If you wanted to style the h1 element containing the text Latest News, you can use the
following child selector:
CSS
#blog > h1 {
color: blue;
}
This will select the element with the ID blog (the parent), then it will select all h1 elements that
are contained directly in that element (the children). The structure of the child selector is a CSS
selector followed by the child combinator symbol > followed by another CSS selector.
Note that this will not go beyond a single depth level. Therefore, the CSS rule will not be
applied to the h1 element containing the text Today's Weather.
:hover Pseudo-Class
A special keyword called a pseudo-class allows developers to select elements based on their
state. Don't worry too much about what that means right now. For now, let's look at how the
hover pseudo-class allows you to style an element when the mouse cursor hovers over the
element.
The simplest example of this is changing the color of a hyperlink when it is hovered over. To do
this, you add the :hover pseudo-class to the end of the selector. In the following example,
adding :hover to the a element will change the color of the hyperlink to orange when it is
hovered over.
CSS
a:hover {
color: orange;}
This pseudo-class is very useful for creating visual effects based on user interaction.
Other Selectors
There are many other CSS selectors available to style your webpage.
Color
p{
color: blue;
}
From CSS Version 3, there are five main ways to reference a color.
By RGB value,
By RGBA value,
By HSL value,
RGB value
RGB is a color model that adds the colors red (R), green (G) and blue (B) together to create colors. This is
based on how the human eye sees colors.
Each value is defined as a number between 0 and 255, representing the intensity of that color.
For example, the color red would have the RGB value of 255,0,0 since the intensity of the red color
would be 100% while blue and green would be 0%.
The color black then would be 0,0,0 and the color white 255,255,255.
When using RGB values in CSS, they can be defined using the rgb keyword:
p{
color: rgb(255, 0, 0);
}
RGBA value
RGBA is an extension of RGB that add an alpha (A) channel. The alpha channel represents the opacity, or
transparency, of the color.
p{
color: rgba(255, 0, 0, 0.8);
}
HSL value
HSL is a newer color model defined as Hue (H), Saturation (S) and Lightness (L). The aim of the model is
to simplify mental visualization of the color that the value represents.
Think of a rainbow that has been turned into a full circle. This represents the Hue. The Hue value is the
degree value on this circle, from 0 degrees to 360 degrees. 0 is red, 120 is green and 240 is blue.
Saturation is the distance from the center of the circle to its edge. The saturation value is represented by
a percentage from 0% to 100% where 0% is the center of the circle and 100% is its edge. For example, 0%
will mean that the color is more grey and 100% represents the full color.
Lightness is the third element of this color model. Think of it as turning the circle into a 3D cylinder
where the bottom of the cylinder is more black and toward the top is more white. Therefore, lightness is
the distance from the bottom of the cylinder to the top. Again, lightness is represented by a percentage
from 0% to 100% where 0% is the bottom of the cylinder and 100% is its top. In other words, 0% will
mean that the color is more black and 100% is white.
In CSS, you use the hsl keyword to define a color with HSL.
p{
color: hsl(0, 100%, 50%);
}
Hex value
Colors can be specified using a hexadecimal value. If you're unfamiliar with hexadecimal, think of it as a
different number set.
Decimal is what you use every day. Digits range from 0 to 9 before tens and hundreds are used.
In fact, you can convert between decimal and hexadecimal. Decimal 10 is equal to hexadecimal A.
Hexadecimal F is equal to decimal 15.
Hexadecimal can also go to tens and hundreds. For example, decimal 16 is equal to
hexadecimal 10, with 10 being the next number after F.
It can be a little confusing at first but don't worry, there are plenty of converters available if you get
stuck.
Colors specified using hexadecimal are prefixed with a # symbol followed by the RGB value in
hexadecimal format.
For example, the color red which is RGB 255,0,0 would be written as hexadecimal #FF0000.
Again don't worry if you get stuck, there are plenty of converters available for this too!
Modern web browsers support 140 predefined color names. These color names are for convenience
purposes and can be mapped to equivalent hex/RGB/HSL values.
black
silver
gray
white
maroon
red
purple
fuchsia
green
lime
olive
yellow
navy
blue
teal
aqua
Text
With CSS there are many ways to change how text is displayed. In this section, you'll learn the most
common text manipulation CSS properties.
Text Color
The color property sets the color of text. The following CSS sets the text color for all paragraph
elements to red.
p{
color: red;
}
There are many different fonts to display text on your computer. In simple terms, a font is a collection of
text characters written in a specific style and size.
If you've used a word processor before, you're probably familiar with the fonts Times New Roman and
Calibri.
To set the font used by text in CSS you use the font-family property.
p{
font-family: "Courier New", monospace;
}
Since computers vary in what fonts they have installed, it is recommended to include several fonts when
using the font-family property. These are specified in a fallback order, meaning that if the first font is
not available, it will check for the second font. If the second font is not available, then it will check for the
third font and so on. If none of the fonts are available, it will use the browser's default font.
p{
font-family: "Courier New", monospace;
font-size: 12px;
}
Text Transformation
Text transformation is useful if you want to ensure the correct capitalization of the text content. In the
example below, the CSS rule will change all text in paragraph elements to uppercase using the text-
transform property:
p{
text-transform: uppercase;
}
The most commonly used values for the text-transform property are: uppercase, lowercase,
capitalize and none. The default value used is none, which means the text displays as it was
written in the HTML document.
Text Decoration
The text-decoration property is useful to apply additional decoration to text such as underlining
and line-through (strikethrough).
p{
text-decoration: underline;
}
It is possible to set the color, thickness and styling of the decoration too. In the example below, the
underline will be a solid red line that is 5 pixels thick.
p{
text-decoration: underline red solid 5px;
}
If this is confusing, don't worry. These properties can be individually set using the text-decoration-
line, text-decoration-color, text-decoration-style and text-decoration-
thickness properties. Let's use the same example again and define it using the individual properties:
p{
text-decoration-line: underline;
text-decoration-color: red;
text-decoration-style: solid;
text-decoration-thickness: 5px;
}
The most common text-decoration-line values used are: underline, overline, line-
through and none. None is the default value to use no text decoration.
There are many styles available for the text-decoration-style property; solid, double,
dotted, dashed and wavy. The text-decoration-style property requires the decoration line to
be defined. If the decoration style is not specified, solid will be used.
ii. Video 2:
The content focuses on the box model in CSS, which is essential for creating effective web layouts.
The box model consists of four parts: content, padding, border, and margin.
Each part plays a role in determining the size and spacing of elements on a webpage.
Content: This is the actual content of the element (text or images) and its size is defined by
content width and height.
Padding: This extends the content area, with its size calculated by adding the content size and
padding thickness on all sides.
Border: Surrounds the padding and content, with various styles (solid, dashed) and thicknesses
(thin, medium, thick).
Margin: Creates space between elements, calculated by adding the border box size and margin
thickness on all sides.
Practical Application
Understanding how to manipulate these properties is crucial for web development, as they affect
the layout and user experience.
D
Diksha
in detail
Coach
Certainly! Here’s a more detailed breakdown of the box model in CSS, which is crucial for web layout
design:
The box model is a fundamental concept in CSS that describes how elements are structured and
displayed on a webpage. Each element is represented as a rectangular box, and the box model consists
of four main components:
1. Content
This is the actual content of the element, such as text, images, or other media.
o
o The size of the content area is defined by content width and content height.
o Browsers automatically calculate these dimensions based on the content itself, but
developers can control them using CSS properties.
2. Padding
Padding is the space between the content and the border of the box.
o
o It increases the size of the box without affecting the layout of surrounding elements.
o The total size of the padding box can be calculated as:
Padding Box Width = Content Width + Padding Left + Padding Right
Padding Box Height = Content Height + Padding Top + Padding Bottom
o Padding can be set individually for each side (top, right, bottom, left) using properties
like padding-top, padding-right, padding-bottom, and padding-left.
3. Border
Practical Application
CSS Properties: You can manipulate the box model using various CSS properties:
o To set the content size: width, height, min-width, max-width, min-height, max-height.
To set padding: padding, padding-top, padding-right, padding-bottom, padding-left.
o
o To set borders: border, border-width, border-style, border-color.
o To set margins: margin, margin-top, margin-right, margin-bottom, margin-left.
Example:
.box {
}
iii. Video 3:
This content focuses on understanding how CSS and HTML elements are positioned on a webpage
through document flow.
Block and Inline Elements
Block-level elements occupy the full width of their parent and start on a new line, stacking
vertically (e.g., <div>, <form>, <h1>).
Inline elements only take up the width and height of their content, allowing them to flow within
the same line (e.g., <span>, <a>, <img>).
An example shows a <div> containing text and <span> elements, illustrating how they display in
an unbroken flow.
Changing a <span> to a <div> moves the text to a new line, demonstrating the difference in
behavior between block and inline elements.
The display property in CSS can change an element's behavior from block to inline and vice versa.
The example illustrates how to use CSS to modify the display property, affecting the layout of
elements on the page.
Here are two examples illustrating the difference between block and inline elements in HTML and CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.block {
background-color: lightblue;
padding: 10px;
margin: 5px 0;
</style>
</head>
<body>
<div class="block">This is a block element.</div>
</body>
</html>
Explanation: Each <div> starts on a new line and takes the full width of the parent container.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.inline {
background-color: lightgreen;
padding: 5px;
margin: 0 5px;
</style>
</head>
<body>
</body>
</html>
Explanation: The <span> elements appear on the same line, only taking up the space of their content.
Alignment basics
Let's explore how to align text and HTML elements using CSS.
Let's first focus on horizontal alignment. Vertical alignment is more difficult so you'll explore that later
on.
Text Alignment
Aligning text within an HTML element is very simple. To do this, you use the text-align CSS property.
In the following example, the CSS rule is setting the text of all paragraph elements to be center aligned.
p{
text-align: center;
}
The justify alignment spreads the text out so that every line of the text has the same width.
The default alignment is left for languages that are left-to-right such as English. For right-to-left
languages such as Arabic, the default alignment is right.
HTML element alignment is more complicated than text alignment. To align HTML elements, you must
consider the box model and document flow from previous lessons. Aligning an HTML element is done by
changing the properties of its box model and how it impacts the document flow.
To center align an element, you set a width on the element and push its margins out to fill the remaining
available space of the parent element as in the following HTML structure:
<div class="child">
</div>
</div>
In your CSS, you'll set the parent element to have a red border to visualize the space it occupies:
.parent {
border: 4px solid red;
}
The child element will have a width equal to 50% of the parent element with a padding of 20 pixels.
Note that padding: 20px is shorthand for setting the padding top, bottom, left and right to 20px. To
visualize the space it occupies, set the border to green:
.child {
width: 50%;
padding: 20px;
border: 4px solid green;
}
To align the element to the center, set its margin property to auto. The auto will tell the browser to
calculate the margin automatically based on the space available.
.child {
width: 50%;
padding: 20px;
border: 4px solid green;
margin: auto;
}
The result is the child element is centered within the parent element:
It is important to note that this works because the div element is a block-level element.
If you want to align an inline element like img, you will need to change it to a block-level element.
Similar to the div example, you add the img to a parent element:
</div>
<img src="[Link]" class="child">
<div class="parent">
The CSS rule then changes the img element to a block-level element and sets its margin to auto:
.child {
display: block;
width: 50%;
margin: auto;
}
To be more precise, in CSS you can set only the left and right margins to auto. This allows you to set the
top and bottom margins to specific values if needed.
.child {
display: block;
width: 50%;
margin-left: auto;
margin-right: auto;
}
The two most common ways to left and right align elements are to use the float property and
the position property.
The position property has several value options that impact how the element displays in the
document flow. You'll explore how to use the position property later on. For now, let's focus on
the float property.
The float property sets an element's position relative to the text content within a parent element. Text
will wrap around the element.
In the following example, the image will be aligned to the right of the div element. The text content will
wrap around the image:
HTML
<div class="parent">
<img src="[Link]" class="child"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur eu odio e
get leo auctor porta sit amet sit amet justo. Donec fermentum quam in diam volutpat, at lacinia diam placerat. Aen
ean quis feugiat sem. Suspendisse a dui massa. Phasellus scelerisque, mi vestibulum iaculis tristique, orci tellus gr
avida nisi, in pellentesque elit massa ut lorem. Sed elementum ornare nunc vel cursus. Duis sed enim in nulla effici
tur convallis sed eget dolor. Curabitur scelerisque eros erat, in vulputate dolor consequat vel. Praesent ac sapien c
ondimentum, ultricies libero at, auctor orci. Curabitur ut augue ac massa convallis faucibus sed in magna. Phasellu
s scelerisque auctor est a auctor. Nam laoreet sem sapien, porta imperdiet urna laoreet eu. Morbi dolor turpis, con
gue id bibendum eget, viverra et risus. Quisque vitae erat id tortor ullamcorper maximus.
</div>
CSS
.child {
float: right;
}
c. Module 3:
Intro to UI Frameworks and Libraries
i. Video 1:
This content focuses on how to include CSS and JavaScript libraries in HTML files, as well as the
concepts of dependencies, package managers, and bundling tools in front-end development.
Understanding Dependencies
Dependencies are libraries and frameworks that your application relies on to function properly.
Including these dependencies in your HTML file is essential for your application to call necessary
API functions.
To include Bootstrap's CSS, you add a link tag in the head element of your HTML file.
For JavaScript functionality, you add a script tag in the body element, specifying the source of the
Bootstrap library.
Package managers, like npm, automate the downloading and installation of dependencies,
managing complex dependency trees.
They ensure that the correct versions of dependencies are used, simplifying the development
process.
Bundling Tools
Bundling tools combine multiple dependencies into a single file to streamline the inclusion
process in your HTML.
Tools like Gulp and Webpack help manage large projects with numerous dependencies
efficiently.
ii. Video 2:
Responsive Design Overview
Definition: Responsive design is a web development approach that allows web pages to
automatically adjust their layout and content based on the screen size and resolution of the
device being used (e.g., smartphones, tablets, laptops).
Importance: With the increasing variety of devices and screen resolutions, responsive design is
crucial for ensuring that websites provide a consistent and optimal user experience across all
platforms.
1. Flexible Grids:
o Structure: Flexible grids are composed of columns, gutters (the space between columns),
and margins (the space between content and the edges of the screen).
o Percentage Values: Instead of using fixed pixel sizes, flexible grids use percentage values
to define element sizes. This allows the layout to adapt fluidly to different screen widths.
2. Fluid Images:
o CSS Max-Width Property: By setting the max-width property of images to 100%, images
can scale down to fit within their containing columns. This prevents images from
overflowing their containers while ensuring they do not become pixelated when the
container is wider than the image.
Media Queries: These are a feature of CSS that allows developers to apply specific styles based
on the characteristics of the device, such as display size, orientation, and aspect ratio. For
example, a media query can change the background color of a website when viewed on a mobile
device with a screen width of 700 pixels or less.
Breakpoints: A breakpoint is a defined point in the CSS where the layout and content of a
website adapt to provide the best possible user experience. Breakpoints can function differently
across various grid types:
o Fixed Grids: Have fixed-width columns with flexible margins. The content width remains
constant within a specific range of breakpoints.
o Fluid Grids: Feature fluid-width columns that stretch from edge to edge of the screen.
Columns can grow or shrink based on the available space.
o Hybrid Grids: Combine both fluid and fixed-width components, allowing for more
complex layouts.
Bootstrap
Bootstrap is often described as a way to "build fast, responsive sites" and it is a "feature-packed,
powerful, and extensible frontend toolkit".
Some people refer to it as a "front-end" framework, and some are trying to be more specific by referring
to it as a "CSS framework" or a “CSS library”.
Simply put, Bootstrap is a library of CSS and JavaScript code that you can combine to quickly build
visually appealing websites.
Modern web development is all about components. Small pieces of reusable code that allow you to
build websites quickly. Bootstrap comes with multiple components for very fast construction of multiple
components, or parts of components.
Another important aspect of modern development is responsive grids which allow web pages to
adapt their layout and content depending on the device in which they are viewed. Bootstrap comes with
a pre-made set of CSS rules for building a responsive grid.
Bootstrap is very popular amongst developers as it saves development time and provides a way for
developers to build visually appealing prototypes and websites.
Bootstrap saves significant time because all the CSS code that styles its grid and pre-built components is
already written. Instead of needing a high level of expertise in various CSS concepts, you can simply use
the existing Bootstrap CSS classes to create visually appealing websites. This is indispensable when you
need to quickly iterate on website layouts.
Once you know how Bootstrap works, you’ll have enough knowledge to tweak its styling and a whole
new world of development opens up to you.
Since Bootstrap is so popular, understanding how to work with it is a prerequisite in many web
development companies. Additionally, you can be safe in knowing that both you and your team
members have a common design system and you don't have to spend time deciding how to build one.
You are free to jump from team to team, from project to project, even from one company to another, and
you don't need to re-learn "their way of doing things".
All of these points make investing time to learn Bootstrap a great way to boost your web development
skills. In this lesson, you’ll be introduced to the core concepts of Bootstrap and learn how to build web
pages using it.
iii. Video 3:
The content focuses on creating a simple webpage using Bootstrap, a popular front-end framework.
Begin by adding container elements using HTML div and applying the Bootstrap container CSS
class.
Create a row for content with another div element using the row CSS class, and add two columns
for menu items and prices.
Adding Content
Name the columns using heading tags (H1 for the menu and H2 for prices).
Under the menu column, add dish names, ingredients, and images using appropriate HTML tags
(H2 for dish names, p for ingredients, and IMG for images).
Add a price table using the HTML table tag and apply the Bootstrap table CSS class.
Include table rows and data tags to display dish names and their corresponding prices.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
href="[Link]
<title>Menu</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<h2>Pasta Salad</h2>
</div>
<div class="col">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet"
href="[Link]
<title>Restaurant Menu</title>
</head>
<body>
<div class="container">
<h1>Menu</h1>
<div class="row">
<div class="col-md-6">
<h2>Falafel</h2>
</div>
<div class="col-md-6">
<h2>Pasta Salad</h2>
</div>
</div>
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</body>
</html>
In Bootstrap, col-md-6 is a class used to define the width of a column in a grid layout. Here's a
breakdown of what it means:
col: This indicates that the element is a column in the Bootstrap grid system.
md: This specifies the breakpoint at which the column will take effect. In this case, md stands for
"medium" devices, which typically refers to screens that are 768 pixels wide or larger.
6: This number represents the number of columns the element will span. Bootstrap's grid system
is based on a total of 12 columns. Therefore, col-md-6 means that the column will take up 6 out of
the 12 available columns, effectively making it half the width of the container on medium and
larger screens.
Example:
On medium and larger screens, col-md-6 will display the column at 50% width.
On smaller screens, if you don't specify a class for those breakpoints, the column will stack
vertically and take the full width.
The main difference between the basic and responsive examples lies in how they handle layout and
responsiveness across different screen sizes. Here’s a summary of the differences:
Basic Example
Column Structure: Uses col class without specifying a breakpoint, which means the columns will
stack vertically on all screen sizes.
Layout: The layout is fixed and does not adapt to different screen sizes. On smaller screens, the
columns will not be side by side but rather one on top of the other.
Use Case: Suitable for very simple layouts where responsiveness is not a concern.
Responsive Example
Column Structure: Uses col-md-6, which specifies that the columns should take up half the width
(6 out of 12 columns) on medium and larger screens.
Layout: The layout is responsive, meaning that on medium and larger screens, the columns will
be displayed side by side. On smaller screens, they will stack vertically, taking the full width.
Use Case: Ideal for modern web design where adaptability to various screen sizes is important,
enhancing user experience on mobile devices.
Summary
iv. Video 4:
This content focuses on using Bootstrap CSS for responsive web design, particularly for the Little Lemon
Restaurant website.
Bootstrap provides a large library of CSS classes for responsive design, allowing developers to
create adaptable websites without redesigning for each device.
Key concepts include "infixes" for responsive breakpoints, which are specific class abbreviations
(e.g., SM for small screens, MD for medium, LG for large).
Responsive Breakpoints
Breakpoints in Bootstrap are defined as follows:
o Extra small: < 576 pixels (default)
o Small: ≥ 576 pixels (SM)
o Medium: ≥ 768 pixels (MD)
o Large: ≥ 992 pixels (LG)
o Extra large: ≥ 1200 pixels (XL)
o Extra extra large: ≥ 1400 pixels (XXL)
Infixes: These are abbreviations used in class names to specify breakpoints. For example:
o col-md-4: This class will apply to medium screens and larger, creating a column that takes
up 4 out of 12 columns.
Ex:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="[Link]
<title>Menu</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="[Link]
<title>Menu</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Both columns(menu and prices) are in same row as 1st input
Using Modifiers
Modifiers in Bootstrap allow customization of components, such as alerts. For example, "alert-
primary" uses the primary color (blue), while "alert-danger" changes it to red for error messages.
Bootstrap provides various contextual classes for alerts, enabling easy implementation of
different alert types based on color.
For example, in alerts:
o alert-primary: Displays a blue alert.
o alert-secondary: Displays a gray alert.
o alert-success: Displays a green alert.
o alert-info: Displays a light blue alert.
o alert-warning: Displays a yellow alert.
o alert-danger: Displays a red alert.
o alert-light: Displays a light gray alert.
o alert-dark: Displays a dark gray alert.
Here are two examples illustrating the use of Bootstrap CSS classes and modifiers:
In an HTML file, you can create a responsive layout using Bootstrap's grid system. For instance, to create
a six-column layout that adjusts for large screens, you would use:
<div class="col-lg-6">
Explanation: The col-lg-6 class specifies that this column should take up 6 out of 12 columns on
large screens (≥ 992 pixels).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
href="[Link]
<title>Menu</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col-lg-6">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Result of col-lg-6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="[Link]
<title>Menu</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Our Menu</h1>
<h2>Falafel</h2>
<p>Ingredients: Chickpea, herbs, spices</p>
<img src="[Link]" class="img-fluid" alt="Falafel">
<h2>Pasta Salad</h2>
<p>Ingredients: Lettuce, vegetables, mozzarella</p>
<img src="[Link]" class="img-fluid" alt="Pasta Salad">
</div>
<div class="col-lg-3">
<h2>Prices</h2>
<table class="table">
<tr>
<td>Falafel</td>
<td>$12</td>
</tr>
<tr>
<td>Pasta Salad</td>
<td>$10</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Result of col-lg-3
To create an alert message that changes color based on the context, you can use:
</div>
To change it to a danger alert (red for errors), you would modify it to:
</div>
Explanation: The alert-primary class displays the alert in blue, while alert-danger changes it to
red, indicating an error.
v. Video 5:
Here are some key notes on using Bootstrap for responsive web design:
Responsive Design
Column Suffixes: Control column width using suffixes (e.g., col-4, col-8).
Stacking on Mobile: Use col-12 for mobile to stack columns vertically.
Side by Side on Desktop: Use col-lg-6 for desktop to display columns side by side.
Development Efficiency
Responsive CSS Rules: Bootstrap automatically adjusts layouts for different devices.
Web Developer Tools: Use tools to simulate device views and test responsiveness.
vi. Video 6:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="[Link]
rel="stylesheet">
</head>
<body>
<h1>Our Menu</h1>
<div class="row">
<div class="col-12 col-lg-6">
<div class="card">
<div class="card-body">
<table class="table">
<tbody>
<tr>
<td>Price</td>
<td>$12</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="[Link]
<script src="[Link]
<script src="[Link]
</body>
</html>
HTML Tags
1. <h1> and <h2>:
o These are heading tags. <h1> is the main title of the page, while <h2> is used for
subheadings (like dish names). They help structure the content and improve accessibility.
2. <span>:
o This inline element is used to apply styles or classes to a portion of text. In this case, it
wraps the "New" badge to apply Bootstrap's badge styling.
3. <p>:
o The paragraph tag is used to define blocks of text. Here, it lists the ingredients for each
dish.
4. <img>:
o This tag is used to embed images in the webpage. The src attribute specifies the image
file, and alt provides alternative text for accessibility.
5. <div>:
o A generic container used to group elements together. In this example, it is used to create
sections for each dish and to contain the card components.
6. <table>:
o This tag is used to create a table. In the example, it displays the price of each dish in a
structured format.
7. <tbody> and <tr>:
o <tbody> groups the body content of the table, while <tr> defines a table row. Each row
can contain multiple cells.
8. <td>:
o This tag defines a cell in a table row. In the example, it is used to display the price label
and the actual price.
Bootstrap Classes
1. container:
o A Bootstrap class that provides a responsive fixed-width container, centering the content
and adding padding.
2. mt-5:
o This class adds a top margin of 5 units (spacing) to the container, creating space above the
content.
3. row:
o This class is used to create a horizontal group of columns. It helps in organizing the layout
in a grid format.
4. col-12 and col-lg-6:
o These classes define the column width. col-12 means the column will take the full width
on small screens, while col-lg-6 means it will take half the width on large screens.
5. img-fluid:
o This class makes images responsive, ensuring they scale with the parent container's
width.
6. card:
o A Bootstrap component that provides a flexible and extensible content container with
multiple variants and options for styling.
7. card-body:
o This class is used to define the main content area of the card, where text and other
elements are placed.
8. card-title and card-text:
o These classes are used to style the title and text within the card, providing consistent
formatting.
9. alert and alert-info:
o These classes create a styled alert box. alert is the base class, while alert-info applies a
specific color scheme (blue) to indicate informational messages.
[Link]
The sidebar on the webpage allows you to navigate through the different sections of the documentation.
There is also a search box if you need to search for a specific piece of information.
Layout
The layout section of the documentation describes how to use the grid system of Bootstrap. This covers
what you've learned so far and includes more advanced usage such as offsets, column alignment, auto-
layout and variable width columns.
Content
The content section of the documentation describes Bootstrap's default text styling and how to use
responsive images and tables. You've learned the basics of these earlier on and this section goes into
further detail.
Forms
The forms section of the documentation describes how to build forms using Bootstrap's styles. The
library has many CSS rules to improve your form's user interface and experience. Below are some
features you'll frequently use as a developer:
Form Styling
Bootstrap includes CSS rules to improve the visual style of input elements.
For example:
This table outlines the different HTML form elements and which Bootstrap CSS class should be used for
them.
input form-control
select form-select
Using these CSS classes will style the elements appropriately for different input types, sizings and states.
More information is available on the Forms documentation page.
Switches
If you've used an app on your mobile device, you're probably familiar with the switch input type.
To do this:
Input Groups
Input groups are useful for providing additional content to the input field. For example, if you wanted to
request the user to input a US dollar amount, you can use an input group to show the dollar symbol and
cents amount.
To do this:
Floating Labels
Floating labels help provide form information to the user as part of the input itself. These are different
from regular form placeholders. The information stays visible if the user is interacting with the element
or if the element has content.
To do this, add the input to a div element. On the div element, apply the form-floating CSS
classes.
1
2
3
4
<div class="form-floating">
<input type="email" class="form-control" id="addressInput" placeholder="Address">
<label for="addressInput">Address</label>
</div>
More information is available on the Floating Labels documentation page
Components
As you have learned, Bootstrap comes with many pre-made UI elements and styles to help speed up your
development.
Some of these components require Javascript to work, while others only require CSS classes applied to
HTML elements. The Components section of the documentation explains these requirements on each
component page and provides many code examples.
Foundation
Official Website
Foundation is a framework for building user interfaces similar to Bootstrap. It is used by many large
companies such as Pixar, Polar and Sonos. One prominent feature of Foundation is that it can be used to
style content for sending via email.
[Link]
Official Website
[Link] is another library for building user interfaces. While it doesn't have as many features as
Bootstrap, it is designed to be minimal in file size. Smaller file sizes improve loading times for web pages
as there is less data to transfer from the web server. If your next project is focused on minimal loading
time, this library is worth considering.
Tailwind CSS
Official Website
Tailwind CSS is a CSS framework that uses a utility-based approach for its CSS rules. This means that the
framework provides many CSS classes with a single purpose. For example, the CSS class pt-6 sets the
padding-top CSS property to 6 pixels. This means that you can be precise in applying styling to your
HTML without writing CSS. The advantage to this is that it is more flexible for customizing your
webpage's design using the framework. However, the disadvantage is that if multiple developers are
working on a project, it could lead to inconsistent design if the team is not strict on its design rules.
UIKit
Official Website
UIKit is a lightweight CSS framework featuring a small set of responsive components. Its simple design
allows developers to easily customize the style rules and visuals.
[Link]
Official Website
[Link] is a small CSS library that automatically styles HTML elements without needing to apply CSS
classes to them. The library aims to allow a developer to quickly prototype a user interface without
worrying about the final design, while still being visually appealing. MVP comes from the technical term
Minimal Viable Product, a product with sufficient features to demo to customers or other business
stakeholders.
Introduction to React
i. Video 1:
This content explains the differences between static and dynamic content on websites, as well as the
roles of web servers and application servers.
Static content consists of files that are sent to the browser exactly as they are stored on the
server, such as images and videos.
Dynamic content is generated in real-time based on user input or other factors, like the current
date, making it more complex and slower to produce.
A web server delivers static content directly to the browser, while an application server generates
dynamic content and handles more complex processing tasks.
Application servers communicate with databases and run application logic, which allows them to
customize content for individual users.
To improve performance, web servers use caching to store copies of dynamic content, reducing
the need to generate it repeatedly.
When a request for dynamic content is made, the web server first checks the cache; if the content
is not there, it retrieves it from the application server and stores it for future requests
ii. Video 2:
The content discusses the concept and functionality of single-page applications (SPAs) in web
development.
SPAs provide a user-friendly and mobile-friendly experience by loading a single HTML page that
updates dynamically as users interact with the application.
Unlike traditional multi-page applications, SPAs reduce server load by only sending necessary
data (like JSON objects) instead of entire web pages.
There are two main approaches for serving resources in SPAs: bundling and lazy loading.
Bundling loads all necessary resources at once, while lazy loading fetches resources as needed,
which can improve performance for complex applications.
Developers should assess the complexity of their applications to determine whether a traditional
multi-page application or an SPA is more suitable.
The choice of resource delivery method can significantly impact the performance and user
experience of the application.
iii. Video 3:
The content focuses on the React library and its significance in front-end development.
Understanding React
React is an open-source JavaScript library that simplifies building user interfaces for web and
mobile applications.
It allows developers to write less code, making it easier to maintain and test applications.
Components in React
React's core concept is the use of components, which are reusable pieces of the user interface.
For example, a user profile picture can be created as a component and reused throughout the
application, enhancing efficiency.
The React community continuously contributes to its development, offering many open-source
libraries with pre-made components.
Annual conferences promote sharing and introduce new features, encouraging developers to
engage with the community.
React is a library for building composable user interfaces. It encourages the creation of reusable UI
components which present data that changes over time.
Traditionally, web application UIs are built using templates or HTML directives. These templates dictate
the full set of abstractions that you are allowed to use to build your UI.
React approaches building user interfaces differently by breaking them into components. This
means React uses a real, full-featured programming language to render views, which we see as an
advantage over templates for a few reasons:
We’ve also created JSX, an optional syntax extension, in case you prefer the readability of HTML to raw
JavaScript.
In a traditional JavaScript application, you need to look at what data changed and imperatively make
changes to the DOM to keep it up-to-date. Even AngularJS, which provides a declarative interface via
directives and data binding requires a linking function to manually update DOM nodes.
When your component is first initialized, the render method is called, generating a lightweight
representation of your view. From that representation, a string of markup is produced and injected into
the document. When your data changes, the render method is called again. In order to perform
updates as efficiently as possible, we diff the return value from the previous call to render with the new
one and generate a minimal set of changes to be applied to the DOM.
The data returned from render is neither a string nor a DOM node — it’s a lightweight description of
what the DOM should look like.
We call this process reconciliation. Check out this jsFiddle to see an example of reconciliation in
action.
Because this re-render is so fast (around 1ms for TodoMVC), the developer doesn’t need to explicitly
specify data bindings. We’ve found this approach makes it easier to build apps.
Because React has its own lightweight representation of the document, we can do some pretty cool
things with it:
iv. Video 4:
This content explains how React manages updates to the web page efficiently through its virtual DOM.
Reconciliation Process
React checks for differences between the virtual DOM and the browser DOM.
Only the changed elements in the virtual DOM are updated in the browser DOM, minimizing
performance costs.
Efficient Updates
As you know, this is called the reconciliation process and can be broken down into the following
steps:
Step 2: The virtual DOM is compared to the previous version of the virtual DOM and checks which
elements have changed.
As updating the browser DOM can be a slow operation, this process helps to reduce the number of
updates to the browser DOM by only updating when it is necessary.
But even with this process, if a lot of elements are updated by an event, pushing the update to the
browser DOM can still be expensive and cause slow performance in the web application.
The React team invested many years of research into solving this problem. The outcome of that research
is what’s known as the React Fiber Architecture.
The Fiber Architecture allows React to incrementally render the web page. What this means is that
instead of immediately updating the browser DOM with all virtual DOM changes, React can spread the
update over time. But what does "over time" mean?
Imagine a really long web page in the web browser. If the user scrolls to the bottom, the top of the web
page is no longer visible. The user then clicks a button on the bottom of the web page that updates some
text on the top of the web page.
But the top of the page isn’t visible. Therefore, why update it immediately?
Perhaps there is text currently displayed on the bottom of the page that also updates when the button is
clicked. Wouldn’t that be a higher priority to update than the non-visible text?
This is the principle of the React Fiber Architecture. React can optimize when and where updates occur
to the browser DOM to significantly improve application performance and responsiveness to user input.
Think of it as a priority system. The highest priority changes, the elements visible to the user, are
updated first. While lower priority changes, the elements not currently displayed, are updated later.
While you’re unlikely to interact with the virtual DOM and Fiber Architecture yourself, it’s good to know
what’s going on if issues occur during the development of your web application.
There are many tools available to help you investigate how React is processing your webpage. The
official React Developer Tools web browser plugin developed by Meta will be one of the key tools in your
developer toolbox. So, if you do have to look deeper into the code, you’ll have the right toolbox available
to help you. These tools will be explored later on.
v. Video 5:
The content focuses on understanding the component hierarchy in React for building applications.
Every React application starts with a root component, known as the app component.
Components are structured in a tree format, where child components are added to the app
component to create the application.
The app component includes two child components: the new item bar for adding items and the
shopping list for displaying items.
Each shopping item is represented by a reusable child component, allowing for efficient updates
when items are removed.
The app component serves as the entire webpage, containing a Navbar component and a Page
component.
The Page component includes a main feature component for a blog summary and multiple
instances of a small feature component for additional blog posts, showcasing code reusability.
Overall, mastering component hierarchies in React can enhance your application development skills.
Alternatives to React
React is a library and not a framework. This means you'll often use other JavaScript libraries with it to
build your application. In this reading, you will be briefly introduced to some JavaScript libraries
commonly used with React.
Lodash
Official Website
As a developer, there's a lot of logic you'll commonly write across applications. For example, you might
need to sort a list of items or round a number such as 3.14 to 3. Lodash provides common logic such as
these as a utility library to save you time as a developer.
Luxon
Official Website
You'll be working with dates and times often as a developer. Think of viewing a list of orders and when
they were placed, or displaying a calendar schedule for an event. Dates and times are everywhere.
Luxon helps you work with dates and times by providing functions to manipulate and display them. For
example, think of how dates are formatted in different countries. In the United States the format
is Month Day Year but in Europe it is Day Month Year. This is one area where Luxon can help you
display the date in the user's local format.
Redux
Official Website
When building a web application, you'll need to keep track of its state. Think of when you shop online.
The web application tracks items currently in your shopping cart. When you remove an item from the
cart, the application needs to update what displays on the screen. This is where Redux comes in. It helps
you manage your application state and even has advanced features such as undo and redo.
Axios
Official Website
As a developer you'll be communicating with APIs over HTTP frequently. The Axios library helps to
simplify sending HTTP requests and processing the response. It also provides advanced features
allowing you to cancel requests and to change data received from the web server before your
application uses the data.
Jest
Official Website
It is good practice to write automated tests for your code as a professional developer. The jest library
helps you to do this and works with many libraries and frameworks. It also provides reporting utilities
such as providing information on how much of your code is tested by your automated tests.
Conclusion
If you're curious to learn more about these libraries, their websites feature setup guides, tutorials and
documentation to get started. These libraries will be covered later on.
Completed