16 HTML - Images
16 HTML - Images
HTML - Images
HTML Images provides a visual content for web pages, enhancing user experiences and
conveying information. They can be photographs, graphics, icons, or illustrations. To insert
an image on HTML document we can use <img> tag.
SEO Impact: If we can use images with proper attributes that does not effect the
loading time can be benificial to improve the website SEO.
There are lots of other advantages to use images we will know in this article.
Try to click the icon run button to run the following HTML code to see the output.
You can use PNG, JPEG, or GIF image files based on your comfort but make sure you
specify the correct image file name in src attribute. Using alt attribute is a good
practice. it specifies an alternate text for an image if the image cannot be displayed.
You can insert any image in your web page by using <img> tag. The <img> tag is an
empty tag, which means that, it can contain only list of attributes and it has no closing
tag.
Open Compiler
https://www.tutorialspoint.com/html/html_images.htm 1/4
7/17/24, 11:19 AM HTML - Images
<DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<p>Simple Image Insert</p>
<img src="/html/images/test.png" alt="Test Image" />
</body>
</html>
Usually, we keep all the images in a separate directory. So let's keep HTML file test.htm in
our home directory and create a subdirectory images inside the home directory where we
will keep our image as test.png. Assuming our image location is "/html/images/test.png",
try the following example.
Open Compiler
<!DOCTYPE html>
<html>
<head>
<title>Using Image in Webpage</title>
</head>
<body>
<img src="/html/images/test.png" alt="Test Image" />
</body>
</html>
You can set image width and height based on your requirement using width and height
attributes. You can specify width and height of the image in terms of either pixels or
percentage of its actual size.
Open Compiler
<!DOCTYPE html>
<html>
https://www.tutorialspoint.com/html/html_images.htm 2/4
7/17/24, 11:19 AM HTML - Images
<head>
<title>Set Image Width and Height</title>
</head>
<body>
<p>Setting image width and height</p>
<img src="/html/images/test.png" alt="Test Image" width="450" height="200" />
</body>
</html>
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
Open Compiler
<!DOCTYPE html>
<html>
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<img src="/html/images/test.png" alt="Test Image" border="3" />
</body>
</html>
Open Compiler
https://www.tutorialspoint.com/html/html_images.htm 3/4
7/17/24, 11:19 AM HTML - Images
<!DOCTYPE html>
<html>
<head>
<title>Set Image Alignment</title>
</head>
<body>
<p>Setting image Alignment</p>
<img src="/html/images/test.png" alt="Test Image" border="3" align="right" />
</body>
</html>
https://www.tutorialspoint.com/html/html_images.htm 4/4