October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
accessibility

How to Paste an Image into HTML: A Complete Guide to Linked, Embedded, and Responsive Images

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

To add an image to an HTML page, use an <img> element with a web-accessible URL in src and useful alt text:

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

The img element is void, so it does not have a closing tag. “Paste” can also mean embedding the actual image bytes in the markup; for that, use a Base64 data URL. The right choice depends on whether you want a maintainable, cacheable image file or a self-contained HTML document.

1. Add a normal image file with img

For most websites, keep the image as a separate file and reference it from HTML. The HTML Standard recommends img with src when a page has one image resource (WHATWG HTML Living Standard).

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

What each attribute does

  • src identifies the image URL. It may be relative, such as images/photo.jpg, or absolute, such as https://example.com/photo.jpg.
  • alt supplies a text alternative when the image cannot be seen or loaded and helps assistive technology understand its content.
  • width and height declare the intrinsic dimensions. Browsers can reserve the correct aspect-ratio space before the file arrives, reducing layout movement.

Use a meaningful description when the image conveys information or performs a function. For a purely decorative image, use an empty value: alt="". Do not omit alt on meaningful content.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Relative versus absolute URLs

A relative URL is resolved from the HTML document’s location. If index.html is next to an images folder, images/photo.jpg works. From a page in blog/, the same file may require ../images/photo.jpg. An absolute URL includes the complete origin and path.

<!-- Relative URL -->
<img src="../images/photo.jpg" alt="A red bicycle" width="800" height="600">

<!-- Absolute URL -->
<img src="https://cdn.example.com/photo.jpg" alt="A red bicycle" width="800" height="600">

Do not use a path on your own computer, such as C:UsersAlexPicturesphoto.jpg. A visitor’s browser cannot read your local disk. Upload the asset to your site or another web-accessible host, then use its URL.

2. If “paste” means embed the image bytes

A data URL places the encoded image inside the src attribute:

<img src="data:image/png;base64,BASE64_IMAGE_DATA" alt="A red bicycle">

Replace BASE64_IMAGE_DATA with the complete Base64 string; the placeholder itself is not a usable image. The prefix must match the media type, for example data:image/png;base64, or data:image/jpeg;base64,.

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

When a data URL is appropriate

  • Small icons or illustrations that must travel in one self-contained HTML file.
  • Generated documents, email templates, or test fixtures where a separate request is undesirable.
  • Offline examples where the markup and bytes are intentionally bundled.

Embedding avoids a separate image request, but it makes the HTML substantially larger and prevents the image from being cached as an independent resource. For ordinary page content, a separate file is easier to edit, deploy, cache, and reuse. The MDN image guidance covers this distinction (MDN: Using images).

Generate a data URL safely

Do not manually retype a long encoded value. Use an image-to-Base64 tool in your build process or a script that reads the file, encodes it, and writes the correct MIME prefix. Treat the resulting HTML as text: a missing character can make the image fail to decode.

3. Make images responsive

A single large file may be wasteful on a phone, while a small file looks soft on a high-density display. Use srcset and sizes to offer width variants:

<img
  src="photo-800.jpg"
  srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w"
  sizes="(max-width: 600px) 100vw, 800px"
  width="800"
  height="600"
  alt="A red bicycle leaning against a brick wall">

The width descriptors (400w, 800w, and so on) tell the browser the intrinsic widths. The sizes expression describes how wide the image will render; the browser then chooses a suitable candidate.

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.

Use picture for format or art-direction choices

The picture element lets you provide conditional sources while retaining an img fallback (MDN: picture element):

<picture>
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" width="800" height="600" alt="A red bicycle leaning against a brick wall">
</picture>

Keep the img inside picture. It is the fallback resource and carries the alternative text and dimensions. Add media conditions to source elements when you need different crops for different layouts.

4. A reliable workflow from local file to published page

  1. Choose and inspect the asset. Confirm the file format, pixel dimensions, orientation, and that you have permission to publish it.
  2. Place or upload the file. Put it in a site directory such as /images/, or upload it to your CDN or CMS.
  3. Write the element. Set src, a useful alt, and known width/height.
  4. Use responsive sources when needed. Add srcset/sizes for variants or picture for alternate formats and crops.
  5. Preview and inspect. Open the page over the same protocol and path structure used in production. Check the browser’s Network and Console panels for 404, MIME-type, or decoding errors.
  6. Test accessibility and layout. Turn off images or use a screen reader to verify that the alternative text communicates the intended information. Test narrow and wide viewports.

5. Common failures and fixes

Broken-image icon or a 404 response

The URL is wrong, the filename case differs, or the file was not deployed. Check the exact path in the browser’s Network panel. On case-sensitive servers, Photo.jpg and photo.jpg are different files.

The image works locally but not online

Your local path, development server route, or filename may not exist in production. Replace computer paths with a deployed URL and verify that the asset is included in the build output.

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

Mixed-content or blocked request

If the page is HTTPS, an HTTP image may be blocked. Serve the image over HTTPS and check the browser’s security message.

Image appears stretched

Do not declare dimensions that conflict with the file’s ratio. Use the intrinsic ratio in width/height and control visual sizing with CSS:

img {
  max-width: 100%;
  height: auto;
  display: block;
}

No alternative text

Write what a user needs to know, not a filename such as IMG_1234.jpg. If the image is decorative and conveys no information, use alt="".

Using a closing </img> tag

img is a void element. Write <img ...> (or the HTML-compatible <img ... />), never a paired closing tag.

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

Data URL does not render

Check the MIME prefix, ensure the Base64 data is complete, and remove accidental line breaks or characters. A very large data URL can also make the document unwieldy; use a normal image URL instead.

6. Performance, caching, and security considerations

  • Reserve space. Correct dimensions reduce cumulative layout movement while the image loads.
  • Send an appropriate file. Responsive candidates let the browser avoid downloading a desktop-sized asset on a small screen.
  • Keep reusable assets separate. A separate URL can be cached across pages; embedding duplicates bytes in every document that contains the data URL.
  • Use trustworthy sources. An external image can disappear or change without notice. Host important assets yourself or on a service you control, and use HTTPS.
  • Protect privacy. Loading a third-party image can reveal a visitor’s IP address and request metadata to that host. Choose hosts and URLs accordingly.
  • Do not expose secrets. Image URLs in HTML are public. Never put API keys, passwords, or private tokens in src.
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 obtain a clean image of a web page rather than hand-author an img tag, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. It accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; you can turn each cleanup step off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

Use the API examples in the ScreenshotNeo documentation:

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

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const bytes = new Uint8Array(await res.arrayBuffer());
// Save bytes as shot.webp in your application.

ScreenshotNeo includes full-page and element captures, 12 device presets plus custom viewports, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen-TTL caching, signed links, asynchronous webhooks, bulk capture for up to 100 URLs per call, usage data, and an OpenAPI specification. Parameter names used by other screenshot APIs also work.

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

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to get started.

Best Value
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • 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

7. Quick decision guide

Need Use Why
Normal page content Separate file with img src Simple, maintainable, and independently cacheable
One small self-contained document Data URL No separate image request, at the cost of larger HTML
Different sizes for devices srcset and sizes Lets the browser select a suitable resource
Alternate formats or crops picture Provides conditional sources with an img fallback
Programmatic webpage screenshots ScreenshotNeo API One call, cleanup before capture, and only clean shots billed

Frequently Asked Questions

Can I paste an image directly from Word or Google Docs into HTML?

Those applications usually place an image on the clipboard, not a public URL. Save or upload the image first, then reference its web URL in src, or deliberately convert its bytes to a complete data URL.

Should I use PNG, JPEG, or WebP in the src attribute?

The HTML method is the same for each format; choose files your target browsers and workflow support, and provide an appropriate MIME type when using a data URL.

Does HTML require a slash in <img />?

No. HTML treats img as a void element, so <img> is valid. A trailing slash is optional HTML syntax.

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

Why is my Base64 image much larger than the original file?

Base64 representation adds encoding overhead, and embedding it repeats the bytes in every document that contains it. Use a separate URL for reusable or larger images.

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 *

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.

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.