Note: If you don't know what an element/tag is and/or how you must use it we recommend you read our HTML tags and attributes tutorial, which you can find in our HTML tutorials section.
Table of contents
Bypass table of contentsThe HTML img element inserts an image in the document, which location is set in the "src" attribute.
Images are great for displaying information that sometimes is hard to explain with text. But you shouldn't forget that people with visual disabilities may not be able to receive its content. This is the main reason for the existence of the "alt" attribute (and its mandatory nature in XHTML), which should be used by authors to provide an alternative textual version for the information displayed in the image.
Some attributes for this element have a strong presentational nature, reason for which they have been deprecated in HTML 4.01 in favor of style sheets. These attributes are: "align", "border", "hspace" and "vspace". Besides, the "name" attribute has been deprecated in XHTML 1.0. Because of this, all these attributes shouldn't be used anymore.
The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).
The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It is used together with style sheets and tells the browser the class (or classes) to which the element is associated with.
A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).
This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although in some cases it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.
You can find more information about presentational attributes at the Cascading Style Sheets tutorial.
The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a short period of time.
Specifies the language of an element's content. The default value is "unknown".
When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously as in the example below. Note that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.
This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:
This attribute contains a URI that is supposed to point to the location of the image resource. This is the element's most important attribute, and it is mandatory, because without it there would be no image to display.
The value of this attribute provides a textual alternative for the image's content, and therefore must describe exactly what the image intends to show. This is vital when the development of the website needs to reach visually impaired audiences.
In XHTML 1.0, this attribute became mandatory for the element and therefore shouldn't be omitted.
This attribute's content points to a resource with extended alternative information for the image's content. Therefore, the destination document, should expand and complement the information set in the "alt" attribute.
Specifies the width of the image. This can be different to the real width of the image, and browsers should resize it as needed. However, specifiyng a different width may cause pixelated images (when bigger) or longer load periods (when smaller).
Specifies the height of the image. This can be different to the real height of the image, and browsers should resize it as needed. However, specifiyng a different height may cause a pixelated images (when bigger) or longer load periods (when smaller).
When this boolean attribute is present, the image is identified as a server-side image map.
When using the HTML img element, a server-side image map must be composed by an image with the "ismap" attribute present, inserted into a link's content. This way, when the image is clicked, the link is followed and the coordinates where the click occurred are sent to the destination document.
These coordinates will define the number of pixels from the top-left corner of the image, and will be named using the value of the "name" attribute of the image: "elem_name.x" for the horizontal coordinate and "elem_name.y" for the vertical.
Remember that in XHTML, boolean attributes must take their own names as value (e.g., attr_name="attr_name").
The value of this attribute points to an image map (HTML map element) that will be associated to this element. Therefore, this value must match the value of the "name" attribute in the image map.
This attribute assigns a name to the element, that can be used to refer to it in scripts or style sheets.
In XHTML 1.0 the "name" attribute for this element has been deprecated in favor of the "id" attribute and in XHTML 1.1 it's simply invalid. Therefore, its use is no longer recommended.
This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.
It specifies the position of the image with respect to the surrounding content. It can take the following case-insentive values:
This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.
This attribute sets the border width in number of pixels.
This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.
Sets the amount of white space (in pixels) to be inserted at the left and right margins of the image.
This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.
Sets the amount of white space (in pixels) to be inserted at the top and bottom margins of the image.
See a complete list and information about events in HTML
Diseño y desarrollo: Latitud29.com