Module-1 Reference Material
Module-1 Reference Material
Prepared
By
[Link] KUMAR
Department of AIML
VIT-AP
MODULE NO. 1
Lee in 1991.
Html is used to create web pages(static web
pages)
Html is not a procedural language like c, c+
+,java..etc
separate groups: the World Wide Web Consortium (W3C) and the Web Hypertext
Application Technology Working Group (WHATWG). To understand the advancements of
HTML5, it's helpful to have a brief overview of the general HTML timeline:
1991–1999
HTML was created by web legend Tim Berners-Lee in 1991, and HTML versions 1–4 were
developed throughout the 1990s by W3C. In these early days of widespread internet use,
HTML efficiently displays the vast majority of web content, since at this time it largely
consists of static, non-interactive sites.
2000
W3C recommends XHTML 1.0 – an XML-based markup language that mirrors/extends
HTML. Previous versions of HTML are now showing their age, struggling to handle the
latest generation of multimedia, and interactive sites. To get the best results, developers are
resorting to third-party plugins.
2004
Development of HTML is closed by W3C, who instead decide to focus on XHTML.
WHATWG is formed to develop HTML further, with the aim of reflecting the modern
dynamic web, while keeping backwards compatibility with existing HTML code.
2004–2006
WHATWG gains support from major web browser developers. In 2006, W3C also
HTML page
The <head> element contains meta information
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-
width, initial-scale=1.0">
<title>My Web Page</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>: This is the very first line and declares the
document type to be HTML5. It's crucial for the browser to
render the page in standards mode. It is case-insensitive.
<html>: The root element of every HTML page. It encloses all
other HTML content. The lang attribute within the <html> tag
specifies the language of the document (e.g., "en" for English).
This is important for accessibility and search engines.
<head>: Contains meta-information about the HTML
document, such as the character set, viewport settings, title,
links to stylesheets, and scripts. This information is not
displayed on the page itself but is crucial for the browser and
other services. <meta charset="UTF-8">: Specifies the
character encoding for the document, typically set to UTF-8 for
broad character support.
<meta name="viewport" content="width=device-width,
initial-scale=1.0">: Configures the viewport for responsive
web design, ensuring the page scales correctly on different
devices.
<title>My Web Page</title>: Sets the title that appears in
the browser tab or window title bar.
<body>: Contains the visible content of the HTML document,
such as text, images, links, and other multimedia.
2. Elements and Tags:
HTML content is structured using elements, which are
defined by tags:
Tags: Keywords enclosed in angle brackets (< and >).
Start Tag: Marks the beginning of an element (e.g., <h1>).
End Tag: Marks the end of an element and has a forward
slash before the element name (e.g., </h1>). Most elements
have both start and end tags.
Empty Elements (Void Elements): Some elements don't
have content and only have a start tag (and sometimes a
self-closing slash, though it's optional in HTML5). Examples
include <br> (line break), <hr> (horizontal rule), and
<img> (image).
Elements: Consist of a start tag, content (if any), and
an end tag (for non-empty elements). For example,
<h1>This is a heading</h1> is an h1 element.
Case-Insensitivity: HTML5 tag names are case-
insensitive (e.g., <h1> and <H1> are the same), but
it's a common best practice to use lowercase for
consistency and readability.
ATTRIBUTES
HTML5 attributes provide additional
information about HTML elements. They
modify the behavior, appearance, or identity
of elements. Attributes are always specified
in the start tag of an element.
Here's a breakdown of key aspects of HTML5
attributes:
1. Syntax:
destination.
"[Link] is the value of
document.
class: Specifies one or more class names for an element,
used for styling with CSS and manipulation with JavaScript.
style: Allows inline CSS styling of an element (generally
discouraged for maintainability).
title: Provides extra information about an element, often
displayed as a tooltip on hover.
lang: Specifies the language of the element's content.
dir: Specifies the text direction (left-to-right or right-to-left).
tabindex: Specifies the tab order of an element.
draggable: Specifies whether an element is draggable.
hidden: Specifies that an element is not yet, or is no longer,
relevant.
data-*: Custom data attributes that allow you to store
private data specific to the element.
EXAMPLE OF GLOBAL ATTRIBUTES:
<div id="main-content" class="container primary" title="Main
section of the page">
<p lang="en">This is some English text.</p>
</div>
some examples:
1. Window Events: These events are triggered on the window
object.
onload: Triggered once the entire page (including all resources
default values.
onfocus: Triggered when an element (like an
clicked.
onmousedown: Triggered when a mouse button is
character-producing keys).
onkeyup: Triggered when a key is released.
changes.
onseeking: Triggered when the user starts moving to a new
changes.
ontimeupdate: Triggered when the current playback position of
downloading.
oncanplay: Triggered when the browser can
drag an element.
ondrag: Triggered while an element is being
dragged.
ondragenter: Triggered when a dragged element
finished.
[Link] background:
div {
background-image: url("[Link]");
}
Styling SVG
You can style SVG using CSS:
<svg width="100" height="100">
<circle class="my-circle" cx="50" cy="50" r="40" />
</svg>
Benefits of SVG
•Scalable: No loss of quality when
<style> zoomed.
.my-circle { •Lightweight: Often smaller than raster
images.
fill: orange; •Interactive: Can be animated or
stroke: black; scripted.
stroke-width: 3; •Accessible: Works well with screen
readers if properly labeled.
}
</style>
SVG (SCALABLE VECTOR GRAPHICS)
IN HTML5, SVG (SCALABLE VECTOR GRAPHICS) IS USED TO DEFINE VECTOR-BASED
GRAPHICS FOR THE WEB. SVG IS AN XML-BASED MARKUP LANGUAGE THAT CAN BE
EMBEDDED DIRECTLY INTO HTML DOCUMENTS. IT ALLOWS FOR RESOLUTION-
INDEPENDENT, SCALABLE, AND INTERACTIVE GRAPHICS, MAKING IT IDEAL FOR
RESPONSIVE WEB DESIGN, DATA VISUALIZATIONS, ICONS, AND MORE.
</body>
Element Description
<svg> The container element
<circle> A circle
<rect> A rectangle
<line> A line
<ellipse> An ellipse
A closed shape with multiple
<polygon>
sides
A complex shape using
<path>
commands
<text> Text inside SVG
Embedding SVG
[Link] SVG (recommended for dynamic or styled content):
<svg>...</svg>
2. Object tag:
<object type="image/svg+xml" data="[Link]"></object>
[Link] tag (no interactivity):
<img src="[Link]" alt="My SVG" />
Web Storage
Web Storage in HTML5 provides a way to store data in the user's
browser, making it possible to save data locally without needing a
server or cookies.
There are two main types:
1. localStorage
•Stores data with no expiration time.
•Data persists even after the browser is closed and reopened.
•Stored per domain
// Store data
[Link]("username", "John");
// Retrieve data
let user = [Link]("username");
[Link](user); // John
Basic Syntax
<canvas id="myCanvas" width="400" height="200"></canvas>
<script>
// Get the canvas element
const canvas = [Link]("myCanvas");
const ctx = [Link]("2d"); // 2D rendering context
<audio controls>
<source src="song.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
•controls: Displays playback controls (play, pause, volume).
•autoplay, loop, muted: Optional attributes to control behavior
<video> Element
<video width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
•ontrols: Shows default playbar.
•width and height: Set dimensions.
•autoplay, loop, muted, poster: Additional optional
attributes.
•poster: Placeholder image shown before playback
starts.
Example with Poster and Multiple Sources
<video controls width="600"
poster="[Link]">
<source src="video.mp4"
type="video/mp4">
<source src="[Link]"
type="video/webm">
Your browser does not support the video tag.
</video>
COMMON MEDIA ATTRIBUTES
Attribute Description
Displays play, pause, and
controls
volume controls
Plays automatically when page
autoplay
loads
loop Repeats playback automatically
Starts playback with audio
muted
muted
(Video only) Image shown
poster
before video plays
Suggests whether to preload
preload
media (auto, metadata, none)
<button
onclick="[Link]('myVideo').play()">Play</button
>
<button
Geolocation
HTML5 provides a Geolocation API that allows websites to access the user's geographical location (with their permission). It is useful for mapping,
directions, location-based services, and more.
Get Current Position
<button onclick="getLocation()">Get My Location</button>
<p id="output"></p>
<script>
function getLocation() {
if ([Link]) {
[Link](showPosition, showError);
} else {
[Link]("output").innerText = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
const lat = [Link];
const lon = [Link];
[Link]("output").innerText = `Latitude: ${lat}, Longitude: ${lon}`;
}
function showError(error) {
switch([Link]) {
case error.PERMISSION_DENIED:
alert("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case [Link]:
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
Geolocation Methods
Description
Method
getCurrentPosition() Gets current position (once)
watchPosition() Tracks position continuously
Stops tracking initiated by
clearWatch()
watchPosition()
WATCH POSITION
LET WATCHID =
[Link](FUNCTION(POSITIO
N) {
[Link]("LAT: " + [Link] +
", LON: " + [Link]);
});
YOU CAN STOP WATCHING LIKE THIS:
[Link](WATCHID);
PRIVACY & PERMISSIONS
BROWSERS ASK FOR USER PERMISSION BEFORE SHARING LOCATION.
WORKS BEST ON HTTPS (MANDATORY IN MOST MODERN BROWSERS).
ACCURACY VARIES: GPS, WIFI, IP, AND OTHER SIGNALS.
Drag & Drop
HTML5 provides built-in drag-and-drop support through JavaScript and the
Drag and Drop API, allowing users to grab elements and move them around
within or across web pages.
The Drag and Drop API consists of:
<script>
const dragMe = [Link]("dragMe");
const dropZone = [Link]("dropZone");
[Link]("dragstart", function(e) {
[Link]("text/plain", "dragMe");
});
[Link]("dragover", function(e) {
[Link](); // Must prevent default to allow drop
});
[Link]("drop", function(e) {
[Link]();
const draggedId = [Link]("text");
const draggedElement = [Link](draggedId);
[Link](draggedElement);
});
</script>
</body>
IMPORTANT ATTRIBUTES &
EVENTS
Attribute/Event Description
draggable="true" Makes an element draggable
Triggered when dragging
dragstart
begins
Must call [Link]() to
dragover
allow drop
drop Handles the drop action
Used to store data associated
dataTransfer
with the drag
•Only elements with draggable="true" can be dragged.
•You can style elements with :dragging pseudo-class via JavaScript.
•For complex behavior (like reordering items or uploading files), use
libraries or combine with other APIs.
WEB WORKERS
WEB WORKERS ARE A FEATURE IN MODERN WEB DEVELOPMENT THAT ALLOWS YOU TO RUN
JAVASCRIPT IN THE BACKGROUND, SEPARATE FROM THE MAIN UI THREAD. THIS PREVENTS THE
[Link] = function(e) {
[Link]("Result from worker:", [Link]);
};
USE IT IN MAIN FILE ([Link] OR [Link])
const worker = new Worker('[Link]');
[Link](10); // Send data to worker
Limitations
[Link] = function(e) { No access to
[Link]("Result from worker:", [Link]); DOM directly from
}; a worker
Needs to
Real-World Use Cases
communicate with
Image or video processing in the browser
the main thread
Complex mathematical calculations
via messages
Parsing large JSON or CSV files Files must be
Handling offline data syncing served over
HTTP/HTTPS (not
Real-time data visualization and transformation
from local [Link]
WORKING WITH FONTS
FONTS ARE A VITAL PART OF WEB DESIGN THAT AFFECT READABILITY, USER
EXPERIENCE, AND OVERALL AESTHETICS. YOU CAN STYLE AND CUSTOMIZE
FONTS USING HTML AND CSS.
font-family: 'Roboto',
font-family Sets the font type
sans-serif;
Vertical spacing
line-height line-height: 1.5;
between lines
Space between
letter-spacing letter-spacing: 1px;
letters
Change case
text-transform:
text-transform (uppercase/lowercase
uppercase;
)
Using Web Fonts (e.g., Google Fonts)
1. Import via <link> (HTML)
<link href="[Link] rel="stylesheet">
2. Use in CSS
body {
font-family: 'Roboto', sans-serif;
}
Font Stack (Fallbacks)
font-family: 'Open Sans', Arial, sans-serif;
Custom Fonts with @font-face
@font-face {
font-family: 'MyFont';
src: url('fonts/MyFont.woff2') format('woff2');
}
body {
font-family: 'MyFont', sans-serif;
}
Example in HTML + CSS
<!DOCTYPE html>
<html>
<head>
<link href="[Link]
family=Poppins&display=swap" rel="stylesheet">
<style> Best Practices
h1 { Use web-safe fonts
as fallbacks.
font-family: 'Poppins', sans-serif; Limit the number of
font-size: 36px; fonts to 2–3 max to
color: #4A90E2; maintain performance
and visual harmony.
} Use Google Fonts or
</style> Adobe Fonts for
</head> quality, free font
libraries.
<body>
Check accessibility:
<h1>Custom Font Example</h1> ensure fonts are
</body> readable at different
sizes and screen
</html>
resolutions.
WORKING WITH OTHER GRAPHICS
Graphic
Description Example Use
Type
Raster files like JPG, PNG, WebP,
Images Backgrounds, photos
etc.
VG
(Scalable XML-based, scalable without Icons, logos,
Vector loss of quality illustrations
Graphics)
HTML element for drawing with Games, graphs,
Canvas
JavaScript animations
3D graphics API using the GPU 3D visualizations,
WebGL
via Canvas simulations
CSS Shapes created using HTML + Buttons, loaders, UI
Graphics CSS elements
Icons
Navigation, UI
(e.g. Font Icon sets as fonts or SVG
controls
Awesome)
IN MODERN WEB DESIGN, GRAPHICS ARE ESSENTIAL FOR ENHANCING VISUAL APPEAL,
USER ENGAGEMENT, AND COMMUNICATION. BESIDES FONTS AND IMAGES, YOU CAN
WORK WITH SVGS, CANVAS, WEBGL, ICONS, AND CSS-BASED GRAPHICS.
<script>
const c =
[Link]("myCanvas");
const ctx = [Link]("2d");
[Link] = "red";
[Link](20, 20, 150, 75);
</script>
4. WebGL for 3D Graphics
WebGL works inside the <canvas> element using
JavaScript.
<canvas id="webglCanvas"></canvas>
<!-- You’ll need a library like [Link] for easy use -->
5. CSS Shapes and Animations
<div class="circle"></div>
<style>
.circle {
width: 100px;
height: 100px;
background-color: coral;
border-radius: 50%;
}
</style>
Best Practices
Optimize image sizes for faster load times
scalability.
Prefer CSS and vector graphics over heavy
SEO.
Style sheets: Introduction CSS
CSS (Cascading Style Sheets) is the language used to style HTML documents. It
controls the layout, color, font, spacing, and overall visual presentation of web
pages.
Why Use CSS?
Separates content (HTML) from presentation (CSS)
Enables responsive and visually appealing designs
Allows consistent styling across multiple pages
Basic Syntax of CSS
selector {
property: value;
}
Example:
p{
color: blue;
font-size: 16px;
}
3 Ways to Use CSS
1. Inline CSS (inside HTML tag)
<p style="color: blue; font-size: 18px;">This is blue text with inline CSS.</p>
2 . Internal CSS
Style is added directly to an HTML element using the style attribute.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: green;
text-align: center;
}
p{
font-size: 16px;
color: gray;
}
</style>
</head>
<body>
<h1>Internal CSS Example</h1>
<p>This paragraph uses internal CSS.</p>
</body>
</html>
3. External CSS
body { Best Practice:
Use external CSS for large
background-color: #f0f0f0; projects, internal CSS for
font-family: Arial; small page-specific styling,
} and inline CSS only for
quick testing or dynamic
h2 { changes.
color: navy; Would you like a sample
} styled webpage combining
all 3 methods?
[Link]
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="[Link]">
</head>
<body>
<h2>External CSS Example</h2>
</body>
</html>