<img/> Tag Syntax

Rules for coding HTML img elements
   ... phrasing content expected ...<img src="image-URL" alt="image description"/>...
Rules for coding the HTML img element

Make sure you understand the difference between a tag and element and are familiar with the definitions of namespace and other HTML terms.

  1. Code the img element where phrasing content is expected.
  2. The img element consists of a standalone <img/> tag. The element name uses lower case letters and should be in the HTML namespace, which it will pick up automatically from the xmlns attribute on the <html> tag.
  3. Code a src attribute with the URL of the image resource.
  4. Code an alt attribute with a description of the image for use by non-visual clients such as auditory browsers and as an alternative in case the image resource is unavailable for some reason.
  5. Include any other attributes of the <img> tag as appropriate.
  6. Since the img element is a void element, it should always be coded as a self-closing tag terminated with the delimiter string />.

<img/> Content Model

Contents of the img element

Content: Empty. All properties are coded using attributes.

Since the <img/> tag is a void element, it is not allowed to have any content, even HTML comments and therefore should always be coded as a self-closing standalone tag, ending with the delimiters /> rather than just > (<img .../>).