HyperText Markup Language/Images

Let us start with a quick minimum example:

And let us also have a look at more extended example:

Images are normally stored in external files. To place an image into an HTML source, use the  tag with the   attribute containing the URL of the image file. To support browsers that cannot render images, you can provide the  attribute with a textual description of the image. To provide a tooltip to the image, use the  attribute.

The space before the  in the examples is there on purpose. Some older browsers behave strangely if the space is omitted.

Placement
Per default, images are placed inline to their surroundings. To place the image as a block or float instead, you can use Cascading Style Sheets.

Alternative text and tooltip
The HTML specification requires that all images have an  attribute. This is commonly known as alt text. Images can be split in to two categories:
 * those that add to the content of the page;
 * those that are purely decorative, e.g. spacers, fancy borders and bullets.

Decorative images should have empty alt text, i.e. . Images used as bullets may use an asterisk,.

All other images should have meaningful alt text. Alt text is not a description of the image, use the  attribute for short descriptions. Alt text is something that will be read instead of the image. For example, The alt text should be the company's name not the ever popular 'Our logo', which would give the sentence 'Our logo makes the best widgets in the world.' when read in a text only browser.

The  attribute stands for alternate which screenreaders for the blind, as well as non-graphic-capable browsers (such as Lynx) may use to better enable its user to understand the purpose of the image. Fully and accurately using alt text is essential for the following reasons:
 * Allows blind and vision impaired users to understand the content of your website.
 * Assists robots and search engines in understanding the content of your website.

Tooltips
Some older browsers incorrectly use the  attribute' tag to produce image tooltips. However, the  attribute should actually be used for this.

Width and height
To have an image appear smaller than it is in the external file, use the attributes  and. When only one or the other is specified, images will scale to keep the same overall ratio.

Format
Most images for the web will be made using a limited number of formats. Below is a simple list of commonly supported formats.
 * jpg / jpeg
 * Useful for photographs.
 * Near universal support.
 * Does not recreate images perfectly, leading to visible issues with many simple logos and illustrations.
 * webp
 * More efficient alternative to jpg.
 * Also supports animation and transparency.
 * png
 * Useful for images with transparency.
 * Good for simple or flat colors, such as cartoons, such as logos.
 * svg
 * Vector format with infinite resolution.
 * Great for logos and simple geometry.
 * Not useful for photographs.
 * gif
 * Supports animated images.
 * Very limited in color and resolution support.
 * Very inefficient format.

HTML/Immagini