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

To add an image to a web page, put an HTML <img> element where it should appear, point its src attribute to an image file, and provide an appropriate alt value. For example: <img src="images/photo.jpg" alt="A red bicycle leaning against a brick wall">. Then use CSS to make it fit the page and, when useful, supply its real dimensions to reserve space while it loads.

1. Put the image file where your website can serve it

Before writing the HTML, make sure the image exists at a location your page can reach. It might be in your website project, such as an images folder, or hosted elsewhere at a URL. The src value must identify the file accurately, and the browser must be able to fetch it.

Use a relative path for a file in your site

If your page is at the site root and the image is in a folder named images, the path can be images/photo.jpg. A relative path is resolved from the page’s location. That means a page in a subfolder may need a different path to reach the same image; check the relationship between the HTML file and the image folder.

Use an absolute URL for a remotely hosted image

You can put an image URL in src when the file is hosted elsewhere. The URL must point to an accessible image file, not merely a page that displays an image. Remote hosting also means the image’s availability and delivery depend on that host.

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. Add the basic HTML image element

Place an <img> element in the HTML where you want the image to appear:

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

src identifies the image file. alt provides a text alternative. At least one of src or srcset is required for an image element, but a simple image can use only src. Use a supported image file format and check the path, filename, and capitalization if it does not load.

Include the image in a complete page

This minimal page shows the element in context. Save the HTML file beside the images folder, or adjust the path to match your project:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>A page with an image</title>
</head>
<body>
  <h1>A bicycle</h1>
  <img src="images/photo.jpg" alt="A red bicycle leaning against a brick wall" width="1200" height="800">
</body>
</html>

The width and height values in this example are only correct if the image’s actual dimensions are 1200 by 800 pixels. Replace them with the image’s real dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

3. Write alt text for the image’s purpose

Alt text is not a caption or a required inventory of everything visible. Decide what text alternative makes sense from the image’s role in the surrounding content. W3C Web Accessibility Initiative (WAI), in its Images Tutorial, states: “Images must have text alternatives that describe the information or function represented by them.”

Informative images

For an image that contributes information, briefly convey the essential point. In the example, “A red bicycle leaning against a brick wall” tells a reader what is shown. If the surrounding text already explains the same fact, avoid needlessly duplicating it; consider whether the image adds information the text alternative should convey.

Decorative images

If an image is purely decorative and adds no meaningful content or function, use an empty alt value: alt="". This lets assistive technology ignore the image. Do not use an empty value as a general shortcut for an image that communicates information.

Images that act as links or controls

If clicking an image performs an action or takes a visitor somewhere, make the alternative describe the function or destination. For example, the useful text for a linked company logo may be the company name or the destination, depending on the context—not a description of its colors and shape.

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.
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.

Charts and complex diagrams

A short alt value may not be enough to communicate a chart’s data or a detailed diagram. Provide enough text to convey the important information, and include a fuller explanation in nearby page content when needed. The text alternative should serve the image’s purpose, not simply announce that a chart exists.

WCAG 2.2 Success Criterion 1.1.1 requires text alternatives for non-text content that serve an equivalent purpose, subject to its specified exceptions. WAI’s H37 technique describes using the alt attribute on img elements; the appropriate value still depends on context.

4. Set the image’s dimensions and make it responsive

Adding the image’s actual intrinsic width and height helps the browser work out its aspect ratio and reserve space before the file finishes loading. That can reduce unexpected movement in the page layout. CSS determines how large the image is rendered; the HTML dimensions should describe the file, not serve as arbitrary styling numbers.

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

A basic fluid-image rule lets an image shrink to fit its container without distorting its proportions:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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 {
  max-width: 100%;
  height: auto;
}

With max-width: 100%, the rendered image will not exceed the available width. height: auto preserves its proportions as it shrinks. WAI’s C37 is an advisory technique for fitting images this way, not the only way to meet accessibility requirements.

Check that the page remains usable at narrow viewport widths. WCAG 2.2 Success Criterion 1.4.10 Reflow specifies vertical content at a width equivalent to 320 CSS pixels and horizontally scrolling content at a height equivalent to 256 CSS pixels, with exceptions for content that requires a two-dimensional layout. These are technical thresholds, not a guarantee that every individual image layout will work well automatically.

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

5. Choose the right image source strategy

One src is often all a small page needs. If you have several versions of the same image or need different crops or formats in different circumstances, HTML provides additional source-selection options.

Approach Use it when What to check
src You have one suitable image file for the page. Verify the path and that the file is the right size for its intended display.
srcset with sizes You have multiple resolutions of the same image and want the browser to choose among them. Use accurate width candidates and a sizes hint that reflects the layout.
<picture> The source itself needs to change, such as for alternate formats or art-directed crops. Check the current HTML syntax and browser support for the sources you use.

Offer width candidates with srcset and sizes

Use width descriptors such as 400w and 800w when listing image files at different intrinsic widths. The sizes attribute gives the browser a hint about how wide the image is expected to appear in the layout. The browser selects from the candidates, with discretion to account for conditions such as bandwidth. Do not mix width (w) and pixel-density (x) descriptors in one srcset.

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.
<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"
  width="1600"
  height="1000"
  alt="Snow-covered mountain reflected in a lake">

This is a pattern, not markup to copy without checking your assets. Make sure each candidate exists, its descriptor matches its real width, and the intended rendered size matches the page layout. The width and height attributes should describe the image’s intrinsic dimensions.

Use picture when resolution is not the only difference

Use <picture> when the browser should have source alternatives—for example, different image formats or a crop designed for a different layout. Use srcset and sizes for choosing among sizes of the same image; use <picture> when the source itself should vary. Consult the current MDN <img> reference for exact syntax and browser support, which can change.

6. Troubleshoot an image that does not appear or fit

  • Broken-image icon or missing image: Check that the src path points to the right location from the page’s location. Verify spelling, capitalization, file extension, and that the file is accessible.
  • Image appears stretched: Avoid forcing a rendered width and height that conflict with the image’s aspect ratio. For a fluid image, use max-width: 100%; height: auto;.
  • Image overflows its container: Apply the responsive CSS rule and check for other CSS that sets a larger fixed width.
  • Space jumps when the image loads: Add the image’s actual intrinsic width and height attributes so the browser can reserve its ratio and space.
  • Image is visible but its meaning is not conveyed: Review whether the image is informative, decorative, functional, or complex, then choose the corresponding text alternative. An empty alt is for decoration, not for every image.
  • A responsive candidate is not selected as expected: Confirm that the files and width descriptors agree, the sizes hint reflects the layout, and you have not mixed w and x descriptors in one srcset.

Or skip the browser setup

If what you need is a screenshot of a web page as an image file, ScreenshotNeo can return a PNG, JPEG, or WebP from one API request. That is different from hosting an image for your page: after receiving the screenshot file, you still need to put it somewhere your site can serve and reference it with src. See the ScreenshotNeo API documentation.

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

Cookie banners, popups, and chat widgets are removed before the shot; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up for 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.

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.