To show one image in an HTML page, use an <img> element with its src attribute set to the image’s URL. Give meaningful images appropriate alternative text, and set the image’s actual width and height when you know them.
<img src="images/photo.jpg"
alt="A red bicycle leaning against a brick wall"
width="800"
height="600">
The dimensions in this example are illustrative: use the file’s real intrinsic dimensions, not these numbers unless they happen to match. The URL must resolve to a file the browser can access. The HTML Standard’s image section recommends <img> with src when embedding a single image resource.
Write the image element
An image is a separate resource from the HTML document. The browser reads the markup, then requests the file named by src. A minimal example is:
<img src="images/photo.jpg" alt="A red bicycle leaning against a brick wall">
The src value is a URL. It can be a relative path on your site, such as images/photo.jpg, or an absolute URL to an image available on another server. For a relative URL, the browser resolves the path against the page’s URL. Make sure the file is deployed at that location and that the spelling and capitalization match; some servers treat uppercase and lowercase filenames as different files. See MDN’s guide to HTML images and reference for <img>.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Example with a relative path
If the HTML page is at https://example.com/about/ and the image is deployed at https://example.com/about/images/team.jpg, this relative source points to it:
<img src="images/team.jpg" alt="The support team at the office">
For a site organized differently, adjust the path. For example, ../images/team.jpg moves up one directory before looking for the image. If the file is missing or the path is wrong, the browser cannot display it; check the requested URL in the browser’s developer tools and confirm the deployed filename.
Choose useful alternative text
The alt attribute provides a text alternative to an image. For an informative image, describe the information or purpose that matters in the surrounding context—not the filename, and not every visible detail. The W3C’s H37 technique advises specifying a short text alternative for an img element.
Informative images
Describe what a reader needs to understand from the image. For example, if a chart communicates that monthly sales rose through the year, the alternative should convey that trend rather than say only “chart.” The right wording depends on what the page is explaining; an image does not have one universally correct description independent of context.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #2
Decorative images
If an image adds no information and is purely decorative, use an empty alternative:
<img src="images/blue-divider.png" alt="">
Do not omit alt just because an image is decorative: an empty value explicitly marks it as having no text alternative to convey. The W3C WAI alt decision tree helps decide what alternative fits an image’s purpose and context.
Images that are the only content in a link or button
If an image is the only content inside a link or button, its alternative should communicate the link’s destination or the button’s action. Otherwise, someone using the page without the image may not know what the control does.
When you need a caption
Alternative text is not a caption. If readers should see a caption, group the image and caption with <figure> and <figcaption>:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
<figure>
<img src="images/bridge.jpg"
alt="A suspension bridge crossing a wide river"
width="1200"
height="800">
<figcaption>The bridge at sunset.</figcaption>
</figure>
Avoid using title as a replacement for alt; it is not reliably available to keyboard, touch, or assistive-technology users. These distinctions are covered in MDN’s image-element reference.
Set the image’s dimensions and display size
The HTML width and height attributes take integer pixel values without units. Set them to the image’s intrinsic dimensions when known, preserving its real aspect ratio:
<img src="images/bridge.jpg"
alt="A suspension bridge crossing a wide river"
width="1200"
height="800">
Accurate attributes let the browser reserve the image’s proportional space before its bytes arrive, which can reduce layout movement as the page loads. They describe the source image’s dimensions; they are not CSS lengths. To make the image adapt to a narrower container, use CSS for its rendered size:
img {
max-width: 100%;
height: auto;
}
With that rule, the image can shrink to fit its container while retaining its proportions. CSS can also specify a particular display size, but avoid distorting the image by forcing a width and height with a different ratio from the source. MDN discusses intrinsic dimensions and sizing in its reference for the img element and HTML images guide.
Rank #4
- 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
Use multiple image files for responsive pages
If you have several versions of an image, srcset lets the browser choose from the available candidates. For width-described files, pair it with sizes, which tells the browser how wide the image is expected to appear at different viewport sizes:
<img
src="images/forest-800.jpg"
srcset="images/forest-400.jpg 400w,
images/forest-800.jpg 800w,
images/forest-1600.jpg 1600w"
sizes="(max-width: 600px) 100vw, 800px"
alt="A forest path beneath tall trees"
width="1600"
height="1067">
The 400w, 800w, and 1600w labels describe the candidate files’ widths in pixels. In this example, sizes says the rendered slot is the viewport width on screens up to 600 pixels wide, and otherwise 800 pixels. Candidate selection depends on the available files and the layout information you provide; it is not a command to display a particular file at a particular CSS size.
Width descriptors and density descriptors
Use width descriptors such as 400w when your candidates have different pixel widths, and provide sizes to describe the expected layout slot. Density descriptors such as 2x instead describe pixel density, for example to provide a higher-density version for a display. Do not mix width and density descriptors in the same srcset. See MDN’s responsive image guidance for the syntax and behavior.
When to use <picture>
Use <picture> with nested <source> elements when you need art direction—different image crops or compositions for different conditions—or format-specific alternatives. For a single file, or a set of resolutions of the same image, a simple <img> with src and, when appropriate, srcset is enough.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsBest Value
Decide when the browser should load the image
Images load eagerly by default. For an image that is offscreen and not important immediately, loading="lazy" can defer loading until it is nearer to the viewing area:
<img src="images/gallery-detail.jpg"
alt="Carved details on the gallery doorway"
width="1200"
height="800"
loading="lazy">
Do not apply lazy loading automatically to an important image in the initial viewport: that can delay an image a reader needs to see straight away. Keep dimensions on lazy-loaded images so the browser can reserve their space before downloading them. Whether a loading choice improves a particular page depends on the page and should be measured; do not assume a guaranteed speed gain for every image. MDN documents loading and image behavior in its reference.
Use CSS backgrounds for decoration, not image content
Use <img> when an image is content that needs a text alternative or belongs in the document’s meaning. A CSS background-image is suited to decorative presentation, such as a texture or an ornament behind other content. Do not make a background image the only way essential information is conveyed without providing that information in an accessible text equivalent. MDN explains this distinction in its HTML images guide.
Troubleshoot an image that does not appear
- Broken-image icon or missing image: Check the actual URL requested by the browser. Confirm the file exists at that location, the relative path is based on the page’s URL, and filename capitalization matches the deployed file.
- Image appears squashed or stretched: Compare the displayed proportions with the source. Correct inaccurate width and height values, or use CSS such as
max-width: 100%; height: auto;so the image scales without changing its aspect ratio. - Image is visible but has no useful accessible description: Decide whether it conveys information, is decorative, or is the only content in a control. Use purposeful alternative text for the first and third cases, and
alt=""for a purely decorative image. - A caption is missing: Add visible caption text in a
<figcaption>inside a<figure>; do not expectalttext to serve as the caption. - The page loads unnecessary image data before it is needed: Consider
loading="lazy"for suitable offscreen images, but not casually for a key image in the initial viewport. Keep intrinsic dimensions so space can be reserved. - The browser chooses an unexpected responsive candidate: Check that each width descriptor matches the candidate file’s real width and that
sizesreflects the rendered slot. Also confirm that width and density descriptors have not been mixed in onesrcset.
Or skip the browser setup
If the image you need is a capture of a web page, ScreenshotNeo can return a screenshot image from one GET request. This does not replace the HTML <img> element: save or host the returned image where your page can access it, then reference that file with src. Keep the API key on a server rather than exposing it in public page markup. See the ScreenshotNeo documentation for API details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
After the command saves the image in your project and you deploy it with the page, you can use ordinary HTML to show it:
Quick Recap
<img src="images/shot.webp" alt="Screenshot of the Stripe home page" width="1200" height="800">
The example dimensions are only suitable if they match the saved image’s actual dimensions. ScreenshotNeo can accept a website URL and return PNG, JPEG or WebP, but a PDF response is not an image source for an <img> element. Its clean-shot features remove cookie or consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses include X-Page-Verdict and X-Billed headers. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client. The Free plan includes 1,000 shots per month with no card, and paid plans start at $5 for 3,000 shots. Sign up for ScreenshotNeo’s free plan.
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.

