HTML Images & Graphics

Learn how to add images, responsive graphics, SVG, and Canvas to your webpages.

<img>(Image Tag)

The <img> tag embeds images into your page. Always include the 'alt' attribute for accessibility.

  • src – the URL of the image
  • alt – descriptive text for accessibility
  • width & height – optional size attributes

Basic HTML Image

A simple image using src, alt, width, and height.

<picture> & <source>

Use <picture> with <source> to provide responsive images that change based on screen size or device resolution.

  • Browser chooses the first matching .
  • Fallback is required inside .
  • Useful for mobile optimization and retina displays.

Responsive Image Example

Using <picture> and <source> to load different images based on screen width.

<svg>

Scalable Vector Graphics can be embedded inline to draw shapes and text directly in HTML.

  • Supports rectangles, circles, lines, paths, and text.
  • Can be styled with CSS and manipulated using JavaScript.
  • Resizes without losing quality.

Inline SVG Example

Drawing shapes and text directly in HTML using SVG.

<canvas>(HTML Canvas)

Use <canvas> to draw graphics programmatically with JavaScript.

  • Requires width and height attributes.
  • Draw shapes, text, images, and animations using JavaScript.
  • Ideal for games, charts, and custom graphics.

Canvas Example

Drawing shapes and text using HTML <canvas> and JavaScript.

Knowledge Check

1. Which attribute is mandatory for <img> for accessibility?

2. Which tag allows multiple sources for responsive images?

3. Which elements define clickable areas on images?

4. Which tag is used for vector graphics inline in HTML?