Web Tech Unit - 2 Notes
Web Tech Unit - 2 Notes
JavaScript.
dy
Key Aspects of Front-End Design:
● ser Interface (UI):The graphical layout of a website.
U
● User Experience (UX):Enhancing usability and accessibility.
u
● Responsiveness:Ensuring the design works on differentscreen sizes.
● Performance Optimization:Reducing load times usingefficient coding practices.
St
2. HTML (HyperText Markup Language)
y
HTML is the foundation of web pages, defining their structure and content.
da
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Web Page</title>
</head>
<body>
O
<ol><li>Item</li></ol>
○ Ordered List:
<ul><li>Item</li></ul>
○ Unordered List:
<a href="https://example.com">Click Here</a>
4. Links:
<img src="image.jpg" alt="Description">
5. Images:
<table>
6. Tables: <tr>
, <td>for tabular data.
,
<form>with
7. Forms: <input> <select>
, <textarea>foruser input.
,
8. S <header>
emantic Elements: <nav>
, <section>
, <article>
, <footer>for
,
better structure.
3. Structuring HTML
dy
Proper structuring ensures better readability, SEO, and accessibility.
u
● Usesemantic elements(
<article> <aside>
, St <section>
, )instead of generic
<div>
.
● ollownested elementsproperly (e.g., a
F <ul>shouldhave
<li>inside).
● Keepconsistent indentationfor readability.
● Usealt attributesfor images to improve accessibility.
● Usemeta tagsfor SEO optimization.
y
Example of a Well-Structured HTML Page:
da
!DOCTYPE html>
<
<html>
<head>
<title>My Website</title>
ne
</header>
<nav>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="about.html">About</a></li>
</ul>
</nav>
<section>
<h2>Welcome!</h2>
<p>This is the main content of the page.</p>
</section>
OnedayStudyVisit
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>
dy
Types of CSS
1. Inline CSS:Directly inside an HTML tag.
<p style="color: blue;">This is blue text.</p>
u
2. Internal CSS:Inside<style>in the <head>section.
<style> St
body { background-color: lightgray; }
</style>
p { color: red; }
● Element Selector:
.classname { color: blue; }
● Class Selector:
#idname { color: green; }
● ID Selector:
h1, h2, h3 { font-family: Arial; }
● Group Selector:
ne
*{ font-family: Arial; }
● Universal Selector:
Box Model
O
● ontent:Actual text or image inside an element.
C
● Padding:Space between content and border.
● Border:Surrounds padding and content.
● Margin:Space between elements.
Example:
div {
width: 300px;
padding: 10px;
OnedayStudyVisit
document.getElementById("demo").innerHTML = "Hello JavaScript!";
dy
Key JavaScript Concepts
u
V
● ariables:let name = "John";
● Functions:
function greet() {
alert("Hello, welcome!");
St
}
● Events:
<button onclick="greet()">Click Me</button>
y
DOM Manipulation:
●
document.querySelector("p").style.color = "red";
da
Different image formats are used based on quality, compression, and transparency needs.
nAPI (Application Programming Interface)is a setof rules and protocols that allows
A
different software applications to communicate with each other. APIs are commonly used in
web development to retrieve, send, and modify data between a client (browser) and a server.
or example, when you use a weather app to check the temperature, it fetches data from a
F
dy
weather API instead of storing all the information locally.
Types of APIs
u
There are multiple types of APIs, but the two most commonly used in web development are:
St
1. REST API (Representational State Transfer API)
AREST APIis a web service that usesHTTP requeststo perform operations like:
● ET- Retrieve data
G
y
● POST- Send data to the server
● PUT- Update existing data
da
Example: If you want to retrieve user data from an API, a GET request might look like this:
GET https://api.example.com/users
ne
{
O
"id": 1,
"name": "John Doe",
"email": "[email protected]"
}
nlike REST,GraphQLallows clients to fetch onlythe specific data they need, reducing
U
unnecessary data transfer.
{
user(id: 1) {
name
email
}
}
{
"data": {
"user": {
dy
"name": "John Doe",
"email": "[email protected]"
}
}
}
u
St
This makesGraphQLmore flexible compared toREST.
Fetching Data Using JavaScript (AJAX and Fetch API) (Not include in Syllabus
y
optional for Exam purpose)
o interact with APIs from a web page, JavaScript provides methods likeAJAX
T
da
responses asynchronously.
1.
fetch("https://api.example.com/data")
{
dy
"id": 1,
"name": "John Doe",
"age": 30
}
u
The JavaScript console will output: St
{id: 1, name: "John Doe", age: 30}
y
Making a POST Request with Fetch API
da
POSTmethod alongwith
Tosend datato an API, use the fetch()
.
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
O
name: "Alice",
email: "[email protected]"
})
})
.then(response => response.json())
.then(data => console.log("User added:", data))
.catch(error => console.error("Error:", error));
How It Works:
b
● ody: JSON.stringify({...})converts the object to aJSON string.
● TheAPI responseis logged in the console.
dy
Conclusion
● PIs allow web applications to communicate with servers.
A
● REST APIsuse HTTP methods to send and receive data.
u
● GraphQL APIsenable fetching specific data more efficiently.
● Fetch APIis a modern way to retrieve data from APIs using JavaScript.
● Proper error handling ensures smooth operation when working with APIs.
St
HTML5 Features
y
da
TML5 introduced several new elements, attributes, and APIs to improve web development.
H
These enhancements providebetter structure, interactivity,and multimedia capabilities
while ensuring cross-browser compatibility.
ne
and SEO. Before HTML5, developers used <div>elementsfor everything. Now, HTML5
providesmeaningfulelements that describe their purpose.
<article R
epresents self-contained content (e.g., blog post, news
>
article).
OnedayStudyVisit
<nav>
Contains navigation links (e.g., menu, sidebar links).
dy
Example Usage
<article>
<header>
u
<h2>Introduction to HTML5</h2>
<p>Published on: <time datetime="2024-03-03">March 3, 2024</time></p>
</header> St
<section>
<p>HTML5 brings new semantic elements, multimedia features, and APIs.</p>
</section>
<footer>
<p>Author: Abhishek</p>
y
</footer>
</article>
da
email
Validates an email format automatically.
url
Ensures only URLs are entered.
tel
Used for phone numbers.
number
Allows numeric input with min/max values.
range
Creates a slider for numeric input.
OnedayStudyVisit
Example Usage
<form>
<label>Email:</label>
<input type="email" placeholder="Enter your email" required>
label>Phone:</label>
<
<input type="tel" placeholder="Enter your phone number">
dy
label>Age:</label>
<
<input type="number" min="18" max="99">
label>Choose a date:</label>
<
<input type="date">
u
button type="submit">Submit</button>
< St
</form>
Canvas
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
tx.fillStyle = "blue";
c
ctx.fillRect(20, 20, 100, 50);
</script>
Explanation:
●
getContext("2d")enables 2D drawing.
dy
●
fillStylesets the fill color.
●
fillRect(x, y, width, height)draws a rectangle.
u
VG isXML-basedand used for vector graphics thatscale without losing quality. Ideal for
S
icons, illustrations, and charts.
raphics
G Pixel-based (raster) Vector-based (scalable)
ne
Type
interaction
Conclusion
H
● TML5 introducedsemantic elementsfor better contentstructure.
● Formsnow support new input types and built-in validation.
● Canvasis ideal for real-time graphics, whileSVGis great for scalable images.
OnedayStudyVisit
Conclusion
his unit covered the essentials of front-end web development, including HTML structuring,
T
CSS styling, JavaScript scripting, common image types, APIs, and HTML5 features.
Mastering these topics is crucial for building interactive and visually appealing web
applications.
u dy
St
y
da
ne
O