img
HTML5 img element
The img element allows you to embed non-interactive static or dynamic images into your HTML document. »video
About img
Display & support img
- display in browser »video
- display type: inline-block





Parents, img
- img nested within elements »img parents
»examples
»video
Attributes img
- required: src, (alt - with a few exceptions)
- optional: crossorigin, ismap, usemap, height, width, srcset; global attributes, event attributes
ismap vs usemap
The difference between a server-side image map (ismap) and a client-side image map (usemap) »video
Syntax img
1 | <> »video |
Attributes and Values img (comma separated)
< | attribute | = | "attribute_value(s)" | > | Video | Examples |
---|---|---|---|---|---|---|
1. specific attributes | ||||||
1. | alt | = | text | »video | <src="images/puppy.jpg" alt="a grey puppy standing in the middle of a room"> | |
2. | crossorigin | = | "", , anonymous, use-credentials | - | <src="URL" alt="image description" crossorigin> | |
3. | ismap | = | "", , ismap | »video | <src="sitemap.jpg" alt="image description" ismap> | |
4. | usemap | = | #value_of_name | »video | <src="blue" alt="blue" usemap="#value"> | |
5. | height | = | pixels | »video | <src="blue" alt="blue" width="50" height="70"> | |
6. | width | = | pixels | »video | <src="blue" alt="blue" width="50" height="70"> | |
7. | src | = | URL | »video | <src="images/puppy.jpg" alt="a grey puppy standing in the middle of a room"> | |
8. | srcset | = | string (URL descriptors, URL descriptors) | - | <src="puppy.jpg" alt="description.." srcset="puppy-small.jpg 20w 20h 2x, puppy-big.jpg 250h"> | |
All Specific Attributes | ||||||
2. global attributes | ||||||
1. | accesskey | = | keyboard key | »img | <accesskey="h"> | |
2. | class | = | class name | »html »img | <class="class_name"> | |
3. | contenteditable | = | "", , true, false | »html | <contenteditable="true"> | |
4. | contextmenu | = | menu id value | »html | <contextmenu="menu_id_value"> | |
5. | data-* | = | value | - | <data-http-error="404"> | |
6. | dir | = | ltr, rtl, auto | »html | <dir="ltr"> | |
7. | draggable | = | true, , false | »img | <draggable="false"> | |
8. | dropzone | = | copy, move, link, string:, file: | - | <dropzone="copy"> | |
9. | hidden | = | "", , hidden | »html »img | <hidden="hidden"> | |
10. | id | = | id name | »html »img | <id="unique_id_name"> | |
11. | itemid | = | URL | - | - | |
12. | itemprop | = | string | »link »a | - | |
13. | itemref | = | string | - | - | |
14. | itemscope | = | "", , itemscope | - | - | |
15. | itemtype | = | absolute URL | - | - | |
16. | lang | = | language code | »html »head»title »img | <lang="en"> | |
17. | spellcheck | = | "", , true, false | »html | <spellcheck="true"> | |
18. | style | = | CSS property:value | »html »img | <style="border:2px solid #0000ff;"> | |
19. | tabindex | = | integer | »img | <tabindex="3"> | |
20. | title | = | text | »html »link»style »abbr»dfn »img »meter | <title="html page"> | |
21. | translate | = | "", yes, no | »html »img | <translate="yes"> | |
All Global Attributes | ||||||
3. global event attributes | ||||||
1. | onclick | = | script | » list | <element onclick="script" > ... | |
2. | ondblclick | = | script | » list | <element ondblclick="script" > ... | |
All Event Attributes |
Video demonstration img element
HTML5 img element: adding images
min | video details |
---|---|
00:08 | video tutorial: <img> tag: embedding a static and a dynamic image into our HTML page |
00:14 | embedding non-interactive images: static an dynamic |
00:15 | 1. STATIC IMAGE |
00:15 | 1. embedding a non-interactive static image |
00:21 | adding the <img> tag in page |
00:26 | the <img> element allows us to embed images into our HTML document |
00:30 | adding the src attribute to <img> tag: this allows us to add the path of the image we want to embed |
00:38 | Save: CTRL+S |
00:40 | Refresh: F5 |
00:41 | the embedded static image displays in our HTML page |
00:46 | adding the alt attribute to <img> tag since it's a required attribute |
00:53 | 2. DYNAMIC IMAGE |
00:53 | 2. embedding a non-interactive dynamic, animated image |
00:56 | CTRL+C = copy CTRL+V = paste |
00:59 | adding the path of the dynamic image as value of the src attribute |
01:07 | changing the value of the alt attribute |
01:09 | Save |
01:11 | refresh |
00:13 | the embedded dynamic image displays |
01:07 | note: the images to embed must be non-interactive |
01:24 | conclusion: the <img> tag allows us to embed non-interactive static or dynamic images into our HTML document |