SyntaxStudy
Sign Up
HTML Beginner 1 min read

HTML Images

HTML Images

Images are embedded using the <img> tag. It is a self-closing (void) element.

Required Attributes

  • src — Path or URL to the image file
  • alt — Alternative text (shown if image fails; used by screen readers)

Optional Attributes

  • width / height — Set dimensions in pixels
  • loading="lazy" — Defer loading until near viewport (performance)

Image Formats

Common web image formats: JPG (photos), PNG (transparency), WebP (modern, compressed), SVG (vectors).

Example
<!-- Image from URL -->
<img src="https://via.placeholder.com/300x200" alt="Placeholder image">

<!-- Local image with fixed size -->
<img src="images/logo.png" alt="Company Logo" width="200" height="100">

<!-- Lazy loaded image -->
<img src="photo.jpg" alt="Beautiful photo" loading="lazy">