To add an image in HTML, put its URL in the src attribute and provide alternative text with alt:
<img src="/images/example.jpg" alt="Description of the image" width="640" height="360">
Use a path to an image on your site or an absolute HTTPS URL for an image you’re permitted to use. For responsive pages, add srcset and sizes so the browser can select an appropriate image file.
What goes in an HTML image link?
The src attribute holds the image URL: the location the browser should load. That can be a site-relative path such as /images/example.jpg, a path relative to the current page such as images/example.jpg, or a complete URL such as https://example.com/photo.jpg. Use a stable URL that you control or are licensed to use.
At least one of src or srcset is required on an <img> element. For the simplest, widely understood pattern, include both src and alt:
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
<img src="https://example.com/photo.jpg" alt="A mountain lake at sunrise">
The URL must point to an image resource, not merely to a web page that displays an image. If a page at https://example.com/gallery contains a photo, use the image file’s URL rather than the gallery page URL.
Absolute and relative image paths
- Root-relative:
/images/photo.jpgstarts from the website’s root, so it can be used consistently from pages in different folders. - Page-relative:
images/photo.jpgis resolved relative to the current page’s URL. A page inside a nested folder may therefore look for the image in a different place. - Absolute:
https://example.com/photo.jpgspecifies the host and path. Use HTTPS and check that the host permits your site to display the image.
For example, if the page is https://mysite.com/guides/html/, a root-relative /images/photo.jpg points to https://mysite.com/images/photo.jpg. A page-relative images/photo.jpg points under the current page path instead. Choose the form that matches where the file is actually hosted.
Choose useful alternative text
The alt attribute is the textual replacement for an image. It can convey the image’s meaning to someone using a screen reader and provide equivalent text when the image cannot be displayed. Describe the information or purpose the image adds, rather than mechanically listing every visible detail.
<img src="/images/mountain-lake.jpg" alt="A mountain lake at sunrise">
If an image is purely decorative and adds no information, use an empty value, alt="". Do not omit alt just because the image is decorative; an empty value indicates that assistive technology should treat it as decorative.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
If the image is inside a link, write alt text that communicates the link’s destination or action. For example:
<a href="https://example.com/article">
<img src="/images/article-thumb.jpg" alt="Read the article about responsive images">
</a>
In this example, the image is the link’s content, so its alternative text tells the reader what activating the link does. Avoid generic alternatives such as “image” or “photo” when they do not explain the image’s purpose.
Set image dimensions to reserve space
When you know an image’s intrinsic dimensions, provide both width and height. These attributes give the browser the image’s proportions before the file finishes loading, helping it reserve the right amount of space in the page.
<img src="/images/example.jpg" alt="Description of the image" width="640" height="360">
Use the actual image dimensions, or dimensions with the same aspect ratio. Here, 640 by 360 represents a 16:9 image. If you set values that describe a different proportion, the image may appear distorted unless CSS or another layout rule adjusts its display. Dimensions do not have to be the final on-screen size: CSS can scale an image while preserving its ratio.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Offer responsive image sizes with srcset and sizes
For a layout that displays the same image crop at different sizes, provide candidate files with srcset. Width descriptors such as 400w and 800w identify each file’s intrinsic width. The sizes attribute tells the browser the width the image is expected to occupy in the layout; the browser can then choose a suitable candidate.
<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">
This example gives the browser three files and says the image is expected to take the full viewport width up to 600 pixels, and 800 pixels beyond that. Adjust sizes to match your actual layout; it is not a substitute for responsive CSS. If it describes a width larger or smaller than the image really occupies, the browser may choose a less appropriate download.
The src value remains a fallback for user agents that do not use the listed candidates. Make sure it points to a usable file, and ensure every URL in srcset is valid. Width descriptors are useful when candidate files have different pixel widths. Density descriptors such as 1x and 2x are another option when providing versions intended for different pixel densities.
Use <picture> for different crops or formats
Use <picture> when the browser should consider alternate image sources based on media conditions or supported formats. The nested <img> is still required: it supplies the fallback image and the alternative text.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
<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 first source offers a mobile crop when its media condition matches. The next offers an AVIF file to a browser that supports that type. If neither source applies or can be used, the browser can fall back to the JPEG in <img>. Keep that fallback: a <picture> element without its nested image does not provide the complete pattern.
Which pattern should you use?
- Use one
srcwhen a single image file is appropriate at every display size. - Use
srcsetwithsizeswhen you have different resolutions of the same crop and want the browser to select a candidate. - Use
<picture>when you need a different crop for a particular layout or want to offer alternate formats with an image fallback.
Use image URLs you can rely on
An image URL that works today may later move, become inaccessible, or be blocked from use on another site. For production pages, prefer images hosted under your site’s control, or confirm the external host allows your use. If you use an externally hosted image, check the image’s license and any attribution requirements separately; a working URL does not establish permission to reuse it.
Keep the path and filename accurate, including capitalization where the host treats it as significant. If you rename or move a file, update the HTML or keep a redirect in place. For multiple responsive candidates, verify every file rather than checking only the src fallback.
Troubleshoot a broken image
- The browser shows a broken-image icon: Open the image URL directly and check that it loads. Correct a misspelled filename, wrong folder, missing file, or incorrect capitalization.
- The URL works when opened but not on your page: Check whether the host permits display from your site and whether the page is using HTTPS. A host may block embedding, or an insecure image request may be blocked on a secure page.
- The wrong file appears at some screen sizes: Inspect all
srcsetURLs and their width descriptors, then compare thesizesvalue with the image’s actual rendered width. A mismatch can lead the browser to select an unsuitable candidate. - The image is announced unhelpfully: Replace missing or generic alt text with a short description of the image’s meaning. For a decorative image, use
alt=""; for a linked image, describe the action or destination. - The page shifts while the image loads: Add accurate
widthandheightattributes so the browser knows the image’s proportions in advance. - The mobile composition is wrong: If the image needs a different crop rather than just a smaller resolution, use a media-specific source inside
<picture>and retain an<img>fallback.
Or skip the browser setup
If you need an image file of a web page rather than an image embedded in your HTML, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a screenshot as PNG, JPEG, or WebP, or a PDF. The response is an image file to download or otherwise handle; it is not automatically a public image URL for your HTML’s src. To use a captured screenshot in a page, save the image and host it somewhere your page can load.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Here is a cURL example that saves a screenshot as WebP. See the ScreenshotNeo documentation for API details:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents using Claude, Cursor, or another MCP client. The Free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo.
Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.
Frequently Asked Questions
Can an HTML image have only a `srcset` attribute?
Yes. An `img` element requires at least one of `src` or `srcset`; for broad fallback support, the patterns in this guide include `src`.
Does `width` and `height` have to match the displayed size?
No. They should describe the image’s intrinsic dimensions or its proportions; CSS can scale the rendered image.
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.

