Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Put the image address in the src attribute: <img src="/images/example.jpg" alt="Description of the image" width="640" height="360">. Use a relative URL for an image hosted with your site, or an absolute HTTPS URL for an image you control or are licensed to use. Add meaningful alt text, and include intrinsic dimensions when you know them.
The basic HTML image link
The <img> element embeds an image in a page. Its src value is the URL the browser requests.
<img src="/images/example.jpg" alt="Description of the image" width="640" height="360">
In this example, /images/example.jpg is a root-relative URL: it starts at your website’s domain. A file in the same folder could use example.jpg, while an image hosted elsewhere could use an absolute URL:
<img src="https://example.com/photo.jpg" alt="A mountain lake at sunrise">
At least one of src or srcset is required for an img element. A URL that works in a demonstration can later move, require authentication, or be blocked, so production sites should prefer assets under their own control or clearly licensed external files.
#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Write useful alternative text
alt is the textual replacement for an image. It is read by screen readers and appears when the image cannot be displayed. Describe the image’s meaning, not every visual detail.
- Informative image:
<img src="/images/team.jpg" alt="The support team at its annual meeting"> - Functional image link: describe the destination or action, such as
alt="Read the responsive-images guide". - Decorative image: use
alt="". Do not omit the attribute, because omission can cause assistive technology to announce the filename or URL.
Keep text in alt equivalent to the purpose of the image. If all important information is already in nearby text, an empty alternative may be correct even when the image is attractive.
Make an image clickable
Wrap the image in an anchor when the click should open another page. The alternative text should explain the link’s destination or action.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →<a href="https://example.com/article">
<img src="/images/article-thumb.jpg" alt="Read the article about responsive images">
</a>
Use a normal text link as well when the destination is important or when users may not recognize the image as interactive. The href is the navigation URL; src is only the image resource.
Use responsive image URLs with srcset and sizes
A single large file forces every device to download the same resource. Provide several width variants and let the browser choose a suitable candidate.
Rank #2
<img
src="/images/hero-800.jpg"
srcset="/images/hero-400.jpg 400w, /images/hero-800.jpg 800w, /images/hero-1200.jpg 1200w"
sizes="(max-width: 600px) 100vw, 800px"
alt="A city skyline at dusk"
width="1200"
height="675">
The w descriptors state each file’s intrinsic width. sizes tells the browser how wide the image is intended to render: full viewport width up to 600 CSS pixels, otherwise about 800 pixels. The browser combines that information with device pixel density and network conditions.
For density variants of the same displayed size, use x descriptors instead:
<img
src="/images/logo.png"
srcset="/images/logo.png 1x, /images/[email protected] 2x"
alt="Example company"
width="200"
height="60">
The regular src remains a fallback for older user agents. Do not mix a width descriptor and a density descriptor in one srcset.
Use picture for formats, breakpoints, and art direction
Use <picture> when the browser should choose among different formats or crops, not merely among resolutions of the same image.
<picture>
<source media="(max-width: 600px)" srcset="/images/hero-crop-mobile.jpg">
<source type="image/avif" srcset="/images/hero.avif">
<img src="/images/hero.jpg" alt="A city skyline at dusk" width="1200" height="675">
</picture>
The browser examines each source in order, considering its media, srcset, and type. The nested img is mandatory: it supplies the fallback URL and carries the accessible alt text. Put the most specific media or format choice first.
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
| Need | Use | What changes |
|---|---|---|
| One stable file | src |
One URL is requested. |
| Different resolutions | srcset plus sizes |
The browser selects a width- or density-appropriate file. |
| Different crop on mobile | picture and media |
Art direction changes composition. |
| Different file format | picture and type |
The browser chooses a supported format, with img fallback. |
Reserve layout space with dimensions
Set accurate width and height attributes whenever possible. They communicate intrinsic dimensions and allow the browser to reserve space while the file loads, reducing unexpected layout movement. They do not prevent responsive CSS sizing.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches<img
src="/images/product.jpg"
alt="Blue ceramic mug"
width="1200"
height="900"
style="max-width:100%;height:auto;">
The attributes describe the source ratio; the CSS makes the rendered image fit a narrow container. If the source is 1200 by 900, do not claim 1200 by 675 unless the file is actually cropped to that ratio.
Choose and maintain image URLs
Relative URLs for site-owned files
Use /images/photo.jpg when the file lives on the same site and should work regardless of the current page’s path. A path such as images/photo.jpg is relative to the current document directory and can break after a URL is moved.
Absolute URLs for controlled external assets
An HTTPS URL is appropriate when another service hosts the file and you have permission to use it. Confirm its license, hot-linking policy, permanence, and whether it requires cookies or a login. The HTML behavior of an external URL does not establish that the underlying image is free to reuse.
Filenames and encoding
Use stable, descriptive filenames and URL-encode spaces and reserved characters. Prefer simple names such as hero-1200.jpg. If a URL contains query parameters for resizing or signing, keep the complete URL exactly as supplied by the image host.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #4
Common failures and fixes
- Broken-image icon: inspect the final requested URL. Check spelling, capitalization, file extension, protocol, and whether the server returns an image rather than an HTML error page.
- Image works locally but not after deployment: verify that the file was included in the deployed output and that the URL’s leading slash points to the intended domain or subdirectory.
- Only the fallback appears: check that each
srcsetcandidate exists and thatsizesis valid. Inpicture, confirm the selectedsourcehas a supported type and a usablesrcset. - Image is stretched: correct the intrinsic dimensions and avoid forcing a conflicting aspect ratio in CSS. Use
height:autowhen scaling width proportionally. - Screen reader announces an unhelpful label: replace a filename, “image,” or duplicated caption with meaningful
alttext; usealt=""for decoration. - External image disappears later: move it to storage you control or select a licensed provider with a durable URL. Do not treat a temporary demo link as a production dependency.
Performance, caching, and reliability checklist
- Generate width variants that match the sizes your layout actually renders; do not list nonexistent candidates.
- Use
sizesthat reflects the real CSS layout, especially when an image occupies only part of a desktop row. - Keep the source ratio in
widthandheightso space can be reserved before loading. - Use
pictureonly when you need a format or crop decision;srcsetis simpler for resolution choices. - Test every candidate URL over HTTPS and check the response in browser developer tools.
- Review licensing and attribution requirements separately from HTML correctness.
HTML determines which resource the browser may request; hosting, compression, cache headers, and image licensing are properties of the service delivering that resource.
Or skip the browser setup
If what you need is a dependable image of a webpage rather than an image file embedded in it, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result.
For a quick WebP capture, see the ScreenshotNeo API documentation and run:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
And Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Features include full-page and selector capture, device presets, custom CSS and JavaScript, waits, request blocking, cookies and headers, geolocation, resizing, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, and a usage API. The Free plan includes 1,000 shots monthly without a card; paid plans start at $5 for 3,000 shots. Sign up free for ScreenshotNeo.
Free tools Windows power users keep installed
One-click scans. No signup required.
FAQ
Can I put a data URL in src?
Yes, a data URL can represent an image directly, but it is a different deployment choice from linking to a hosted file. Use it only when its size, caching, and maintenance trade-offs fit your page.
Should a caption go in alt?
Not automatically. A visible caption and alternative text serve different purposes; avoid repeating identical wording when the caption already conveys the image’s relevant meaning.
Best Value
Why does the browser choose a larger file than expected?
The choice considers the rendered slot, device pixel density, available candidates, and the sizes declaration. Recheck the actual CSS width and make sure the width descriptors match the files.
Frequently Asked Questions
Can I put a data URL in src?
Yes, but it has different caching and maintenance trade-offs from a hosted image file.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Should a caption go in alt?
Only when it provides the image’s alternative meaning; avoid duplicating a visible caption.
Why does the browser choose a larger srcset file?
Selection uses the rendered slot, device pixel density, available candidates, and your sizes declaration.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

