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

You do not convert an image into a special HTML format. Put a browser-reachable image address in an <img> element’s src attribute. Use a normal hosted URL for a separate, shareable file, or a data: URL when the image should be embedded directly in the HTML.

The basic markup is:

<img src="https://example.com/images/photo.jpg" alt="Describe the image">

The URL must identify the image resource itself. A path on your computer, such as C:\Users\you\Pictures\photo.jpg or /Users/you/Pictures/photo.jpg, is not a public website URL. Visitors’ browsers cannot read your local disk, so you must either publish the file at an address they can reach or embed its bytes in a data: URL.

Choose between a hosted URL and a data URL

Approach What the HTML contains Use it when Main trade-off
Hosted image URL A normal https:// (or relative) address pointing to an image file The image should be independently addressable, reused on several pages, publicly shareable, or managed separately from the HTML The file must remain available at that address, and the host must allow the browser to request it
Data URL The image bytes encoded inside the src value A small icon, preview, email, or self-contained HTML document needs no separate image request Markup becomes much longer, and every copy of the HTML carries another copy of the image data

MDN describes data URLs as URLs using the data: scheme that embed small files inline in a document (MDN data URL reference). For ordinary site images, a hosted URL is usually easier to cache, update, inspect, and reuse.

How to create a public image URL

1. Put the file on a web-accessible host

Upload the image to your own website, an image host, object storage, or another service that supplies a direct file address. The important result is an address that opens the image resource itself, not a dashboard page that merely displays it.

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.

2. Copy the direct URL

Open the copied address in a new browser tab. It should return the image rather than an upload form or gallery page. Keep the exact extension and URL encoding supplied by the host; do not add quotation marks inside the URL.

3. Use the address in src

<img src="https://cdn.example.com/photos/blue-chair.webp" alt="A blue chair beside a window">

You can also use a relative URL when the image is in your own site’s published files:

<img src="/images/blue-chair.webp" alt="A blue chair beside a window">

The HTML <img> element accepts image URLs and supports alternate resources through srcset; see the MDN <img> reference.

What can prevent a hosted image from displaying?

  • The URL points to an HTML page, redirect, login screen, or thumbnail instead of the image file.
  • The file was deleted, made private, or moved without a redirect.
  • The server returns an error or an inappropriate content type.
  • The host blocks embedding or requires authentication that the visitor does not have.
  • The URL contains characters that were not correctly encoded.

Paste the URL into a private browser window to test what an unauthenticated visitor receives. If it does not open as an image there, changing the HTML will not fix the hosting problem.

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

How to make a data URL from an image

Understand the syntax

The documented form is:

data:[<media-type>][;base64],<data>

For a Base64-encoded PNG, the prefix is data:image/png;base64,. For JPEG, use data:image/jpeg;base64,; for WebP, use data:image/webp;base64,. The comma is required: it separates the metadata from the encoded payload.

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.
<img
  src="data:image/png;base64,PASTE_THE_COMPLETE_BASE64_PAYLOAD_HERE"
  alt="A small chart"
>

The example above is intentionally not a working image until the placeholder is replaced with the complete Base64 output. Match the MIME type to the actual file format. Omitting the comma, truncating the payload, or declaring the wrong type can stop the browser from decoding it.

Generate one in a browser with a file picker

FileReader.readAsDataURL() reads a selected local file and returns a data URL. This creates a preview in the current browser; it does not upload the file or create a durable Internet address.

<label for="image-file">Choose an image</label>
<input id="image-file" type="file" accept="image/*">
<img id="preview" alt="Selected image preview">

<script>
  const input = document.querySelector("#image-file");
  const preview = document.querySelector("#preview");

  input.addEventListener("change", () => {
    const file = input.files?.[0];
    if (!file) return;

    const reader = new FileReader();
    reader.addEventListener("load", () => {
      preview.src = reader.result;
    });
    reader.readAsDataURL(file);
  });
</script>

To inspect or store the generated value, read reader.result after the load event. If another user or another website must access the image, upload the original file and use the hosting provider’s URL instead.

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

Generate a data URL from a canvas

For an image already drawn to a canvas, call canvas.toDataURL():

const dataUrl = canvas.toDataURL("image/png");
document.querySelector("#preview").src = dataUrl;

A canvas can become non-origin-clean after drawing cross-origin content without the required access conditions. In that case, the browser may refuse to serialize it. This is different from a malformed image URL: the source image may display while the canvas still cannot be exported.

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.

Convert an image file to a data URL outside the browser

Node.js

import { readFile } from "node:fs/promises";

const path = "photo.png";
const bytes = await readFile(path);
const dataUrl = `data:image/png;base64,${bytes.toString("base64")}`;
console.log(dataUrl);

Change the MIME prefix when the file is JPEG or WebP. This prints the entire inline value, which can be very long for a photograph.

Python

import base64

with open("photo.png", "rb") as image_file:
    encoded = base64.b64encode(image_file.read()).decode("ascii")

print("data:image/png;base64," + encoded)

These scripts encode a local file; they do not publish it. Anyone who needs a normal URL still needs an upload or deployment step.

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

Use responsive image URLs when screen size varies

If the problem is serving different sizes rather than embedding bytes, keep the images hosted and provide alternatives with srcset:

<img
  src="/images/landscape-800.jpg"
  srcset="/images/landscape-400.jpg 400w,
          /images/landscape-800.jpg 800w,
          /images/landscape-1600.jpg 1600w"
  sizes="(max-width: 600px) 100vw, 800px"
  alt="A mountain landscape"
>

The browser selects an appropriate resource from the URLs you provide. This is not a conversion to another URL type; it is a way to offer multiple hosted image URLs.

Accessibility and markup checks

  • Write meaningful alt text when the image conveys information. Describe the subject or function rather than writing “image.”
  • Use alt="" for purely decorative images so assistive technology can skip them.
  • Keep the complete URL inside the quoted src value. Do not add spaces or line breaks inside a data URL payload.
  • Verify that the declared media type matches the actual file.
  • Do not put large photographs or repeated Base64 payloads into markup without a specific self-contained-document requirement; the HTML source grows with every embedded copy.

Troubleshoot a broken image URL

The image icon appears, but no picture loads

Open the exact src value in a new tab. A 404, permission page, or HTML response means the URL or hosting configuration is wrong. Correct the path, publish the file, or use the host’s direct-download address.

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

The data URL is rejected

Check the prefix, comma, and payload. It must look like data:image/png;base64,... for Base64 PNG data. Make sure the payload was not shortened by a text editor, shell, database field, or logging system.

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.

A local path works only on your computer

Replace the disk path with a relative URL deployed with your site or an absolute URL served over HTTP(S). A browser visiting your page cannot access another person’s filesystem.

The preview works, but there is no shareable link

readAsDataURL() is a client-side representation. Upload the file to a server or storage service and use the resulting public address when a persistent link is required.

Canvas export throws a security error

Review the origins of every image drawn to the canvas and configure the image server for the access conditions required by your application. Otherwise, obtain the image from the same origin or avoid exporting that canvas.

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 actual requirement is a screenshot of a web page rather than converting an existing image file, ScreenshotNeo returns a screenshot from one GET request. It accepts the page URL and can return PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. It also provides an MCP server for AI agents, including Claude and Cursor.

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.

See the parameter details in the ScreenshotNeo documentation. The same request can be made from common environments:

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.

cURL

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

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)

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}`);

ScreenshotNeo includes full-page and element capture, device and viewport settings, retina scale, PDF controls, custom CSS and JavaScript, waits, request blocking, cookies and headers, geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed links, asynchronous jobs, webhooks, bulk capture for up to 100 URLs per call, usage data, and an OpenAPI specification. Every feature is on every plan: 1,000 shots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Final decision

Use a hosted URL when the image should be public, reusable, independently cacheable, or easy to replace. Use a data URL for a small image that must travel inside a self-contained document or local preview. In both cases, put the resulting value in <img src="...">, provide accurate alternative text, and test the exact resource address in a browser.

Frequently Asked Questions

Can I turn a data URL into a permanent public link without uploading it?

No. A data URL is the image data embedded in markup. A permanent public link requires serving the file from a web-accessible host.

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

Does changing a file extension create a valid image URL?

No. The URL must return actual image bytes, and a data URL’s media type must match those bytes. Renaming a file or editing only the suffix does not convert its format.

Should I use a data URL for a large photograph?

Usually not. Embedding makes the HTML substantially larger and duplicates the image whenever the markup is copied. Host the photograph separately unless a self-contained document is the specific goal.

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.