Encodera

Thanks for reading!

Donate to the site — we work hard for you.

HTML & CSS reference

src

The address of the embedded file for `<img>`, `<video>`, `<audio>`, `<script>`, `<iframe>`.

Syntax

<img src="/images/photo.jpg" alt="…">

Parameters

ParameterTypeDescription
srcURLThe file address: an image, video, script or frame.

Examples

One attribute — different elements:

<img src="/media/photo-200x200.jpg" alt="Coffee beans" width="100">
<audio src="/media/t-rex-roar.mp3" controls></audio>

Notes

src embeds a file into the page, while href links to a resource. Paths follow the same rules as in href: / from the site root, no slash from the page's folder. For several versions of an image there is srcset.

See also

  • <img> — An image.
  • alt — The text alternative for an image: read by screen readers and shown if the image fails to load.
  • srcset — Several files of one image in different sizes: the browser picks the one that fits the screen.
  • href — The address an `<a>` link leads to or a `<link>` points at.

Related recipes

In the tutorial

  • Images — The img tag, the src and alt attributes, sizes, captions with figure and figcaption, image formats and lazy loading.

Thanks for reading!

Donate to the site — we work hard for you.