Você está na página 1de 3

The <img> tag defines an image in an HTML page.

The <img> tag has two required attributes: src and alt. Note: Images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image. Tip: To link an image to another document, simply nest the <img> tag inside <a> tags.

Differences Between HTML and XHTML


In HTML the <img> tag has no end tag. In XHTML the <img> tag must be properly closed.

Attribute Values
Value text Description Specifies an alternate text for an image.

Attribute alt

Value text

Description Specifies an alternate text for an image

Syntax
<img alt="text" />

Guidelines for the alt text:

The text should describe the image if the image contains information The text should explain where the link goes if the image is inside an <a> element

Use alt="" if the image is only for decoration src URL Specifies the URL of an image

Syntax

<img src="URL" />

Possible values:

An absolute URL - points to another web site (like src="http://www.example.com/image.gif") A relative URL - points to a file within a web site (like src="image.gif")

Optional Attributes
Attribute align Value top bottom middle left right Description Use styles instead. Specifies the alignment of an image according to surrounding elements The align attribute specifies the alignment of an image according to the surrounding element. The <img> element is an inline element (it does not insert a new line on a page), meaning that text and other elements can wrap around it. Therefore, it can be useful to specify the alignment of the image according to surrounding elements. border height hspace pixels pixels % pixels Deprecated. Use styles instead. Specifies the width of the border around an image Specifies the height of an image Deprecated. Use styles instead. Specifies the whitespace on left and right side of an image Specifies an image as a server-side image-map Specifies the URL to a document that contains a long description of an image Specifies an image as a client-side image-map Deprecated. Use styles instead. Specifies the whitespace on top and bottom of an image Specifies the width of an image

ismap longdesc usemap vspace width

ismap URL #mapname pixels pixels %

Standard Attributes
The <img> tag supports the following standard attributes:

Attribute class dir id lang style title xml:lang

Value classname rtl ltr id language_code style_definition text language_code

Description Specifies a classname for an element Specifies the text direction for the content in an element Specifies a unique id for an element Specifies a language code for the content in an element Specifies an inline style for an element Specifies extra information about an element Specifies a language code for the content in an element, in XHTML documents

Você também pode gostar