Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
HTML

How to Download an Image from an HTML Link

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make an HTML link download an image instead of opening it, put the image file URL in an <a> element and add the download attribute. This works for same-origin image URLs, and for blob: and data: URLs. For an image hosted on another origin, the image server may need to send a Content-Disposition: attachment response header; the page’s HTML cannot force an arbitrary cross-origin URL to download.

The basic HTML link for a same-origin image

Use the image file as the anchor’s href, then include download. The example assumes the image is served from the same origin as the page—that is, the same scheme, host, and port.

<a href="images/photo.jpg" download="photo.jpg">Download image</a>

When a visitor selects the link, the browser treats the linked URL as a download rather than simply navigating to it. The download value is a suggested filename, not a guarantee: the browser may adjust the name to meet filesystem restrictions, and browser settings can affect whether it asks where to save, saves automatically, or handles the resource another way. MDN describes the attribute as causing the browser to treat the linked URL as a download.

If you do not provide a filename, the browser can derive a suggestion from the response’s Content-Disposition header, the final URL path segment, or the media type. If both the header and the attribute specify a filename, MDN notes that the header filename takes priority; browser behavior and settings can still affect the final result.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

Use a useful filename

Give the visitor a descriptive name when it improves clarity, such as product-front.jpg rather than img_4837.jpg. Keep the extension consistent with the actual image format. The suggested name does not convert the image: a JPEG URL remains a JPEG even if the link suggests a different extension.

Choose the method based on where the image is hosted

Situation Use Important limit
Image is same-origin with the page An anchor with href and download The browser may adjust the suggested filename or handle saving according to its settings.
Image is on another origin and you control its server Serve the image with Content-Disposition: attachment The server response, not the page’s download attribute, indicates attachment behavior.
Image is on another origin and JavaScript must process it Fetch it and create a Blob URL, if the server permits access through CORS JavaScript cannot use this approach to bypass the image server’s access policy.
The page shows a responsive image and a particular resolution is required Link directly to the desired image variant The browser may select a different image candidate for display.

For a cross-origin image, configure the image response

A cross-origin URL belongs to a different scheme, host, or port from the page. Adding download to a link to that URL does not reliably force a download. The HTML attribute is documented to work for same-origin URLs and for blob: and data: URLs, not as a way to override another server’s response.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

If you control the remote image server, have it return an attachment disposition. For example:

Content-Type: image/jpeg
Content-Disposition: attachment; filename="photo.jpg"

The filename parameter suggests a name. For encoded filenames, the header can use filename*; clients that understand both parameters prefer filename*. The header communicates attachment behavior, but it does not guarantee identical prompts, save locations, or handling across browsers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

Use JavaScript only when the page needs the image data

A direct anchor is simpler when the task is only to offer a file. JavaScript fetch-to-Blob is useful when the page needs to handle or transform the image before offering it as a download. For a cross-origin image, the image server must allow the requesting origin through its CORS response headers. Adding a crossorigin attribute in page markup does not grant that permission.

Here is a minimal pattern for an image the page is permitted to fetch:

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
async function downloadImage(url, filename) {
  const response = await fetch(url);
  if (!response.ok) {
    throw new Error(`Image request failed: ${response.status}`);
  }

  const blob = await response.blob();
  const blobUrl = URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.href = blobUrl;
  link.download = filename;
  document.body.appendChild(link);
  link.click();
  link.remove();
  URL.revokeObjectURL(blobUrl);
}

downloadImage("https://example.com/photo.jpg", "photo.jpg");

Replace the example URL and filename with the intended image and suggested name. If the server’s CORS policy does not allow the page to read the response, the fetch will not provide the image data to this script. A Blob URL is temporary; revoke it once the browser no longer needs it. If you need to transform the image, do that with the Blob or image data before creating the download link.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make the download link point to the intended resolution

An image displayed with srcset and sizes can have several source files. The browser selects a candidate according to display width or pixel density, so the URL in an image’s single src attribute does not necessarily identify the candidate currently shown.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

If visitors should download a particular resolution, link the action directly to that file and label the available size clearly. If the download should track a particular image variant, make that variant’s URL the anchor’s href rather than assuming the browser’s display choice is the desired download.

Troubleshoot a link that opens the image or saves the wrong file

  1. Check the origin. Compare the page and image URL’s scheme, host, and port. If they match, test the anchor with download. If they differ, the attribute cannot reliably force the remote URL to download.
  2. Check the image server’s response. For a remote image whose server you control, configure Content-Disposition: attachment. If you do not control it, the page cannot impose that response behavior on the server.
  3. Check CORS when fetch fails. Inspect whether the image server’s response allows the page’s origin. A markup-only crossorigin change cannot grant script access that the server has not allowed.
  4. Check which image URL is linked. If the saved image has an unexpected resolution, look for srcset and sizes, then point the download action to the desired variant.
  5. Check filename sources. Review the Content-Disposition header, final URL path, and media type. The browser can prioritize the response header’s filename or sanitize a suggested name.

Or skip the browser setup

If you need an image of a rendered web page rather than the original image file behind a link, ScreenshotNeo can return a page screenshot as PNG, JPEG, or WebP, or as a PDF. It is not a way to download the source image asset. For a screenshot, one GET request is enough:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Before capture, it accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the page verdict and billing status in headers. An MCP server offers take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Every feature is available on every plan.

Sign up for ScreenshotNeo to get 1,000 free screenshots a month with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can I use the download attribute with a Blob or data URL?

Yes. The HTML download attribute is documented to work with same-origin URLs as well as blob: and data: URLs.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.