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

To display an image from a URL, put the image resource’s URL in an HTML <img> element’s src attribute. For example: <img src="https://example.com/photo.jpg" alt="Description of the photo" width="800" height="600">. Use an absolute URL for a full address or a relative URL for a file located relative to your page. If you only need to show the image, this is usually all the code you need.

Display an image directly with HTML

The <img> element embeds an image in a document. The browser requests the resource in src and renders it as part of the page; JavaScript is not required for ordinary display.

<img
  src="https://example.com/photo.jpg"
  alt="A red bicycle leaning against a brick wall"
  width="800"
  height="600"
>

Replace the example address and description with the actual image URL and what the image shows. The URL should identify an image resource, not just a web page that contains an image. If you know the image’s dimensions, include them: they reserve space before the file loads and help avoid the surrounding page shifting as the image appears.

Absolute and relative URLs

An absolute URL gives the browser a complete address, such as https://example.com/images/photo.jpg. A relative URL is resolved from the address of the page containing the HTML. For example, images/photo.jpg points to an images folder under the page’s current location. Use an absolute URL when the image is hosted elsewhere or you need to specify its full address; use a relative URL for an image that is part of your own site and whose location is known relative to the page.

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.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

Write useful alternative text

The alt value should describe the image’s relevant content, rather than repeat its filename or say only “image.” If the image communicates information, give a concise description that makes sense in the page’s context. If you omit the attribute, assistive technology may not have an equivalent text description. Add width and height when you know the intended dimensions; they describe the image’s layout size, not a requirement that the file itself have those exact pixel dimensions.

Choose HTML or JavaScript based on what you need

Use <img src="..."> when the browser only needs to show an image. Use JavaScript fetch() when your code needs to inspect, transform, or otherwise handle the response before displaying it. These are different loading paths: an image can display successfully in an <img> while a script’s attempt to read its bytes is blocked by cross-origin rules.

Need Approach Cross-origin consideration
Display an image <img src="..."> A remote image can normally be embedded this way.
Read or process the response in JavaScript fetch(), then read a Blob The image server must allow the page’s origin through CORS.
Read or export image pixels with canvas Set the image’s CORS mode before assigning its URL, then draw it to canvas The image server must return compatible CORS headers or the canvas is tainted.

Fetch an image in JavaScript and display it

If you need the response as data—for example, to process it before assigning it to an image element—you can fetch it, check the HTTP status, convert it to a Blob, and create a temporary object URL.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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.
async function loadImage(url, img) {
  const response = await fetch(url);
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}`);
  }

  const blob = await response.blob();
  const objectURL = URL.createObjectURL(blob);

  img.onload = () => URL.revokeObjectURL(objectURL);
  img.src = objectURL;
}

loadImage(
  "https://example.com/photo.jpg",
  document.querySelector("#preview")
).catch((error) => {
  console.error("Could not load the image:", error);
});

The page needs an image element with the matching selector, such as <img id="preview" alt="A mountain at sunset">. The example checks response.ok because fetch() does not treat every HTTP error status as a rejected promise. If the URL is on another origin, the server must return CORS permission for the page’s origin before JavaScript can read the response. Converting the response to a Blob does not bypass that rule.

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

The object URL refers to the Blob held by the browser. Revoke it when the image has loaded and you no longer need that URL, as in the example, to avoid retaining unnecessary browser memory. If you need to use the same object URL elsewhere, wait to revoke it until those uses are finished.

Load a remote image into canvas

Showing an image and reading its pixels are separate permissions. If you draw an image from another origin to a canvas without CORS permission, the browser taints the canvas; pixel-reading and export operations such as toDataURL() and toBlob() then fail. Set the image’s CORS mode before setting src, and configure the image server to return an Access-Control-Allow-Origin header that permits your page.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.
<img id="source" crossorigin="anonymous" alt="">
<canvas id="work" width="800" height="600"></canvas>

<script>
  const source = document.querySelector("#source");
  const canvas = document.querySelector("#work");

  source.crossOrigin = "anonymous";
  source.onload = () => {
    const context = canvas.getContext("2d");
    context.drawImage(source, 0, 0);

    // Pixel-reading or export calls require the image server
    // to allow this page's origin through CORS.
  };
  source.onerror = () => {
    console.error("The image did not load.");
  };
  source.src = "https://cdn.example.com/photo.jpg";
</script>

Ordering matters: configure crossOrigin before assigning src, so the browser requests the image using the intended CORS mode. The attribute alone does not grant permission; the remote server must send a compatible response header. If you control neither the image server nor its CORS settings, a server-side proxy you control may fetch and re-serve the image. Build such a proxy with authentication, caching, size limits, and content-rights controls rather than turning it into an unrestricted relay.

Why no-cors does not fix JavaScript access

Setting mode: "no-cors" on a fetch request does not let your script inspect a cross-origin image response. It produces an opaque response, whose contents JavaScript cannot read. Use a server that grants the required CORS permission, or a controlled server-side proxy if direct access is unavailable.

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

Serve responsive images and avoid layout shifts

For pages that show images at different sizes, provide width variants with srcset and describe the rendered size with sizes. The browser can then choose a suitable source for the available layout.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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
<img
  src="small.jpg"
  srcset="small.jpg 480w, large.jpg 1200w"
  sizes="(max-width: 600px) 100vw, 800px"
  alt="A kayaker on a lake"
  width="800"
  height="533"
>

Here, srcset lists image candidates and their widths; sizes tells the browser how wide the image is expected to appear under the stated condition. Provide files that correspond to the variants you list. These attributes affect image selection and delivery, not cross-origin permission.

For an image below the fold, you can ask the browser to defer loading it with loading="lazy":

<img src="gallery/photo.jpg" alt="A close-up of a fern" loading="eager" width="800" height="600">

Do not lazy-load a key hero image that should be available immediately. Lazy loading is a timing choice; it does not change whether the URL is reachable, whether JavaScript can read its response, or whether canvas may use its pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is to capture a web page as an image or PDF rather than embed an image file, ScreenshotNeo provides a screenshot API. For a one-request screenshot, use this cURL example with your API key and the page URL you want to capture. See the ScreenshotNeo API documentation for request options.

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

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, and failed loads are never billed, and the response indicates the page verdict and billing status. Its MCP server lets AI agents use screenshot tools. The Free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.

Troubleshoot an image that will not load

Use the browser’s Network panel to inspect the request rather than guessing from the page’s appearance. Check the requested URL, response status, redirects, MIME type, and whether the request was blocked. Then follow the symptom that matches what you see.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • The image area is blank: Confirm that src points to an actual image resource and that the address is reachable over HTTPS. Check for a failed status or redirect in Network, and verify that the server returned an image rather than an HTML error or sign-in page.
  • The request is blocked despite a valid URL: Check the page’s Content Security Policy, especially its img-src directive. The policy must permit the image source.
  • <img> works but fetch() fails: Inspect the response’s CORS headers. The remote image server must permit the requesting page’s origin for JavaScript to read the response.
  • The image appears, but canvas export or pixel reading fails: Set crossorigin="anonymous" before src and ensure the image server returns compatible Access-Control-Allow-Origin permission. A canvas tainted by an image without CORS permission cannot be used for the affected read or export operations.
  • The page shifts when the image appears: Supply the image’s known width and height so the browser can reserve layout space.
  • Memory remains in use after Blob-based display: Revoke the object URL after the image loads and no longer needs it.

Do not treat an opaque no-cors fetch response as a successful way to access image bytes. If script must process a cross-origin image, solve the CORS permission or use a suitably restricted proxy you control.

Frequently Asked Questions

Does an image URL have to end in .jpg, .png, or another image extension?

The important point is that the address returns an image resource the browser can render. Check the actual network response rather than relying only on the text at the end of the URL.

Can I use fetch with no-cors and then turn the result into a Blob?

No. A no-cors request gives script an opaque response, so it cannot read the image bytes to make a usable Blob. The server must allow the page through CORS for JavaScript access.

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.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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