liveBook · Manning

Src attribute

As explained in Web Design Playground, Second Edition

The src attribute specifies the location of the image resource referenced by an HTML img element.

The src attribute, short for “source,” tells an HTML element where to find the file it should use. For an img element, the browser retrieves the image and displays it where the element appears. section 6.1

Choose the src value according to where the file lives:

  • Use a full URL when the image is on a remote server. section 6.1
  • Use the filename when the image is in the same directory as the HTML file. section 6.1
  • Use the path and filename when the image is in another folder, such as /images/logo.png. section 6.1
  • Use a placeholder URL when the final image is not ready but its dimensions are known. section 6.1

An image with a source

Use <img src="/images/atomic-logo.png" alt="Atomic Web Design logo" title="Logo for Atomic Web Design">. The src points to the image; alt supplies replacement text, and title provides optional hover text. Tiny attribute, big responsibility. section 6.1

The same idea works with video and audio. A single-format video or audio element can carry src directly; when several formats are offered, put a src on each nested source element instead. section 6.15 section 6.16

<img 
    src=”/images/atomic-logo.png”            #1
    alt=”Atomic Web Design logo”             #2
    title=”Logo for Atomic Web Design”>      #3
<span>Atomic Web Design</span> 

Inspect the complete img example to see src alongside accessibility and tooltip attributes. section 6.1

How Web Design Playground, Second Edition covers it

How deep it goes
Explains remote URLs, local filenames, paths, placeholders, and multiple media sources without covering server-side file handling.
Examples
Uses an image path, a placeholder URL, and single- or multiple-format video and audio markup.
What it assumes
Assumes basic HTML element syntax while defining source, alternative text, and media placement through concrete examples.
What you can do after
Build it into HTML media elements by supplying appropriate filenames, paths, URLs, or source alternatives.
How it connects
Connects src with img, video, audio, source, alt, title, and media format types.

Also explained in

Compare how 2 books explain src attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.