HTML Images

Images can improve the design and the appearance of a web page.

Example

Result

HTML Image

Trulli

HTML Images Syntax

The HTML <img> tag is used to embed an image in a web page.

Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image.

The <img> tag is empty, it contains attributes only, and does not have a closing tag.

The <img> tag has two required attributes:

Syntax

The src Attribute

The required src attribute specifies the path (URL) to the image.

Example

Result

Alternative text

The alt attribute should reflect the image content, so users who cannot see the image get an understanding of what the image contains:

Flowers in Chania

The alt Attribute

The required alt attribute provides an alternate text for an image,

if the user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

The value of the alt attribute should describe the image:

Example

Result

If a browser cannot find the image, it will display the alternate text:

Flowers in Chania

Images in Another Folder

If you have your images in a sub-folder, you must include the folder name in the src attribute:

Example

Result

Images in Another Folder

It is common to store images in a sub-folder. You must then include the folder name in the src attribute:

HTML5 Icon

 

Images on Another Server/Website

Some web sites point to an image on another server.

To point to an image on another server, you must specify an absolute (full) URL in the src attribute:

Example

Result

Images on Another Server

Common Image Formats

Here are the most common image file types, which are supported in all browsers (Chrome, Edge, Firefox, Safari, Opera):

Abbreviation File Format File Extension
APNG Animated Portable Network Graphics .apng
GIF Graphics Interchange Format .gif
ICO Microsoft Icon .ico, .cur
JPEG Joint Photographic Expert Group image .jpg, .jpeg, .jfif, .pjpeg, .pjp
PNG Portable Network Graphics .png
SVG Scalable Vector Graphics .svg