TOC

The community is working on translating this tutorial into Arabic, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".

HTML Basics:

Images

In HTML images are defined with the <img> tag. The image tag is an empty element as it only contains attributes and therefore has no closing tag. The simplest way of using the <img> tag is with the src attribute (src is an abbreviation of source). The value of the src attribute is the url for the picture you want to display.

The url points to where the picture is stored which would normally be on your server.

<img src="my-picture.jpg">

Besides the src attribute, the alt attribute is required too. Alt is an abbreviation for alternate text. The value of the alt attribure is the elements fallback content – this means, the alt attribute will be shown if the browser was not able to show the picture itself. The value of the alt attribute is also what screenreaders will read aloud when they come to your image. This means, that the alt attribute should be used to describe the actual picture. Let’s say, the picture is a portrait of Angelina Jolie, the HTML markup would look like this:

<img src="my-picture.jpg" alt="Portrait of Angelina Jolie">

On the other hand, a picture of Picasso might be described as “Portrait of Angel Fernandez de Soto. A work from the later part of Picasso’s Blue Period. A man probably drinking absinthe, depicted in a gloomy style". And why this long description? Imagine you cannot se the picture and the alt txt is your description of the picture.

The last attribute to mention regarding the image tag is the title attribute. If you have ever hovered your mouse over an image and seen a text, this is the value of the title attribute. In addition, this text is often referred to as a tooltip. This adds semantic meaning to your pictures but should only be used on pictures where the hover effect does not conflict with the usability of your page. This means that you should not use the title attribute on e.g. images that functions as page navigation.

What you have learned

  • In order to actually show an image, you always have to add the src-attribute to the image-tag
  • The value of the alt attribute is essential to screenreaders and if the browser for some reason cannot show your picture
  • The alt attribute is relevant for screenreaders and searchengines’ webcrawlers – so remember to use it!

This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!
adplus-dvertising