<img/> Tag Syntax
Rules for coding HTML img elements
<body> ... ... phrasing content expected ...<img src="image-URL" alt="image description"/>... ... </body>
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.
- Code the img element where phrasing content is expected.
- 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
xmlnsattribute on the <html> tag. - Code a
srcattribute with the URL of the image resource. - Code an
altattribute 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. - Include any other attributes of the <img> tag as appropriate.
- 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 .../>).