Image
Image
HTML Images
• The <img> tag is used to embed an image in an HTML page.
• The src attribute specifies the path to the image to be displayed.
Example:
<!DOCTYPE html>
<html>
<body>
<h3>src Attribute</h3>
<img src="C:\Users\DELL\Desktop\flower.jpg" width="50" height="65">
</body>
</html>
• The <img> tag should also contain the width and height attributes, which specify the width and
height of the image (in pixels).
• The required alt attribute for the <img> tag specifies an alternate text
for an image, if the image for some reason cannot be displayed. This
can be due to a slow connection, or an error in the src attribute, or if
the user uses a screen reader.
• Example:
<img src="C:\Users\DELL\Desktop\flower.jpg" alt="beautiful flowers"
width="50" height="65">
Image as a Link
<!DOCTYPE html>
<html>
<body>
<a href="hello.html">
<img src="C:\Users\DELL\Desktop\flower.jpg" width="50" height="65">
</a>
</body>
</html>
• Image Floating
The CSS float property to let the image float to the right or to the left of
a text:
<p>
<img src="C:\Users\AGRIMA\Desktop\flower.jpg" width="50"
height="65" style="float:right;width:50px;height:40px;">
This is image floating
</p>
Image Maps
• The HTML <map> tag defines an image map. An image map is an image with clickable areas. The
areas are defined with one or more <area> tags.
• In an image map, you should be able to perform different actions depending on where in the
image you click.
• The image is inserted using the <img> tag. The only difference from other images is that you must
add a usemap attribute:
• The name attribute must have the same value as the <img>'s usemap attribute .
• You must define the shape of the clickable area, and you can choose one of these values:
• It is a good idea to always include width and height attributes. If height and width
are not set, the page might flicker while the video loads.
• The <source> element allows you to specify alternative video files which the
browser may choose from. The browser will use the first recognized format.
• The text between the <video> and </video> tags will only be displayed in
browsers that do not support the <video> element.
• Example:
<!DOCTYPE html>
<html>
<body>
<video width="320" height="240" controls>
<source src="C:\Users\AGRIMA\Downloads\video.mp4" type="video/mp4"
Your browser does not support this video tag.
</video>
</body>
</html>
• Add muted after autoplay to let your video start playing automatically (but muted):
Example: <video width="450" height="320" autoplay muted>
HTML Youtube Video
• Upload the video to YouTube
• Take a note of the video id
• Define an <iframe> element in your web page
• Let the src attribute point to the video URL
• Use the width and height attributes to specify the dimension of the player
• Add any other parameters to the URL
• Example:
• <body>
• <iframe width="560" height="315" src="https://www.youtube.com/embed/By_rtKFZWQo?
si=wMox60xlyrNtDbCS" title="YouTube video player" frameborder="0" allow="accelerometer;
autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin" allowfullscreen>
• </iframe>
• </body>
• Example:
<iframe width="560" height="315" src="https://www.youtube.com/embed/By_rtKFZWQo?
si=wMox60xlyrNtDbCS" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay;
clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-
when-cross-origin" style="border:2px green solid;" allowfullscreen>
</iframe>
• Some browsers do not allow autoplay in most cases. However, muted autoplay is suggested to be used.
Add mute=1 after autoplay=1 to let your video start playing automatically (but muted).
Example:
<body>
</body>
HTML Audio
• The HTML <audio> element is used to play an audio file on a web page.
• The controls attribute adds audio controls, like play, pause, and volume.
• The <source> element allows you to specify alternative audio files which the browser may choose from. The browser will use the first
recognized format.
• The text between the <audio> and </audio> tags will only be displayed in browsers that do not support the <audio> element.
• Example:
<body>
<audio controls>
<source src="newyear.mp3" type="audio/mpeg">
Your browser does not support this audio.
</audio>
• Some browsers do not allow autoplay in most cases. However, muted autoplay is suggested.
• Add muted after autoplay to let your audio file start playing automatically (but muted):
• Example:
<audio controls autoplay muted>
Animated Images
• HTML allows animated GIFs:
• Example:
<img src="food.gif" alt="Family Dinner" style="width:50px;height:50px;">
Iframes
• An HTML iframe is used to display a web page within a web page.
• An inline frame is used to embed another document within the current HTML document.
• It is a good practice to always include a title attribute for the <iframe>. This is used by screen
readers to read out what the content of the iframe is.
• Syntax:
<iframe src="url" title="description"></iframe>
• You can add the style attribute and use the CSS height and width properties:
To remove the border, add the style attribute and use the CSS border property:
Example:
<iframe src="hello.html" style="border:none;" title="Iframe Example"></iframe>