HTML img tag
Note: If you don't know what a tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.
The
HTML img tag inserts the image file pointed by the "src" attribute, where it's defined, but it can also be set as "floating". It's a better practice to do this using style sheets instead of the deprecated "align" attribute.
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.
Example:
Code begin
<p id="paragraph1">This is the first paragraph named as paragraph1. To dynamically change its properties use this identifier.</p>Code end
The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used with style sheets and tells the browser the class to which the element is associated with. A class gives visual attributes to elements.
Example:
Code begin
<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>Code end
Defines a visual style of this element. Is a better practice to define styles attributes in external style sheets grouping them in classes. Attributes in the "style" parameter must preserve this order "name : value" and be separated by a semi-colon.
If you're writing
XHTML code it's recommended not to use this attribute and try style sheet classes (with the "class" attribute).
Example:
Code begin
<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style</p>
<p>And this is another text without style.</p>Code end
Indicates a title for the element. Used to give a short description about the element that is usually shown as a "tool tip" when the user put the mouse pointer over the element.
Example:
|
Code
|
View
|
|
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
|
HTML code
|
Specifies the language of an element's content. The default value in "unknown".
When writing
XHTML code the syntax "xml:lang" represents a preferred alternative in XHTML 1.0 and a replacement in XHTML 1.1 (e.g., xml:lang="en").
Example:
Code begin
<p lang="en">This is a paragraph in english.</p>
<p lang="es">Este es un párrafo en español.</p>Code end
dir
Specifies the text direction of the element's contents and attribute values, as well as tables directionality. It has two possible values that are case insensitive:
- RTL: Right to left.
- LTR: Left to right.
Example:
Code begin
<q lang="he" dir="rtl">...a Hebrew quotation...</q>Code end
The "alt" attribute defines an alternate text designed to be a textual replacement for objects that are usually not supported by some browsers. It also serve as additional information for browsers that do support these objects (images, forms and applets). Browsers may display this text as a tool tip when the mouse is over the object.
This attribute is required when writing
XHTML code.
Example:
|
Code
|
View
|
|
<img width="88" height="31" src="http://www.htmlquick.com/img/links/button.jpg" alt="HTMLQuick link button" />
|
|
Specifies a name for the element, for further reference (e.g., style sheets or JavaScript). This attributes has been included for backwards compatibility and authors should use the "id" attribute instead (specially for
XHTML code compatibility).
ismap
When this boolean attribute is set, the image is identified as a server-side image map. The image must also be linked to a processing agent (script) that will handle the data sent by the user. When the user clicks somewhere in the image, the coordinates where the click occurred are sent to the processing agent (working like a form).
Remember that boolean attributes must be defined as attr_name="attr_name" to be
XHTML code compliant.
usemap (uri)
This attribute specifies the image map to which this element is related to. To work correctly the "usemap" attribute of this element must match the "name" attribute from the associated
HTML map tag.
Example:
Code begin
<img src="http://www.htmlquick.com/img/examples/nav1.jpg" usemap="#nav1" alt="Navigation menu" /> Code end
align
Specifies the alignment of the element. This three values sets the element's position with respect to the surrounding text.
- bottom: Means that the bottom of the object should be vertically aligned with the current baseline. This is the default value.
- middle: Means that the center of the object should be vertically aligned with the current baseline.
- top: Means that the top of the object should be vertically aligned with the top of the current text line.
This two values sets the position of a floating element:
- left: Cause the image to float to the current left margin.
- right: Cause the image to float to the current right margin.
Assigns a width to the element.
Assigns a height to the element.
Specifies the element's border width.
This attribute works as a margin for the element, defining the amount of white space to be inserted at the left and right sides of the element.
This attribute works as a margin for the element, defining the amount of white space to be inserted at the top and bottom sides of the element.
- onclick
- ondblclick
- onmousedown
- onmouseup
- onmouseover
- onmousemove
- onmouseout
- onkeypress
- onkeydown
- onkeyup
See complete list and information about
events in HTML
Common use for the HTML img tag.
|
Code
|
View
|
<p>Here is an image you can use to link to us from your website:</p> <img src="../../img/links/button.jpg" alt="HTMLQuick.com logo" /> <p>Here is an example of how to use it:</p> <a href="http://www.htmlquick.com"> <img width="88" height="31" src="../../img/links/button.jpg" alt="Learn HTML code" /></a>
|
Here is an image you can use to link to us from your website:
Here is an example of how to use it:
|