HTML Tags: Media
The essential things on this page are:
<img>
,<audio>
,<video>
to embed multimedia files<iframe>
to embed HTML pages
These are the HTML tags related to embedding media (picture, video, sound, etc).
Tag | Type | Description |
---|---|---|
Media | ||
<img> | Inline | Embeds image |
<audio> | Inline | Embeds audio |
<video> | Inline | Embeds video |
<picture> | Inline | Defines different alternative versions of an image |
<source> | Other | Specifies a media source |
Maps | ||
<map> | Other | Defines an image map |
<area> | Other | Defines an area inside an image map |
Tracks (subtitles) | ||
<track> | Other | Specifies subtitle for <audio> or <video> |
Embedding | ||
<embed> | Block | Embeds external content |
<iframe> | Inline | Embeds another HTML page |
<object> | Inline | Represents any external resource |
<param> | Other | Defines a parameter for <object> |
<img>
Embeds image.
Common attributesalt=[...]
— alternative text describing the image (for screen readers).src=[...]
— image URL sourcewidth=[...]
— width of image in pixelsheight=[...]
— height of image in pixels
decoding=[...]
— hints when/how to decode the image (i.e., when/how the browser should translate the image data to something it can show on screen). Can be:sync
(decode the image synchronously with page render)async
(decode the image asynchronously with page render)auto
(let the browser decide)
loading=[...]
— Indicates when to load the imageeager
(loads the image immediately)lazy
(loads the image when it's close to being visible on screen)
srcset=[...]
— read heresizes=[...]
— read here
ismap
— indicates that the image is part of server-side image map (only makes sense if the image is a children of<a href="...">
). When the image is clicked, the browser will send the coordinates where the image was clicked.usemap=[...]
— points to thename
of a client-side image map (<map name="...">
) associated with the image.

<audio>
Embeds audio.
Instead of providing src
directly, you can also provide multiple sources with children <source src="..." type="...">
tags. The browser will use the first one it understands.
src=[...]
— audio URL sourcecontrols
— display audio controls (play/pause button, volume, etc.)
autoplay
— begin playing audio ASAP, without waiting for the entire audio file to finish downloadingmuted
— set the default audio volume to muteloop
— replay audio when it reaches the endcurrentTime
— for JavaScript: get/set current playback positionduration
— for JavaScript: get audio length
preload=[...]
— hints the browser what should be preloaded. Can be:auto
(preload everything)metadata
(preload only audio metadata, e.g. length)metadata
(don't preload anything)
crossorigin=[...]
— read here
<video>
Embeds video.
Instead of providing src
directly, you can also provide multiple sources with children <source src="..." type="...">
tags. The browser will use the first one it understands.
src=[...]
— video URL sourcecontrols
— display video controls (play/pause button, volume, etc.)width=[...]
— width of video display area in pixelsheight=[...]
— height of video display area in pixels
autoplay
— begin playing video ASAP, without waiting for the entire video file to finish downloadingmuted
— set the default video volume to muteloop
— replay video when it reaches the endplaysinline
— play the video "inline" within the video display area (don't play it fullscreen like mobile browsers normally do)currentTime
— for JavaScript: get/set current playback positionbuffered
— for JavaScript: get time ranges of the buffered areaduration
— for JavaScript: get audio length
poster=[...]
— URL of an image to be shown while the video is downloading. (By default, browsers use the first video frame.)preload=[...]
— hints the browser what should be preloaded. Can be:auto
(preload everything)metadata
(preload only video metadata, e.g. length)metadata
(don't preload anything)
crossorigin=[...]
— read here
<picture>
Works like <img srcset="..." sizes="...">
, but semantically, instead of giving sources of an image in different resolutions, you give sources of an image in different versions.
(E.g., instead of just resizing the image for smaller screens, you crop out the less relevant part for display on smaller screens.)

<source>
Specifies a media source inside <picture>
, <audio>
, or <video>
.
<picture>
Attributes when it's child of <audio>
or <video>
src=[...]
— URL of the mediatype=[...]
— MIME type of the media (e.g.video/mp4
), optionally with a codecs parameter (e.g.audio/ogg; codecs=vorbis
).
<map>
Defines an image map (clickable link areas in image).
It will contain some <area>
tags.
name=[...]
— name of map
<area>
Defines an area inside an image map.
When given href
attribute, the area represents a hyperlink.
alt=[...]
— alternative text describing the areahref=[...]
— target URL when the area is clickedtarget=[...]
— where to open the target URL (read here)shape=[...]
— defines the shape of the area. Can be:rect
(indicates the area is a rectangle)cicle
(indicates the area is a circle)poly
(indicates the area is a polygon)default
(indicates the area is the rest of the undefined regions)
coords=[...]
— defines the coordinates ofshape
:- if
shape="rect"
, the value isx1,y1,x2,y2
, which defines the top-left and bottom-right corner of the rectangle - if
shape="cicle"
, the value isx,y,radius
, which defines the circle center and the radius - if
shape="poly"
, the value isx1,y1,x2,y2,...,xn,yn
which defines the coordinates of the polygon
- if
download=[...]
— instead of opening the link, prompt the user to download it. If value is not empty, it will be the name of the downloaded file. (Only works for same-origin URLs, orblob:
anddata:
schemes)ping=[...]
— list of space-separated URLs to which the browser will sendPING
POST requests when the hyperlink is followed (usable for tracking).hreflang=[...]
— indicates the language of the linked resource (e.g.en-US
)rel=[...]
— relation of the linked resource (read here)referrerpolicy=[...]
— read here

<track>
Specifies timed text tracks ("subtitles") for <audio>
or <video>
. The format is WebVTT (.vtt
files).
src=[...]
— URL to the VTT file. Must be on the same origin as the document, unlesscrossorigin
attribute is set on the parent<audio>
or<video>
srclang=[...]
— language of the text track (e.g.en
)label=[...]
— title of the text track (shown when listing available text tracks)default
— indicates that this is the default text trackkind=[...]
— signifies what kind of text track this is. Can be:subtitles
captions
descriptions
chapters
metadata
<embed>
Embeds external content. This content is provided by an external application (e.g. browser plugin). If possible, use <img>
, <audio>
, or <video>
instead.
"Most modern browsers have deprecated and removed support for browser plugins, so relying upon <embed>
is generally not wise if you want your site to be operable on the average user's browser" (MDN).
src=[...]
— URL to the contenttype=[...]
— MIME type of the contentheight=[...]
— displayed height of the content (in pixels)width=[...]
— displayed with of the content (in pixels)
<iframe>
Embeds another HTML page into current page (as inline frame).
Represents nested browsing context. (Browsing context is the environment where a browser displays a Document. It's normally a tab, a window, or an iframe.)
Common attributessrc=[...]
— URL of page to embedsrcdoc=[...]
— overridessrc
height=[...]
— height of the framewidth=[...]
— width of the framename=[...]
— name of the frame (can be referenced by thetarget
orformtarget
attribute of<a>
,<form>
, etc.)loading=[...]
— Indicates when to load the iframeeager
(loads the iframe immediately)lazy
(loads the iframe when it's close to being visible on screen)
allow=[...]
— feature policy for the iframe (specifies what features is available to the iframe), e.g.allow="camera 'none'; microphone 'none'"
csp=[...]
— CSP enforced for the iframe (read here), e.g.csp="default-src 'self'"
sandbox=[...]
— applies extra restriction to the iframe. Empty value means restrict everything. Otherwise, the value is space-separated list of something like:allow-downloads
,allow-forms
,allow-popups
, etc. (read here for the complete list)referrerpolicy=[...]
— read here
<object>
Represents an external resource (which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin).
Possible attributesdata=[...]
— URL to the resourcetype=[...]
— MIME type of the object (must be specified)height=[...]
— displayed height of the objectwidth=[...]
— displayed width of the objectusemap=[...]
— points to thename
of a client-side image map (<map name="...">
) associated with the object.
name=[...]
— name of the a valid browsing context (for what?)form=[...]
—id
of a<form id="...">
this object is associated with (for what?)
<param>
Defines a parameter for <object>
.
name=[...]
— name of the parametervalue=[...]
— value of the parameter
<!-- Embed a flash movie with parameters -->
<object data="movie.swf" type="application/x-shockwave-flash">
<param name="foo" value="bar">
</object>
References
- HTML elements reference (MDN) — https://developer.mozilla.org/en-US/docs/Web/HTML/Element#image_and_multimedia
- Responsive images (MDN) — https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images
- Top tips for web performance: Use srcset to automatically choose the right image size (web.dev) — https://web.dev/use-srcset-to-automatically-choose-the-right-image/#what-about-pixel-density
- Synchronous / Asynchronous Image Decode using〈img decoding〉Attribute — https://usefulangle.com/post/277/img-decoding-attribute
- Image decoding on the web — https://dexecure.com/blog/image-decoding/
- Responsive images with srcset and sizes (Medium) — https://medium.com/@woutervanderzee/responsive-images-with-srcset-and-sizes-fc434845e948
- What Does 'playsinline' Mean in Web Video? (CSS-Tricks) — https://css-tricks.com/what-does-playsinline-mean-in-web-video/
- Using Feature Policy: The iframe allow attribute (MDN) — https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy/Using_Feature_Policy#the_iframe_allow_attribute