CSC 326 Web Development
CSC 326 Web Development
1
Web Basics and Overview: Introduction to Internet, World Wide Web, Web Browsers, URL,
HTTP.
History of Internet
This marvelous tool has quite a history that holds its roots in the cold war scenario. A need was
realized to connect the top universities of the United States so that they can share all the research
data without having too much of a time lag. This attempt was a result of Advanced Research
Projects Agency (ARPA), which was formed at the end of 1950s just after the Russians had
climbed the space era with the launch of Sputnik. After the ARPA was success in 1969, it didn’t
take the experts long to understand that how much potential can this interconnection tool have. In
1971 Ray Tomlinson made a system to send electronic mail. This was a big step in the making as
this opened gateways for remote computer accessing i.e. telnet. During all this time, rigorous paper
work was being done in all the elite research institutions. From giving every computer an address
to setting out the rules, everything was getting penned down. 1973 saw the preparations for the
vital TCP/IP and Ethernet services. At the end of 1970s, Usenet groups had surfaced. By the time
the 80s had started, IBM came up with its PC based on Intel 8088 processor, which was widely
used by students, and universities for it solved the purpose of easy computing. By 1982, the
Defense Agencies made the TCP/IP compulsory and the term ―internet‖ was coined. The domain
name services arrived in the year 1984, which is also the time around which various internet based
marked their debut. A worm, or a rust on the computers, attacked in 1988 and disabled over 10%
of the computer systems all over the world. While most of the researchers regarded it as an
opportunity to enhance computing as it was still in its juvenile phase, quite a number of computer
companies became interested in dissecting the cores of the malware, which resulted to the
formation Computer Emergency Rescue Team (CERT). Soon after the world got over with the
computer worm, World Wide Web came into existence. Discovered by Tim Berners-Lee, World
Wide Web was seen as a service to connect documents in websites using hyperlinks.
World Wide Web : The World Wide Web (abbreviated WWW or the Web) is an information
space where documents and other web resources are identified by Uniform Resource Locators
(URLs), interlinked by hypertext links, and can be accessed via the Internet. English scientist Tim
Berners-Lee invented the World Wide Web in 1989. He wrote the first web browser computer
program in 1990 while employed at CERN in Switzerland. The Web browser was released outside
CERN in 1991, first to other research institutions starting in January 1991 and to the general public
on the Internet in August 1991. The World Wide Web has been central to the development of the
Information Age and is the primary tool billions of people use to interact on the Internet. Web
pages are primarily text documents formatted and annotated with Hypertext Markup Language
(HTML). In addition to formatted text, web pages may contain images, video, audio, and software
components that are rendered in the user's web browser as coherent pages of multimedia content.
Embedded hyperlinks permit users to navigate between web pages. Multiple web pages with a
common theme, a common domain name, or both, make up a website. Website content can largely
be provided by the publisher, or interactively where users contribute content or the content depends
2
upon the users or their actions. Websites may be mostly informative, primarily for entertainment,
or largely for commercial, governmental, or non-governmental organizational purposes, WWW is
another example of client/server computing. Each time a link is followed, the client is requesting
a document (or graphic or sound file) from a server (also called a Web server) that's part of the
World Wide Web that "serves" up the document. The server uses a protocol called HTTP or
Hypertext Transfer Protocol. The standard for creating hypertext documents for the WWW is
Hyper Text Markup Language or HTML. HTML essentially codes plain text documents so they
can be viewed on the Web.
Browsers: WWW Clients or "Browser": The program you use to access the WWW is known as a
browser because it "browses" the WWW and requests these hypertext documents. Browsers can
be graphical, allows seeing and hearing the graphics and audio; text-only browsers (i.e., those with
no sound or graphics capability) are available. All of these programs understand http and other
Internet protocols such as FTP, gopher, mail, and news, making the WWW a kind of "one stop
shopping" for Internet users.
Uniform Resource Locators or URLs: A Uniform Resource Locator or URL is the address of a
document found on the WWW. The browser interprets the information in the URL in order to
connect to the proper Internet server and to retrieve your desired document. Each time a click on
a hyperlink in a WWW document instructs browser to find the URL that is embedded within the
hyperlink. The elements in a URL: Protocol: //server's address/filename Hypertext protocol:
http://www.aucegypt.edu File Transfer Protocol: ftp://ftp.dartmouth.edu Telnet Protocol:
telnet://pac.carl.org News Protocol: news:alt.rock-n-roll.stones What are Domains? Domains
divide World Wide Web sites into categories based on the nature of their owner, and they form
part of a site's address, or uniform resource locator (URL). Common top-level domains are:
Additional three-letter, four-letter, and longer top-level domains are frequently added. Each
country linked to the Web has a two-letter top-level domain, for example, .fr is France, .ie is
Ireland.
MIME (Multi-Purpose Internet Mail Extensions):- MIME is an extension of the original
Internet e-mail protocol that lets people use the protocol to exchange different kinds of data files
on the Internet: audio, video, images, application programs, and other kinds, as well as the ASCII
text handled in the original protocol, the Simple Mail Transport Protocol (SMTP). In 1991, Nathan
Borenstein of Bellcore proposed to the IETF that SMTP be extended so that Internet (but mainly
3
Web) clients and servers could recognize and handle other kinds of data than ASCII text. As a
result, new file types were added to "mail" as a supported Internet Protocol file type.
Servers insert the MIME header at the beginning of any Web transmission. Clients use this header
to select an appropriate "player" application for the type of data the header indicates. Some of these
players are built into the Web client or browser (for example, all browsers come with GIF and
JPEG image players as well as the ability to handle HTML files); other players may need to be
downloaded. New MIME data types are registered with the Internet Assigned Numbers Authority
(IANA). MIME is specified in detail in Internet Request for Comments 1521 and 1522, which
amend the original mail protocol specification, RFC 821 (the Simple Mail Transport Protocol) and
the ASCII messaging header, RFC 822.
Hypertext Transport Protocol: HTTP means Hypertext Transfer Protocol. HTTP is the
underlying protocol used by the World Wide Web, and this protocol defines how messages are
formatted and transmitted, and what actions Web servers and browsers should take in response to
various commands. For example, when you enter a URL in your browser, this sends an HTTP
command to the Web server directing it to fetch and transmit the requested Web page. The other
main standard that controls how the World Wide Web works is HTML, which covers how Web
pages are formatted and displayed.
HTTP is called a stateless protocol because each command is executed independently, without
any knowledge of the commands that came before it. This is the main reason that it is difficult to
implement Web sites that react intelligently to user input.
HTTPS: A similar abbreviation, HTTPS means Hyper Text Transfer Protocol Secure. Basically, it
is the secure version of HTTP. Communications between the browser and website are encrypted
by Transport Layer Security (TLS), or its predecessor, Secure Sockets Layer (SSL).
Web development is the process of creating, building, and maintaining websites and web
applications. It involves everything from web design to programming and database management.
Web development is generally divided into three core areas: Frontend Development, Backend
Development, and Full Stack Development.
Frontend Development
Frontend development refers to everything that users see and interact with on the website. It
involves the design, structure, and layout of the website and is often referred to as the ‘client
side’ of an application.
4
Frontend Technologies
HTML: HTML stands for Hypertext Markup Language. It is the standard markup language
used to create and design web pages, defining their structure and layout.
CSS: Cascading Style Sheets fondly referred to as CSS is a simply designed language
intended to simplify the process of making web pages presentable. It is used to style our
website.
JavaScript: JavaScript is a scripting language used to provide a dynamic behavior to our
website.
Frontend Frameworks/Libraries
React.js : A popular JavaScript library for building dynamic, component-based user
interfaces.
Angular : A full-fledged framework for building single-page applications (SPAs), with
features like two-way data binding and dependency injection.
Vue.js : A progressive JavaScript framework that is flexible and can be used for building both
simple and complex user interfaces.
5
Backend Development
Backend development refers to the server side of a website, where the logic and data are
processed and stored. Users do not directly interact with this part, but it ensures that the website
works properly.
Node.js Express
C# .NET
Databases
MySQL
PostgreSQL
MongoDB
MariaDB
SQLite
6
Full Stack Development
Full-stack development refers to the practice of developing both the frontend and backend of a
website or web application. Full-stack developers have a deep understanding of both areas and
can build end-to-end solutions.
Databases
In web technology, a database is a structured collection of data that is stored electronically and
accessed via a web application. It serves as the backend component where data is stored,
managed, and retrieved. Databases can be relational (like MySQL, PostgreSQL) using structured
tables and SQL for queries, or non-relational (like MongoDB, CouchDB) which store data in
flexible, document-oriented formats. They enable web applications to handle dynamic content,
user data, transactions, and more by providing efficient storage, retrieval, and manipulation
capabilities. Database management systems (DBMS) are used to interact with the database,
ensuring data integrity, security, and performance.
1. Relational Databases
A relational database stores data in tables, similar to a spreadsheet, where each table has rows
and columns. The rows hold individual records, and the columns define the data attributes.
Tables can be linked to each other through special keys, allowing related data to be connected.
Postgre SQL : PostgreSQL is a powerful, open-source relational database that supports
advanced SQL features and complex queries. It handles structured data, ensures ACID
compliance, and is known for its reliability and extensibility.
MariaDB : MariaDB is an open-source relational database that evolved from MySQL,
offering improved performance, security, and features. It supports SQL queries, ACID
compliance, and is highly compatible with MySQL.
MySQL : MySQL is an open-source relational database management system that uses SQL
for managing structured data. It’s known for its reliability, ease of use, and performance,
widely used in web applications.
2. NoSQL Databases
A NoSQL database stores data in a flexible, non-tabular format, unlike traditional relational
databases. Instead of using tables with rows and columns, NoSQL databases might use
documents, key-value pairs, wide-columns, or graphs to store data. This allows them to handle
large amounts of unstructured or semi-structured data efficiently. They are designed to scale
easily and manage big data applications.
Mongodb : MongoDB is a NoSQL database storing data in JSON-like documents. It handles
unstructured data, supports powerful queries, and scales easily across servers, making it
popular for flexible, scalable applications.
7
Cassandra : Apache Cassandra is an open-source NoSQL database that is used for handling
big data. It has the capability to handle structure, semi-structured, and unstructured data.
Redis: Redis is an in-memory NoSQL database known for its speed. It supports various data
structures like strings, hashes, and lists, making it ideal for caching, real-time analytics, and
messaging.
HTML
HTML stands for Hypertext Markup Language. It is the standard language used to create and
structure content on the web. It tells the web browser how to display text, links, images, and other
forms of multimedia on a webpage. HTML sets up the basic structure of a website, and then CSS
and JavaScript add style and interactivity respectively to make it look good and function better.
How Does HTML Work? - HTML documents are plain-text files saved with an .html extension.
Browsers read these documents, interpret the markup (tags and attributes), and render the
formatted content on your screen.
HTML is a markup language, not a programming language, meaning it annotates text to
define how it is structured and displayed by web browsers.
It forms the building blocks of all websites and is complemented by CSS for style and
JavaScript for interactivity.
It is a static language, meaning that it does not inherently provide interactive features but
can be combined with CSS for styling and JavaScript for interactivity.
In a nutshell, HTML is all about organizing and displaying information on a webpage. We
can think of it as the bones or structure of a webpage.
Basic HTML Code Example
1
<! DOCTYPE html>
2
<html>
3
4
<head>
5
<title>My First Webpage</title>
6
</head>
7
8
<body>
9
<h1>Welcome to My Webpage</h1>
10
<p>This is my first paragraph of text!</p>
11
</body>
8
12
13
</html>
Output:
HTML
In this example:
<!DOCTYPE html>: Declares the document type and version (HTML5).
<html>: The root element that wraps all HTML content.
<head>: Contains meta-information about the webpage, like the title.
<title>: Specifies the title of the webpage (appears in the browser tab).
<body>: Contains the visible content of the webpage.
<h1>: Represents the main heading on the page ("Welcome to My Webpage").
<p>: Defines a paragraph of text ("This is my first paragraph of teHTML Introduction
Key Features of HTML
Markup Language: HTML uses tags to markup content. Each tag defines different
elements, such as headings, paragraphs, tables, links, etc.
Semantics: HTML provides semantic tags that describe the meaning of the content. For
example, <article>, <footer>, <header>, and <nav> describe different types of content on a
webpage.
Responsive Web Design: HTML supports various features for building responsive websites,
including media queries and the ability to embed multimedia content.
Interactive Content: HTML can embed interactive content using JavaScript, which allows
for dynamic changes in the content.
9
<! DOCTYPE html> - This is the document type declaration, not a tag. It declares that the
document is an HTML5 document.
<html> - This is called the HTML root element. All other elements are contained within it.
<head> - The head tag contains the "behind the scenes" elements for a webpage. Elements
within the head aren't visible on the front end of a webpage. Typical elements inside the
<head> include:
o <title>: Defines the title displayed on the browser tab.
o <meta>: Provides information like the character set or viewport settings.
o <link>: Links external stylesheets or resources.
o <style>: Embeds internal CSS styles.
o <script>: Embeds JavaScript for functionality.
<title> - The title is what is displayed on the top of your browser when you visit a website
and contains the title of the webpage that you are viewing.
<h2> - The <h2> tag is a second-level heading tag.
<p>- The <p> tag represents a paragraph of text.
<body> - The body tag is used to enclose all the visible content of a webpage. In other words,
the body content is what the browser will show on the front end.
10
An HTML document can be created using an HTML text editor. Save the text file using the
".html" or ".htm" extension. Once saved as an HTML document, the file can be opened as a
webpage in the browser.
Note: Basic/built-in text editors are Notepad (Windows) and TextEdit (MacOS). Other
advanced text editors include Sublime Text, Visual Studio Code, Froala, etc.
HTML Elements and HTML Tags are related but distinct. An HTML element is the complete
structure, including the opening tag, content (if any), and the closing tag (if applicable).
On the other hand, A tag is the actual keyword or name enclosed in angle brackets (< >) that
tells the browser what kind of content to expect.
HTML Tags
Tag Description
11
HTML Attributes
Attributes provide additional information about an element. They are placed inside the opening
tag and are written as name="value". Common attributes include class, id, href, and src.
Example:
<a href="https://www.example.com">Visit Example</a>
href is an attribute of the <a> tag that defines the URL of the link.
index.html
Why Learn HTML?
Here are 5 common reasons to learn HTML:
1. Build Websites: HTML is the basic building block for creating any website. Learning HTML
can help you pursue a career in web development.
2. Customize Content: Allows you to edit or tweak web pages, emails, or templates to fit your
needs.
3. Understand how the web works: This helps you grasp how the internet works and how web
pages are structured.
4. Employment Opportunities: According to the Bureau of Labor Statistics, projects that
employment for web developers will grow 16% between 2022 and 2032, which is much
faster than the average across all occupations.
5. Learn Easily: HTML is beginner-friendly, making it a great first step into the world of
coding and technology.
Applications of HTML
Web Development: HTML is the backbone of every webpage. It structures the content and
integrates multimedia, hyperlinks, and more.
Web Applications: HTML, in combination with CSS and JavaScript, powers complex web
applications (e.g., Google Docs, Trello).
12
Emails: HTML emails use table-based layouts and embedded media to deliver rich,
interactive content.
Mobile App Development: HTML5 is used with frameworks like PhoneGap to build mobile
apps for iOS and Android.
Limitations of HTML
No Logic or Functionality: HTML cannot handle complex logic, interactivity, or dynamic
content on its own. It requires JavaScript for such tasks.
SEO Limitations: While HTML provides structure, it’s not enough by itself for search
engine optimization (SEO). Proper metadata and content structuring, as well as external SEO
practices, are necessary.
Limited Styles: While HTML can handle basic styles via the style attribute, it is typically
complemented by CSS for complex styling and layout.
HTML5: Enhancements and New Features
HTML5 introduced several powerful features that improve the structure and functionality of web
pages, including:
Semantics: New tags like <article>, <footer>, <header>, and <section> to improve the
meaning of the content.
Multimedia: <audio> and <video> tags for embedding audio and video without plugins.
APIs: New APIs like Geolocation, Web Storage, and Canvas allow for more dynamic content
and interactive websites.
HTML History
Currently, we are using HTML5, which is the latest and most advanced version of HTML.
Tim Berners-Lee initially created HTML in 1991 as a way to share and structure documents
on the web.
The first-ever version was HTML 1.0, a basic and limited version. However, the first
standardized version, HTML 2.0, was published in 1995, laying the foundation for web
development, as we know it today.
13
HTML Structure
Below mentioned are the basic HTML tags that divide the whole page into various parts like
head, body, etc.
Basic HTML Tags for Document Structure
Tags Descriptions
Encloses the entire HTML document, serving as the root element for all HTML
<html>
content.
Contains header information about the webpage, including title, meta tags, and
<head> linked stylesheets. It is part of the document's structure but is not displayed on
the webpage.
14
Basic HTML Tags for Document Structure
Tags Descriptions
Used within the <head> section to define the title of the HTML document. It
<title> appears in the browser tab or window and provides a brief description of the
webpage's content.
Encloses the visible content of the webpage, such as text, images, audio, videos,
<body> and links. All elements within this tag are displayed on the actual webpage when
viewed in a browser.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>HTML</title>
</head>
<body>
<!--Contents of the webpage-->
<p> Online study platform</p>
</body>
</html>
Code Overview:
This HTML document defines a basic webpage with a responsive design using <meta>
tags, ensuring it adjusts well to different devices.
The content includes a paragraph <p> displaying “Online study platform," and the title
"HTML" appears in the browser tab.
HTML Headings
The HTML heading tags are used to create headings for the content of a webpage. These tags
are typically placed inside the body tag. HTML offers six heading tags, from <h1> to <h6>, each
displaying the heading in a different font size.
Syntax:
<h1></h1>
<h2></h2>
<h3></h3>
<h4></h4>
<h5></h5>
<h6></h6>
15
<html>
<body>
<h1>Heading 1 (h1)</h1>
<h2>Heading 2 (h2)</h2>
<h3>Heading 3 (h3)</h3>
<h4>Heading 4 (h4)</h4>
<h5>Heading 5 (h5)</h5>
<h6>Heading 6 (h6)</h6>
</body>
</html>
Code Overview:
This code displays six headings (<h1> to <h6>) on the webpage, with <h1> being the
largest and most prominent and <h6> being the smallest.
The headings are used to define text hierarchy and emphasize content based on importance.
<html>
<body>
<p>
HTML stands for HyperText Markup Language.<br>
It is used to design web pages using a markup
language.<br>HTML is a combination of Hypertext
and Markup language.<br>Hypertext defines the
link between web pages.<br>A markup language
is used to define the text document within the
tag which defines the structure of web pages.
</p>
</body>
</html>
Code Overview:
This HTML code uses a <p> tag to display a paragraph of text, providing an overview of
what HTML is and its purpose.
The <br> tags are used to insert line breaks, making the text more readable by separating
each sentence onto a new line within the paragraph.
HTML Horizontal Line
The HTML <hr> tag is used to divide a page into sections by creating a horizontal line that
spans from the left to the right side of the page. This is an empty tag and does not require a
closing tag or any additional attributes.
16
Syntax:
<hr>
<html>
<body>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
<p>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
A Computer Science portal for geeks<br>
</p>
<hr>
</body>
</html>
HTML Images
The <img> tag is used to insert an image into a webpage. The source of the image is specified
within the src attribute, like this: <img src="source_of_image">.
Syntax:
<img src="geeks.png">
This HTML code uses the <img> tag to display an image on a webpage.
The src attribute specifies the URL of the image, which is loaded and displayed when the
page is rendered in the browser.
View HTML Source Code
While checking a web page, you might want to see the HTML code behind it. Here we will see
how you can view HTML source code for the entire page or a specific element.
17
This lets you see the HTML and CSS behind that element. You can also try making changes
and see the changes.
HTML Comments
HTML comments are used to add notes or explanations in the HTML code that are not
displayed by the browser.
They are useful for documenting the code, making it easier to understand and maintain.
To add a comment, use the syntax <!-- your comment here -->.
<!-- This is a comment and will not be displayed on the webpage -->
<p>This is visible text.</p>
In this example:
The text within the <!-- and --> tags will not appear on the webpage.
These comments can include reminders, warnings, or explanations about the code, which can
be useful for anyone reading or editing the HTML document.
Different Ways to Add Comments in HTML
There are two main ways to write comments in HTML: single-line and multi-line comments.
Both use the same basic syntax but differ in how they are implemented
Comment Descriptions Syntax
<!-- Multi
Multi- It follows the syntax of a single-line comment by adding
Line
line multiple lines in the comment.
Comment -->
Note: The shortcut for adding the comment through the keyboard is by typing Ctrl + / in
Windows, and Command + / for Mac users.
More Examples of HTML Comments
In this example:
The code uses HTML comments (<!-- comment -->) to add notes for developers, which are
not displayed on the webpage.
The <h1> and <h2> tags display headings, while inline comments in <h2> do not affect the
visible text.
18
Multi-Line Comments and Hidden Code Sections
<html>
<body>
<!-- This is
heading tag -->
<h1>GeeksforGeeks</h1>
<!-- This is
multi-line
comment -->
<h2>This is multi-line comment</h2>
<!-- <button style="font-family: Sans-serif;">
Click Me
</button> -->
</body>
</html>
In this example:
The code includes HTML comments (<!-- comment -->) that are not displayed by browsers
but serve as notes for developers.
The <h1> and <h2> tags define headings, with comments explaining their purpose; the
commented-out <button> element is not rendered on the page.
19
HTML Text Formatting
20
Tags Description
21
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text Formatting Example</title>
</head>
<body>
<p>
<strong>Strong:</strong>
This text is important and bold.
</p>
<p>
<em>Emphasized:</em>
This text is emphasized and italic.
</p>
<p>
<b>Bold:</b>
This text is bold.
</p>
<p>
<i>Italic:</i>
This text is italic.
</p>
<p>
<mark>Marked:</mark>
This text is highlighted.
</p>
</body>
</html>
Output:
22
HTML Text Formatting Example Output
Example 2: Combining Logical and Physical Tags
This example shows how logical and physical tags can be combined for enhanced text
formatting:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Advanced Text Formatting</title>
</head>
<body>
<p>This is a
<strong><em>very important</em></strong> message.
</p>
<p>The chemical formula of water is H
<sub>2</sub>O.
</p>
<p>
<del>Deleted text</del> and
<ins>inserted text</ins>
are shown here.
</p>
<p><small>Smaller text</small>
can be used for disclaimers.
</p>
<p>E = mc<sup>2</sup></p>
</body>
</html>
Output:
23
CSS (Cascading Style Sheet)
We will cover:
✅ What is CSS?
✅ How to add CSS to an HTML document
✅ CSS Syntax and Structure
✅ CSS Selectors: How to target elements
✅ Styling text and fonts
✅ Understanding the CSS Box Model
✅ Working with colors and backgrounds
✅ Using display and position properties
✅ Creating layouts with Flexbox
✅ A practical example project
✅ Summary and next steps for learning CSS
What is CSS?
It is a language used to describe how HTML elements should be presented on screen (or in print,
or on other media). CSS lets you style HTML elements: control colors, fonts, spacing, layouts,
and more.With CSS, you can separate content (HTML) from design (CSS), which makes your
code cleaner and easier to maintain.
Why use CSS?
1. Inline CSS
You add the style directly to an HTML element using the style attribute.
Example:
<p style="color: red ;"> Hello World</p>
24
2. Internal CSS
You can add a <style> block inside your HTML <head> tag.
Example:
<html>
<head>
<style>
p {
color: red;
}
</style>
</head>
Example:
<head>
<link rel="stylesheet" href="styles.css">
</head>
p {
color: red;
}
Best practice: Makes your HTML cleaner and allows styles to be reused across multiple pages.
CSS Syntax
selector {
property: value;
}
Example:
h1 {
color: blue;
font-size: 30px;
}
25
Explanation:
Example usage:
#header {
background-color: lightgray;
}
.content {
padding: 20px;
}
div p {
color: green;
}
Text and typography are key to a good design. You can style them using the following
properties:
p {
color: #333;
font-family: Arial, sans-serif;
font-size: 16px;
font-weight: bold;
text-align: center;
text-decoration: underline;
line-height: 1.5;
}
26
Common text properties:
Every HTML element is considered a box, and CSS controls how this box behaves.
Example:
div {
padding: 10px;
border: 2px solid black;
margin: 20px;
}
background-color: lightblue;
Example:
Display Property
27
The display property defines how an element is rendered:
Position Property
Example:
css
CopyEdit
.fixed-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
}
Flexbox is a modern layout system that makes it easy to create flexible, responsive designs.
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
Properties:
28
Common values:
.item {
flex: 1;
padding: 10px;
}
flex-grow
flex-shrink
flex-basis
Flexbox is very powerful for building responsive designs without complex float or positioning
hacks.
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
h1 {
color: darkblue;
text-align: center;
}
.content {
background-color: white;
padding: 20px;
margin: 50px auto;
width: 50%;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
<div class="content">
<p>This is a paragraph inside a styled box.</p>
29
</div>
</body>
</html>
Summary
Next Steps
30
Introduction to JavaScript
What is JavaScript?
JavaScript is a scripting language that runs in the browser and is primarily used to make web
pages interactive. It can:
Quick Start:
console.log("Hello, JavaScript!");
31
Basic HTML + JavaScript Template
<!DOCTYPE html>
<html>
<head>
<Title>My First JS Page</title>
</head>
<body>
<h1>Welcome to JavaScript</h1>
<script>
alert("This is your first JavaScript alert!");
</script>
</body>
</html>
A variable is a container for storing data values, like numbers, text, or objects.
Declaring Variables
ES6+ Keywords:
32
🧪 Examples
let message = "JavaScript is fun!";
let score = 95;
let isPassed = true;
Mini Practice
Output:
JavaScript has several kinds of operators you will use all the time — for math, comparisons, and
logic.
1. Arithmetic Operators
+ 5+3 Addition
- 10 - 4 Subtraction
* 4*2 Multiplication
33
Operator Example Meaning
/ 8/2 Division
** 2 ** 3 Exponentiation
let a = 10;
let b = 3;
console.log(a + b); // 13
console.log(a % b); // 1
console.log(2 ** 3); // 8
2. Assignment Operators
let x = 10;
x += 5; // x = 15
x *= 2; // x = 30
console.log(x);
2. Comparison Operators
34
Operator Description Example
4. Logical Operators
||
OR true || false → true
Mini Practice
let score = 87;
let passed = score >= 50;
let perfect = score === 100;
1. if / else Statements
let age = 18;
If the condition is true, the first block runs. Otherwise, the else block runs.
35
2. else if Chains
let grade = 85;
3. Ternary Operator
console.log(message);
4. switch Statement
switch (day) {
case "Monday":
console.log("Start of the week!");
break;
case "Friday":
console.log("Weekend is near!");
break;
default:
console.log("Just another day.");
}
Important Concepts
Mini Practice
Try this:
36
console.log("Good morning!");
} else if (time < 18) {
console.log("Good afternoon!");
} else {
console.log("Good evening!");
}
1.6 Loops in JavaScript
Loops let you run a block of code multiple times — perfect for working with lists, repeating
actions, or running until a condition is met.
1. for Loop
for (let i = 1; i <= 5; i++) {
console.log ("Count: " + i);
}
Structure:
2. while Loop
let i = 1;
while (i <= 3) {
console.log("Hello " + i);
i++;
}
3. do...while Loop
let i = 1;
do {
console.log("Number: " + i);
i++;
} while (i <= 3);
37
let user = {
name: "Alice",
age: 25,
isAdmin: true
};
Mini Practice
// Print even numbers from 1 to 10
for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) {
console.log(i);
}
}
Features:
<button onclick="calculate('add')">Add</button>
<button onclick="calculate('subtract')">Subtract</button>
38
<button onclick="calculate('multiply')">Multiply</button>
<button onclick="calculate('divide')">Divide</button>
<script src="calculator.js"></script>
</body>
</html>
if (isNaN(num1) || isNaN(num2)) {
alert("Please enter valid numbers!");
return;
}
switch (operation) {
case "add":
result = num1 + num2;
break;
case "subtract":
result = num1 - num2;
break;
case "multiply":
result = num1 * num2;
break;
case "divide":
if (num2 === 0) {
alert("Cannot divide by zero!");
return;
}
result = num1 / num2;
break;
default:
result = "Invalid operation";
}
document.getElementById("result").innerText = result;
}
How to Run It
39
2.1 Functions
What is a Function?
A function is a reusable block of code that performs a specific task. It can accept inputs
(parameters) and optionally return a result.
Declaring a Function
function greet (name) {
console.log ("Hello, " + name + "!");
}
Returning a Value
function add(a, b) {
return a + b;
}
let result = add(3, 7);
console.log(result); // 10
Function Practice
function multiply(x, y) {
return x * y;
}
console.log(multiply(4, 5)); // 20
40
};
Arrow functions are shorter and especially useful with array methods
41