img ElementThe img element is an inline element declared by the XHTML 1.1 Images Module
This is the only element in this Module.
The img element is used to insert
an image into a document. The location of the image is given by the
element's mandatory src
attribute. The alt
attribute (also mandatory) is used to specify short alternative text for the image which
will be displayed in user agents which do not support images or have them disabled.
Purely aesthetic images carrying no useful information should be given an empty
alt attribute.
A longer description of a detailed image may be created at a separated
URI and then referenced using the optional
longdesc
attribute; this attribute is not well supported, however, and is therefore
of limited use - a separate link to the detailed description is best provided
using a conventional hyperlink (see the a element).
An image may be given explicit dimensions using the
height and
width attributes so
that the user agent immediately knows how much screen space the image will
cover, thereby speeding up the rendering process.
The img element is an inline element, enabling
images to be contained within paragraph text, for instance.
For example:
<p>You can include <img alt="images" src="/images/images.png" /> within the text of a paragraph.</p>
Given a suitable image at the src URI, this renders as:
You can include
within the text of a paragraph.
Vertical alignment of images within paragraph text can be controlled to a certain degree using the
CSS vertical-align property. The rendered image
above has no styling applied to it, however, and is therefore displayed using your browser's default
behaviour.
If the example above is viewed in a non-graphical browser - or with images disabled -
the alt text
"images" is used in place of the image and the paragraph reads naturally. If instead the alternative text had
been "Picture of the word images" (which admittedly does describe the image) the resulting paragraph text
would have been confusing: "You can include Picture of the word images within the text of a paragraph.". Always construct alternative text so that the content makes maximum possible sense
when images are not rendered.
Image maps may be created using either the Server-side Image Map Module or the Client-side Image Map Module.
The alt and src attributes are #REQUIRED on the img element.
img element are listed below:alt [ type Text - #REQUIRED ]height [ type Length ]longdesc [ type URI ]altsrc [ type URI - #REQUIRED ]width [ type Length ]img element are listed below:class [ type NMTOKENS ]id [ type ID ]style [ type CDATA ], from the Style Attribute Module (deprecated)title [ type Text ]xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Modulexml:lang [ type LanguageCode ]All attributes in the
Events Attribute Collection
are supported:onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
img element is:
EMPTY
See Content Model & Nesting for information about Content Model syntax and Nesting Groups.
imgThis element is empty and may have no children.
imgabbr, acronym, address, cite, code, dfn, div, em, h1 - h6, kbd, p, q, samp, span, strong, varadd, dt, licaption, td, thbutton, fieldset, label, legendb, big, i, small, sub, sup, ttdel, insbdoobjectrb, rt