HTML Attributes Explained

Most HTML tags can have what are called attributes. There are many types of attributes and some are required while others are not. They always follow the same format.

Attributes modify or add meaning to an HTML element.

Attribute Syntax

Attributes follow a relatively simple format

<tag attribute-name="attribute-value">Some content...</tag>

The img Element

The img element is used to insert images into an HTML document. It is an empty tag (meaning it has no closing tag).

The img element has two required attributes:

  1. src: The source location (URL) of the image file.
    This works the same way as the href attribute on links
  2. alt: The alternate text.
    This is used to describe the image for someone who cannot see it because they are either using a screen reader or the image src is missing. This text will only show if the image does not.

A graphic explaining html attributes
From Learning Web Design, P. 62

Things to remember: