Multimedia Embedding in HTML

What Is Multimedia Embedding in HTML?

HTML allows for embedding the following type of multimedia:

  • images,

  • videos,

  • audio files, and

  • vector graphics, and

  • objects (e.g. PDF documents).



To embed a semantically important image on an HTML page the img element should be used.

The img element's src (stands for source) attribute points to a relative path or an absolute URL with the image data.

<img src="images/horses/roach.jpg">
<img src="">

It is possible to control an img element dimensions with width and height HTML attributes and/or CSS.

Semanticity of Images

For robots (such as search engine web crawlers and assistive technologies) optimization it is considered a good practice to:

  • add alt (stands for alternative text) attribute i.e. a description of the image,

  • have src to point to a semantically meaningful relative path or absolute URL (images/horses/roach.jpg is better than dns/ho_ro_10.jpg).

In addition to making the robots life easier the alt attribute is also displayed to the user when there are any problems with downloading the image from its source.

  alt="A drawing of Roach, the horse of Geralt of Rivia."

When an image is semantically important, it is recommended to use img elements over CSS background properties. The CSS background property should only be used for decoration purposes as having no semantic meaning.

Images With Captions

It is often a sound idea to nest an img element within a figure element and support it with a caption using a figcaption element.

    alt="A drawing of Roach, the horse of Geralt of Rivia."
    Roach - Geralt's horse.

The difference between the figcaption element and alt attribute is that the figcaption element is always visible to the user.


To embed a video use the video element. The video's data source is indicated in the src attribute.

The controls attribute indicates that the video should be equipped with the native user agent's video controls.


Nowadays, video files are often embedded using third-party's (such as YouTube's) ready-made embedding HTML code.

Audio Files

To embed an audio file use the audio element. The audio file's data source is indicated in the src attribute.

The controls attribute indicates that the audio element should be equipped with the native user agent's audio controls.


The notable audio element's optional attributes are autoplay, loop, and muted.

Scalable Vector Graphics

Scalable vector graphics (SVGs) are rendered by user agents instead of just being served like pre-rendered raster images.

SVGs have two main advantages over raster images:

  • smaller memory size, and

  • scalability (i.e. the ability to be zoomed in without quality loss).

The main disadvantage of SVGs towards raster images is SVGs':

  • limited semanticity as SVGs cannot have descriptive file names, nor alt attributes, and

  • limited support in some user agents like older browsers or email clients.

There are two ways of embedding an SVG file within an HTML document:

  • using img element, or

  • using svg element (so called inline SVG).

<img src="svgs/horses/roach.svg">

<svg xmlns="" viewBox="0 0 512 512">
  <path d="...">


The HTML object element represents an external resource to be embedded within an HTML document. The resource type is indicated in the type attribute and the address (a relative path or an absolute URL) to the resource in the data attribute.

The HTML object element is a phrasing element.

PDF documents are often embedded in HTML documents using the object HTML element.


We use cookies and similar technologies to enhance the quality of services, maintain statistics and adjust marketing content. You will find more information in the Cookies Policy.

By clicking OK you grant consent to processing of your personal data by us and our Trusted Partners with the purpose of maintain statistics and adjustment of the marketing content pursuant to the Privacy Policy. If you wish to not grant that consent and/or limit its extent click Settings.