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


