HTML images make web pages more engaging, informative, and visually appealing.
In this lesson, you will learn how to display images in HTML, use image attributes,
optimize images for SEO and accessibility, and build responsive image layouts.
What Are HTML Images?
HTML images allow you to display photographs, icons, illustrations,
logos, diagrams, and graphics on a web page. Images are added using
the <img> element.
Unlike most HTML elements, the image tag is a void element,
meaning it does not require a closing tag.
<img src="html-logo.png" alt="HTML Logo" />
HTML Image Syntax
<img
src="image.jpg"
alt="Description of image"
/>
src specifies the image file location.
alt provides alternative text.
width defines image width.
height defines image height.
HTML Images Cheatsheet
The following table contains the most commonly used HTML image patterns
and attributes every developer should know.
Feature
Example
Purpose
Basic Image
<img src="logo.png" alt="Logo" />
Display an image.
Image Width
width="300"
Sets image width.
Image Height
height="200"
Sets image height.
Lazy Loading
loading="lazy"
Improves page performance.
Responsive Image
max-width:100%
Fits all screen sizes.
Image Link
<a><img /></a>
Makes image clickable.
Picture Element
<picture>
Responsive image sources.
Image Caption
<figure><figcaption>
Add captions to images.
External Image
src="https://..."
Load image from another server.
Accessibility
alt="Description"
Screen reader support.
Image Source Paths
The src attribute tells the browser where the image file is located.
Accessible images help users who rely on screen readers and assistive technology.
Always provide meaningful alt text.
Use empty alt text for decorative images.
Provide captions when useful.
Avoid embedding important text inside images.
<img
src="divider.png"
alt=""
/>
Decorative images should use empty alt text so screen readers ignore them.
Common HTML Image Mistakes
Missing alt attributes.
Uploading extremely large image files.
Using generic file names.
Using images instead of text content.
Not specifying image dimensions.
Using decorative images without empty alt text.
Ignoring responsive image techniques.
Key Takeaways
HTML images are added using the <img> tag.
The src attribute defines the image source.
The alt attribute is essential for SEO and accessibility.
Responsive images improve mobile experiences.
Lazy loading improves performance.
Descriptive file names and alt text improve image SEO.
Use figure and figcaption when captions are needed.
Pro Tip
The combination of a descriptive file name, meaningful alt text,
WebP format, and lazy loading provides the biggest SEO and performance
benefits for HTML images.
You now understand HTML images, responsive image techniques, accessibility,
image SEO, lazy loading, and performance best practices. Next, learn how
to create HTML lists and organize content effectively.