liveBook · Manning

Img element

As explained in Build a Website with ChatGPT

The img tag is HTML markup that embeds an image resource in a web page.

The img element tells a web browser to insert an external image file into a page. Its src attribute identifies the image location, while alt provides a useful description. section 10.2.1 section 10.9

Use the two main attributes like this:

  • Set src to the filename when the image is beside the HTML file, or include the subdirectory path when it is stored elsewhere. section 10.2.1
  • Write specific alt text for people using screen readers or Braille apps; use alt="" for decorative images. section 10.2.1

Add an image from a subdirectory

Use <img src="images/old-road-marker.jpg" alt="A photo with a very old road marker in the foreground that reads 'Appleby 12 Miles'">. The path points to the file, and the alt text explains its content. section 10.2.1

<img src="images/logo.png" alt="Ampersand Photography logo">
Add an image named "old-road-marker.jpg", which is stored in the "images" subdirectory. For the alt attribute, use the following: "A photo with a very old road marker in the foreground that reads 'Appleby 12 Miles'".
<img src="images/old-road-marker.jpg" 
     alt="A photo with a very old road marker in the 
     foreground that reads 'Appleby 12 Miles'">

Compare a simple logo example with a longer, descriptive alt-text example. section 10.2.1

How Build a Website with ChatGPT covers it

How deep it goes
Defines src and alt, explains file paths and accessibility, and stops short of advanced image behavior.
Examples
Uses logo files, an old road-marker photograph, descriptive alt text, and empty alt text for decorative images.
What it assumes
Assumes basic HTML-file awareness while teaching image paths, attributes, and accessible descriptions from the beginning.
What you can do after
Build it from scratch by inserting an image, pointing src to its file, and writing appropriate alt text.
How it connects
Connects HTML markup with file paths, alternative text, screen readers, Braille apps, figure elements, and captions.

Also explained in

Compare how 3 books explain img element →

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.