w3resource

HTML img tag and element

1. HTML img (image) element embeds an image in an HTML document.

2. The img element is an empty element. It starts with <img> tag and does not have any end tag.

3. The value of the src element of img element holds the URI representing the location of the image.

Syntax

<img src="location of the image" / >

Category

HTML img element is a part of HTML object, image and applet.

Whether both start and end tags are required

Start tag is required but end tag is forbidden.

Can contain

HTML img element can contain any other elements.

Can reside within

HTML img element can reside within Inline elements, Block-level elements except pre.

Attributes

Identifiers

id, class.

language information and text direction

lang, dir.

Title

Title.

Style

Style.

Events

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup.

alternate text

alt.

client side image maps

ismap, usemap.

visual presentation

align, width, height.

Supported doctypes

HTML 4.01 Strict, HTML 4.01 Transitional, and HTML 4.01 Frameset.

Example of using HTML img element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>HTML img tag example - HTML tutorial | w3resource</title>
</head>
<body>
<p><img src="/images/layout.gif" alt="html img tag example" 266" height="239"></p>
</body>
</html>

Result

html img element

View this example in a separate browser window

HTML img tag example.

Previous: HTML base tag and element
Next: HTML map tag and element

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.