The img Element
Understand how to embed images using the img tag in HTML, including specifying the source path and providing alternative text for accessibility. Practice organizing images alongside headers within containers using id and class attributes to create a semantic web page layout.
We'll cover the following...
We'll cover the following...
Images in HTML
Use the <img> tag to embed an image into your web page with an src attribute that contains a file path to the image you want to be included. Use the alt attribute to provide alternative text with a description of the image in case it doesn’t load, or is being read by a screen reader for people with disabilities.
Unlike most of the elements we have encountered thus far, the img element does not have a closing tag :
<!-- Incorrect img declaration -->
<img src="path/to/image/cat.jpg" alt="A cat"></img>
<!-- Correct img declaration -->
<img src="path/to/image/cat.jpg" alt="A cat">
Exercise
In this exercise, you will need to do the following:
- Add an image of the final result of the recipe from a search engine of your choice to your HTML page. Give this image an alternative text label. Place this image under the main level header.
- Wrap the main level header and the image in a container. Give this container an
idattribute, with the valuerecipeTitle. - Group the elements comprising
IngredientsandInstructionsinto separate containers.- Give each container an
idvalue; one namedingredients, the other namedinstructions. - Give both containers a
classvalue ofrecipeList.
- Give each container an