liveBook · Manning

Src attribute

As explained in Build a Website with ChatGPT

The src attribute is an HTML attribute that specifies the URL or filename of an embedded resource such as an image.

The src attribute tells the browser where to find an external resource, such as an image. In an <img> element, src is short for “source.” section 10.2.1 section 10.9

Use a path that matches where the image file is stored:

  • Keep the filename directly in src when the image is in the same directory as the HTML file: <img src="logo.png" alt=""> section 10.2.1
  • Include the directory name and a slash when the image is in a subdirectory: <img src="images/logo.png" alt=""> section 10.2.1
  • Change src whenever you rename or move the image file; otherwise the browser cannot find the referenced image. section 4.3.1

A photo in an images folder

Use a path and helpful alternative text together: <img src="images/old-road-marker.jpg" alt="A photo with a very old road marker in the foreground that reads 'Appleby 12 Miles'">. section 10.2.1

How Build a Website with ChatGPT covers it

How deep it goes
Explains filename and subdirectory paths with examples, but does not descend into advanced resource-loading behavior.
Examples
Uses logo files, an images subdirectory, and an old-road-marker.jpg photograph to demonstrate resource paths.
What it assumes
Assumes basic HTML file organization while teaching image paths and the img element directly.
What you can do after
Apply it by writing image paths in HTML and correcting src when files are renamed or moved.
How it connects
Connects src to HTML img elements, file paths, alt attributes, thumbnails, and figure elements.

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 Build a Website with ChatGPT. The section links point to the parts of the book it draws on.