Unit 3
Unit 3
In HTML5, multimedia tags are used to embed audio, video, and other types of multimedia content
into web pages. These tags provide a standardized way of playing multimedia content across different
browsers and devices. However, multimedia tags are not just for playback; they also serve as a way to
organize and manage multimedia content.
In HTML5, there are several multimedia tags that can be used to embed different types of media, such
as audio and video, into web pages. These tags include:
1. <audio>- This tag is used to embed audio files, such as music or podcasts, into web pages.
2. <video>- This tag is used to embed video files, such as movies or TV shows, into web pages.
1. <source>- This tag is used to specify alternative versions of media files, such as different formats
or bitrates, which the browser can choose from based on the user's device and internet connection.
2. <track>- This tag is used to add subtitles or captions to video or audio files.
3. <picture>- This tag is used to specify different versions of an image that can be displayed
depending on the user's device and screen size.
3.1.1Audio Tag
One of the most important multimedia tags in HTML5 is the <audio>tag. This tag is used to embed
audio content into web pages. It supports several audio formats, such as MP3, OGG, and WAV. The
tag has several attributes, including srcto specify the location of the audio file and controlsto display
the default audio player controls. Here's an example:
</audio>
In this example, the srcattribute specifies the location of the audio file audiofile.mp3, while the
controlsattribute displays the default audio player controls. If the browser does not support the
<audio>tag, it will display the text between the opening and closing tags.
The <video>tag is used to embed video files in a web page. It supports several video formats, such as
MP4, WebM, and OGG. The tag has several attributes, including srcto specify the location of the
video file and controlsto display the default video player controls. Here's an example:
</video>
In this example, the srcattribute specifies the location of the video file videofile.mp4, while the
controlsattribute displays the default video player controls. If the browser does not support the
<video>tag, it will display the text between the opening and closing tags.
• autoplay: automatically starts playing the video when the page loads
• widthand height: specifies the dimensions of the video display area in pixels
The <source>tag is used to specify alternative versions of a multimedia file, such as different formats
or bitrates, that the browser can choose from based on the user's device and internet connection. The
tag has several attributes, including srcto specify the location of the multimedia file and typeto specify
the MIME type of the file. Here's an example:
<video controls>
</video>
In this example, the <video>tag includes two <source>tags with different video formats (mp4and
webm). The browser will choose the appropriate format based on the user's device and internet
connection. If the browser does not support the <video>tag, it will display the text between the
opening and closing tags.
The <track>tag is used to add subtitles or captions to a video or audio file. The tag has several
attributes, including srcto specify the location of the subtitles file, kindto specify the type of subtitles
(e.g., subtitlesor captions), and srclangto specify the language of the subtitles. Here's an example:
<video controls>
</video>
In this example, the <video>tag includes a <track>tag with the location of the subtitles file
(subtitles.vtt), the type of subtitles (subtitles), and the language of the subtitles (en). If the browser
does not support subtitles, they will not be displayed.
The <picture>tag is used to specify different versions of an image that can be displayed depending on
the user's device and screen size. It includes one or more <source>tags with different image sources
and media queries that specify the conditions under which the image should be displayed. Here's an
example:
<picture>
</picture>
In this example, the <picture>tag includes two <source>tags with different image sources and media
queries that specify the conditions under which the image should be displayed. The first <source>tag
specifies that the large image.jpg file should be used for devices with a minimum width of 1200
pixels, while the second <source>tag specifies that the medium image.jpg file should be used for
devices with a minimum width of 768 pixels. If neither of these conditions is met, the <img>tag will
display the small image.jpgfile.
Note that the <picture>tag is not supported in all browsers, so it's important to include a fallback
image using the <img>tag. Additionally, it's important to optimize images for the web to ensure fast
loading times and good performance.
• <source>tags: the same attributes as for the <source>tag in the <video>tag, plus the media
attribute, which specifies the conditions under which the image should be displayed
• <img>tag: the same attributes as for the <img>tag in HTML, such as src, alt, width, and height
A website can be divided into various sections comprising of header, menus, content, and footer based
on which there are many different layout designs available for developers. Different layouts can be
created by using a div tag and using CSS property to style it. The most common structure of website
layout is given below:
Notice: Header section contains a website logo, a search bar and profile of user. The navigation menu
contains link to various categories of articles available and content section is divided into 3
parts(columns) with left and right sidebar containing links to other articles and advertisements
whereas the main content section is the one containing this article, then at the bottom there is a footer
section which contains address, links, contacts etc.
1. Header Section: The header section is generally placed either at the top of the Website or just
below a top navigation menu. It often comprises of the name of the Website or the logo of the
Website.
2. Navigation Menu: A Navigation Bar/Menu is basically a list of links that allows visitor to
navigate through the website comfortably with easy access.
3. Content Section: The content section is the main body of the website. The user can divide the
content section in an n-column layout. The most common layouts are:
The user can also create a responsive layout where the layout will get changed as per screen size.
Consider the below example where if the idth of the screen is more than 600px then there will be a
3-column layout and if the width of the screen is between 400px to 600px then there will be a
2-column layout and if the screen size is less than 400px then the 1-column layout will display.
1. Footer Section: A footer section is placed at the bottom of the webpage and it generally consists
of information like contact info, copyrights, About us etc.
Supported Browser:
• Google Chrome
• Internet Explorer
• Firefox
• Opera
• Safari
Example:
<!DOCTYPE html>
<html>
<head>
<title>
Website Layout
</title>
<style>
*{
box-sizing: border-box;
}
/* CSS property for header section */
.header {
background-color: green;
padding: 15px;
text-align: center;
}
/* CSS property for navigation menu */
.nav_menu {
overflow: hidden;
background-color: #333;
}
.nav_menu a {
float: left;
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: white;
color: green;
}
/* CSS property for content section */
.columnA,
.columnB,
.columnC {
float: left;
width: 31%;
padding: 15px;
text-align: justify;
}
h2 {
color: green;
text-align: center;
}
/* Media query to set website layout
according to screen size */
@media screen and (max-width:600px) {
.columnA,
.columnB,
.columnC {
width: 50%;
}
}
@media screen and (max-width:400px) {
.columnA,
.columnB,
.columnC {
width: 100%;
}
}
</style>
</head>
<body>
<!-- header of website layout -->
<div class="header">
<h2 style="color:white;font-size:200%">
GeeksforGeeks
</h2>
</div>
<!-- navigation menu of website layout -->
<div class="nav_menu">
<a href="#">Algo</a>
<a href="#">DS</a>
<a href="#">Language</a>
</div>
<!-- Content section of website layout -->
<div class="row">
<div class="columnA">
<h2>Column A</h2>
<p>
Prepare for the Recruitment drive of product
based companies like Microsoft, Amazon, Adobe
etc with a free online placement preparation
course. The course focuses on various MCQ's
& Coding question likely to be asked in the
interviews & make your upcoming placement
season efficient and successful.
</p>
</div>
<div class="columnB">
<h2>Column B</h2>
<p>
Prepare for the Recruitment drive of product
based companies like Microsoft, Amazon, Adobe
etc with a free online placement preparation
course. The course focuses on various MCQ's
& Coding question likely to be asked in the
interviews & make your upcoming placement
season efficient and successful.
</p>
</div>
<div class="columnC">
<h2>Column C</h2>
<p>
Prepare for the Recruitment drive of product
based companies like Microsoft, Amazon, Adobe
etc with a free online placement preparation
course. The course focuses on various MCQ's
& Coding question likely to be asked in the
interviews & make your upcoming placement
season efficient and successful.
</p>
</div>
</div>
</body>
</html>
This often meant a separate website for mobile devices and larger screens, with the same server
system but different domains.The original website, for example, could be examplewebsite.com, and
the mobile version would be examplewebsite.mobi, or m.examplewebsite.com. The user's device
would be detected by ready-made scripts and then the appropriate domain would be rendered. This
practice still exists today.
Apart from the two-domain method, web designers and developers can create a website for a
particular screen size first (it could be desktop, tablet, or mobile), and then add what are called media
queries to make the website adapt to different screen sizes. This is the mobile-first approach.
This tells the browser to execute the CSS code written within the media query when the screen width
is below a 720 pixel breakpoint. The breakpoint can usually be any value between 1200 pixels and
320 pixels.
Example:
@media screen and (max-width: 768px) {
body {
background-color: #333;
color: #3498db;
}
}
Here, we are instructing the browser to change the background-color to dark-grey, and the color to
blue when the screen width is below 768 pixels.
Some extra-large screens and TVs can take more than 1200px.
Example:
@media screen and (max-width: 768px) {
p{
font-size: 1.5rem;
}
}
img {
display: block;
max-width: 100%;
}
Another way to make images responsive is to use the picture element in HTML. With this element,
you can tell the browser to display different images that correlate to the width on different devices.
<picture>
<source
media="(max-width: 1100px)"
srcset=" logo.jpg"
/>
<source
media="(max-width: 900px)"
srcset=" logo.jpg"
/>
<source media="(max-width: 760px)"
srcset=" logo.jpg" />
<img
src=" logo.jpg"
alt=" Logo "
style="max-width: 100%"
/>
</picture>
3.3.4.1 Flexbox
With CSS flexbox, responsive design gained more relevance because, with it, you don't have to add
too many media queries unlike when you use floats for a layout.
Immediately when a display of flex is assigned to the containing element, the element direction is
rendered on the row by default.
You can later use a media query to set the direction to a column for smaller screens with the
flex-direction property. The flex-direction property value has to be explicitly set to a column.
You can also layout the way you want the content on the web page to render with properties such as
flex-grow and flex-shrink. These two properties make the element they contain grow as the screen
viewport (width) increases and shrink as the viewport decreases. How cool is that?
In the code snippets below, the direction of the different pieces of text in their respective containers
will be a row on screens higher than 768 pixels in width, and a column when the width is lower than
768 pixels.
We were able to do it by displaying the whole items inside the body element as flex.
Example:
Program.html
<body>
<div class="container-one">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
mollitia, consequuntur aliquid nobis vitae soluta maiores expedita ipsam
delectus molestiae!
</p>
</div>
<div class="container-two">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Consectetur
architecto temporibus sed officiis vero, quisquam, corrupti quis veritatis
dolor amet nostrum quam! Voluptates nam architecto enim neque nemo
consectetur molestias unde fugit dolorum alias temporibus expedita
doloribus deserunt laborum asperiores illum saepe, voluptate rerum quia
sit facilis consequuntur perferendis aperiam. Nobis reiciendis debitis
consequuntur placeat maiores voluptas, quos esse eum.
</p>
</div>
<div class="container-three">
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Minus fugiat,
nemo rem facere cumque error. Aliquam consequatur nobis cupiditate atque!
Fugiat amet facere magni, nulla pariatur ut ullam, vel est eum voluptatum
dicta quis dignissimos labore repellendus. Maiores deserunt quas tempore
impedit, corporis quae amet blanditiis voluptatum laudantium magni ipsa!
</p>
</div>
</body>
Style.css
body {
display: flex;
}
div {
border: 2px solid #2ecc71;
margin-left: 6px;
}
@media screen and (max-width: 768px) {
body {
flex-direction: column;
}
}
Style.css
body {
display: grid;
grid-auto-flow: column;
gap: 6px;
}
div {
border: 2px solid #2ecc71;
margin-left: 6px;
}
@media screen and (max-width: 768px) {
body {
grid-auto-flow: row;
}
}
What is JavaScript ?
• Client-side: It supplies objects to control a browser and it’s Document Object Model (DOM).
Like if client-side extensions allow an application to place elements on an HTML form and respond to
user events such as mouse clicks, form input, and page navigation. Useful libraries for the client
side are AngularJS, ReactJS, VueJS, and so many others.
• Server-side: It supplies objects relevant to running JavaScript on a server. For if the
server-side extensions allow an application to communicate with a database, and provide continuity of
information from one invocation to another of the application, or perform file manipulations on a
server. The useful framework which is the most famous these days is node.js.
• Imperative language – In this type of language we are mostly concerned about how it is to be
done. It simply controls the flow of computation. The procedural programming approach,
object-oriented approach comes under.
• Declarative programming – In this type of language we are concerned about how it is to be
done; basically, here logical computation requires. Her main goal is to describe the desired result
without direct dictation on how to get it as the arrow function does.
Syntax:
<script>
// JavaScript Code
</script>
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Basic Example to Describe JavaScript
</title>
</head>
<body>
<!-- JavaScript code can be embedded inside
head section or body section -->
<script>
console.log("Welcome to India");
</script>
</body>
</html>
• Machine Learning: This JavaScript ml5.js library can be used in web development by using
machine learning.
• Mobile Applications: JavaScript can also be used to build an application for non-web
contexts. The features and uses of JavaScript make it a powerful tool for creating mobile applications.
This is a Framework for building web and mobile apps using JavaScript. Using React Native, we can
build mobile applications for different operating systems. We do not require to write code for different
systems. Write once use it anywhere!
jQuery Features
Following are the important features of jQuery.
• HTML manipulation
• DOM manipulation
• DOM element selection
• CSS manipulation
• Effects and Animations
• Utilities
• AJAX
• HTML event methods
• JSON Parsing
• Extensibility through plug-ins
So, you can say that out of the lot of JavaScript frameworks, jQuery is the most popular and the most
extendable. Many of the biggest companies on the web use jQuery.
Some of these companies are:
• Microsoft
• Google
• IBM
• Netflix
Downloading jQuery
There are two versions of jQuery available for downloading:
• Production version - this is for your live website because it has been minified and compressed
• Development version - this is for testing and development (uncompressed and readable code)
Tip: Place the downloaded file in the same directory as the pages where you wish to use it.
jQuery CDN
If you don't want to download and host jQuery yourself, you can include it from a CDN (Content
Delivery Network).
Google is an example of someone who host jQuery:
Google CDN:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
Tip: The jQuery team has also created an even shorter method for the document ready event:
$(function(){
// jQuery methods go here...
});
Example
When a user clicks on a button, the element with id="test" will be hidden:
Example
$(document).ready(function(){
$("button").click(function(){
$("#test").hide();
});
});
Example
When a user clicks on a button, the elements with class="test" will be hidden:
Example
$(document).ready(function(){
$("button").click(function(){
$(".test").hide();
});
});
The term "fires/fired" is often used with events. Example: "The keypress event is fired, the moment
you press a key".
Here are some common DOM events:
1. click()
The click() method attaches an event handler function to an HTML element.
The function is executed when the user clicks on the HTML element.
The following example says: When a click event fires on a <p> element; hide the current <p>
element:
Example
$("p").click(function(){
$(this).hide();
});
2 dblclick()
The dblclick() method attaches an event handler function to an HTML element.
The function is executed when the user double-clicks on the HTML element:
Example
$("p").dblclick(function(){
$(this).hide();
});
3 mouseenter()
The mouse enter() method attaches an event handler function to an HTML element.
The function is executed when the mouse pointer enters the HTML element:
Example
$("#p1").mouseenter(function(){
alert("You entered p1!");
});
4. mouseleave()
The mouseleave() method attaches an event handler function to an HTML element.
The function is executed when the mouse pointer leaves the HTML element:
Example
$("#p1").mouseleave(function(){
alert("Bye! You now leave p1!");
});
5. mousedown()
The mousedown() method attaches an event handler function to an HTML element.
The function is executed, when the left, middle or right mouse button is pressed down, while the
mouse is over the HTML element:
Example
$("#p1").mousedown(function(){
alert("Mouse down over p1!");
});
6 mouseup()
The mouseup() method attaches an event handler function to an HTML element.
The function is executed, when the left, middle or right mouse button is released, while the
mouse is over the HTML element:
Example
$("#p1").mouseup(function(){
alert("Mouse up over p1!");
});
7. hover()
The hover() method takes two functions and is a combination of the mouseenter() and mouseleave()
methods.
The first function is executed when the mouse enters the HTML element, and the second function is
executed when the mouse leaves the HTML element:
Example
$("#p1").hover(function(){
alert("You entered p1!");
}, function(){
alert("Bye! You now leave p1!");
});
8. focus()
The focus() method attaches an event handler function to an HTML form field.
The function is executed when the form field gets focus:
Example
$("input").focus(function(){
$(this).css("background-color", "#cccccc");
});
9. blur()
The blur() method attaches an event handler function to an HTML form field.
The function is executed when the form field loses focus:
Example
$("input").blur(function(){
$(this).css("background-color", "#ffffff");
});
4. Game
JavaScript is also used for creating games. It has various libraries and frameworks for creating a
game. The game can either be a 2D or 3D. Some JavaScript game engines such as PhysicsJS,
Pixi.js help us to create a web game. We can also use the WebGL (web graphics library), which is
the JavaScript API to render 2D and 3D images on browsers.
5. Presentations
JavaScript also helps us to create presentations as a website. The libraries, such as RevealJs, and
BespokeJs, can be used to create a web-based slide deck. They are easier to use, so we can easily
make something amazing in a short time.
The Reveal.js is used to create interactive and beautiful slide decks with the help of HTML. These
presentations work great with mobile devices and tablets. It also supports all of the CSS color
formats. The BespokeJS includes animated bullet lists, responsive scaling, and a wide variety of
features.
6. Server Applications
A large number of web applications have a server-side to them. JavaScript is used to generate
content and handle HTTP requests. JavaScript can also run on servers through Node.js. The
Node.js provides an environment containing the necessary tools required for JavaScript to run on
servers.
Frames are a very advanced new feature that provides an entirely different way of looking at Web
pages. However, they are also currently supported only in Netscape 2.0, and even worse, pages
created using frames are not easily backward-compatible with other browsers.
</HTML>
<HEAD>
<TITLE>Target Parent Window</TITLE>
<BASE TARGET="first_window"> <!-- add BASE TARGET="value" here -->
</HEAD>
<BODY>
<H1>Target Parent Window</H1>
<P>
<A HREF="target2.html">Open</A> <!-- no need to include a TARGET -->
a new window called first_window. <BR>
<A HREF="target3.html" TARGET="second_window">Open</A>
a new window called second_window.
</P>
<P>
<A HREF="target4.html">Load</A> <!-- no need to include a TARGET -->
some new text into first_window.
</P>
</BODY>
</HTML>
In this case, target2.html and target4.html are loaded into the default window assigned by the
<BASE> tag; target3.html overrides the default by defining its own target window.
You can also override the window assigned by the <BASE> tag by using one of two special
window names. If you use TARGET="_blank" in a hyperlink, a new browser window is opened
that does not have a name associated with it. Alternatively, if you use TARGET="_self", the
current window is used rather than the one defined by the <BASE> tag.
The frame definition document is the page that contains the layout of each frame and the names
of the HTML documents that will fill that frame.
A frameset is the set of frames defined by the <FRAMESET> tags in the frame definition
document
2 The COLS Attribute
When you define a <FRAMESET> tag, you must include one of two attributes as part of the tag
definition. The first of these attributes is the COLS attribute, which takes the following form:
Tip: To define a frameset with three equal-width columns, use COLS="*, *, *". This way, you won't
have to mess around with percentages, because Netscape automatically gives an equal amount of
space to each frame assigned an * width.
<FRAMESET ROWS="50%,50%">
<FRAMESET ROWS="*, *">
Note: If you try either of the preceding examples for yourself, you'll find that the <FRAMESET> tag
does not appear to work. The reason for this is that currently no contents are defined for the rows or
columns in the frameset. To define the contents, you need to used the <FRAME> tag,
<FRAMESET ROWS="*,*,*">
<FRAME SRC="document1.html">
<FRAME SRC="document2.html">
<FRAME SRC="document3.html">
</FRAMESET>
In this example, a frameset with three equal-height horizontal frames has been defined. The contents
of document1.html are displayed in the first frame, document2.html in the second frame, and
document3.html in the third frame
5 Additional Attributes
A few extra attributes can be assigned to a <FRAME> tag to give you additional control over how the
user interacts with your frames. Below table presents the details about them.
Control attributes for the <FRAME> tag.
<HTML>
<HEAD>
<TITLE>Page Title</TITLE>
</HEAD>
<FRAMESET>
your frame definition goes here.
<NOFRAME>
Include any text, hyperlinks, and tags you want to here.
</NOFRAME>
</FRAMESET>
</HTML>
None of the text you include inside the <NOFRAME> block will be displayed by Netscape 2.0, but
when the page is loaded into a Web browser that does not support frames, it will be displayed. Using
both frames' content and tags inside <NOFRAME>, you can create pages that work nearly well with
both kinds of browsers.
Doing this splits the screen into two sections: a small frame at the bottom of the screen that is 80
pixels high, and a large frame at the top of the screen that uses the rest of the available space. Two
<FRAME> tags have also been defined to represent the contents of each frame.
The embedded COLS frameset defines two columns, the first being 30 percent of the width of the
embedded frame area and the second taking up all the remaining space in the embedded frame area. In
addition, two <FRAME> tags are embedded inside the <FRAMESET> block to define the contents of
each column.
Note: When used inside an embedded frameset, any percentage sizes are based on a percentage of the
total area of the embedded frame and not as a percentage of the total screen.
How to create framesets and link them together by using the tags listed in Table below
New tags discussed in this chapter.
Tag Attribute Description
<BASE Set the global link window for a
TARGET="window document.
">
<FRAMESET> Define the basic structure of a frameset.
• Improve SEO. Google uses mobile-first indexing, which means it crawls the mobile
version of your website and chooses how to rank you based on the content and structure of
your mobile site.
• Use location services. Unlike the generally static location of desktop devices,
smartphone locations constantly change. Location services help mobile websites serve
specific, location-based content or targeted ads.
• Consider download speed. Designing a website that takes speed into account
enhances the on-the-go mobile UX. Choose a minimalist design to improve load times.
The right imagery can be the difference between making a sale or losing a customer, so
ensure your images have the chance to shine no matter what device they’re viewed on.