HTML images embed pictures into a webpage with the <img> element. The web started as text; images make pages informative and visual. <img> is a void (self-closing) element and a replaced element—its content comes from an external file, not from child HTML text.
How is this page different from the <img> tag reference?
This tutorial teaches how to use images in real HTML pages: choosing src paths, writing alt, reserving space with width/height, captions with <figure>, formats, responsive <picture>, and when CSS backgrounds are better. For attribute lists and technical rules, open the <img> tag reference.
What do you need for a useful image?
At minimum: src (where the file is) and alt (what the image means when it cannot be seen). Add width and height so the layout does not jump when the file arrives.
When should an image be in HTML vs CSS?
Put content images in HTML (<img>) so they have alt text and print with the article. Put decorative surfaces in CSS (background-image) when they are not part of the meaning.
Descriptive filenames help.
Prefer mountain-sunrise.jpg over img835.png—humans and search engines both benefit.
Do not hotlink.
Do not point src at someone else’s image host without permission. Host files you have the right to use, or use a CDN you control.
Relative URLs are easier to maintain.
Keep images on your site (or CDN) and use paths like images/photo.jpg instead of hard-coding another domain for every asset.
Syntax
HTML Syntax for Images
The basic pattern every content image needs:
img.html
<img src="url" alt="description">
HTML
<!-- Same folder as the HTML file -->
<img src="dinosaur.jpg" alt="Dinosaur skeleton">
<!-- Inside an images/ subfolder -->
<img src="images/dinosaur.jpg" alt="Dinosaur skeleton">
<!-- Absolute URL (host yourself; avoid hotlinking) -->
<img src="https://www.example.com/images/dinosaur.jpg" alt="Dinosaur skeleton">
Optional but recommended: width and height in pixels (integers, no units) to reserve layout space.
Reference
Core HTML Concepts
Ideas that make image markup work well on real pages:
Concept
Meaning in HTML
<img>
Void element that embeds an image file
src
URL of the image resource (relative or absolute)
alt
Text alternative when the image cannot be seen
width / height
Intrinsic size hints that reduce layout shift
Replaced element
Content/size defined by an external resource
<figure> / <figcaption>
Group an image with a visible caption
<picture> / <source>
Art direction or format choice with img fallback
loading="lazy"
Defer download until near the viewport
CSS background
Decorative imagery that is not page content
Choose an image format
Format
Best for
JPEG / JPG
Photos; smaller files, lossy compression
PNG
Transparency, sharp graphics, screenshots
SVG
Logos and icons that must scale cleanly
WebP / AVIF
Modern formats with smaller sizes; offer fallbacks when needed
GIF
Simple animation; prefer video or CSS for most motion
What to put in alt
Image role
Alt guidance
Content / informative
Describe the information the image adds
Already described in nearby text
Often alt="" to avoid duplication
Decorative
alt="" (or use CSS background instead)
Inside a link
Alt (or visible text) must name the link destination
Text baked into a graphic
Avoid if possible; otherwise put that text in alt
Approach
How to Add Images to an HTML Page
A practical order from first photo to responsive setups.
Host the file (or use a CDN you control) and pick a descriptive filename.
Add <img src="…" alt="…"> where the image belongs in the content flow.
Set width and height to the intrinsic pixel size (scale with CSS if needed).
Wrap with <figure> + <figcaption> when a visible caption helps.
Use loading="lazy" for below-the-fold images; keep hero/LCP images eager.
Add <picture> when you need different crops or formats per screen.
Goal
HTML pattern
Basic content image
<img src="photo.jpg" alt="…">
Reserve layout space
width="400" height="300" on img
Visible caption
<figure>…<figcaption>…</figcaption></figure>
Defer offscreen load
loading="lazy"
Art direction / formats
<picture><source>…<img></picture>
Try it
Live Preview
Switch how an image is marked up and see the role of alt, size, caption, and lazy loading.
Preview updates the sample markup note and a simple rendered result.
Sample result
<img src="photo.jpg" alt="A scenic mountain landscape at sunrise">
Code
HTML Examples
Six patterns: basic img, dimensions, figure caption, lazy loading, responsive picture, and a full page.
Example 1 — Basic Content Image
Embed a photo with src and meaningful alt:
HTML
<img src="photo.jpg" alt="A scenic mountain landscape at sunrise">
Structure — headings organize image sections like any other HTML content.
Accessibility — every content image keeps an alt.
Performance — dimensions + lazy loading for offscreen assets.
Semantics — figure when a caption is part of the story.
Edge Cases & Pitfalls
Most image bugs are missing alt, bad paths, or treating decoration as content.
alt
Missing alt or filename as alt
Never omit alt on content images. Do not write alt="photo.jpg"—describe the meaning.
path
Broken src paths
Wrong folders or typos show the alt text (or a broken icon). Check relative paths from the HTML file.
hotlink
Hotlinking other sites
Unethical bandwidth use and fragile URLs. Host your own assets or licensed CDN files.
cls
No width/height
Text jumps when large images finally load. Set intrinsic dimensions (or CSS aspect-ratio).
lazy
Lazy-loading the hero
Above-the-fold / LCP images should load immediately—skip loading="lazy" there.
css
Content stuck in CSS backgrounds
Important photos and charts belong in <img> so they get alt text and remain part of the document.
Compatibility
Browser Support
The img element, figure/figcaption, picture, and loading="lazy" are supported in all modern browsers.
✓ Baseline · Widely available
Images in HTML
Embedding images with img — plus captions and responsive picture — works across current browsers.
100%img / picture support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
HTML images featuresUniversal
Bottom line: Focus on alt text, file size, and correct paths—browser support for basic HTML images is not the bottleneck.
Remember
Key Takeaways
src + alt are the minimum for useful content images.
width/height reduce layout shift while the file downloads.
figure adds a visible caption; picture chooses among sources.
HTML for content, CSS backgrounds for decoration.
One line: Embed with <img src alt> → size it → caption or respond with figure/picture when needed.
Frequently Asked Questions
Use the img element with src pointing to the image URL (relative or absolute) and alt with a text description. img is a void element—no closing tag.
This tutorial teaches how to use images in real HTML pages: alt decisions, width/height, figure captions, formats, responsive picture, lazy loading, and CSS backgrounds. The img tag reference covers element syntax and attributes in detail.
Alt describes the image when it cannot be seen—screen readers, broken paths, text-only browsers, or images turned off. Write what the image contributes to the page, not the filename.
Use alt="" only for purely decorative images that add no information. Prefer CSS background images for decoration. Never omit the alt attribute entirely on content images.
Use img when the image is content (photos, charts, product shots). Use CSS background-image for decorative surfaces that do not need alt text or to be printable as content.
img is a replaced element: its visual content and intrinsic size come from an external file, not from child HTML text inside the tag.