A useful HTML image needs more than a working file path. Decide what information the image contributes, provide an appropriate text alternative, reserve its aspect ratio, and choose loading behavior that suits its position on the page. These choices affect accessibility and layout as well as the time it takes a reader to see the content.
Start with the role of the image
For an informative image, alt should convey the information needed in its context. For a purely decorative image, an empty alt attribute can keep assistive technology from announcing redundant decoration. A linked image or image-only button needs an accessible name that describes its purpose. A complex chart may require nearby text or a longer explanation in addition to short alt text. The same picture can need different treatment on two pages because its role differs.
An original markup example
Suppose a real photograph shows a fern frond with curled tips and its intrinsic dimensions are 1200 by 800 pixels. The following is illustrative markup for that situation; the filename is a placeholder you must replace with your actual asset. The image is assumed to be below the initial viewport.
<img src="images/fern.jpg"
alt="Fern frond with curled tips"
width="1200" height="800"
loading="lazy">In your stylesheet, img { max-width: 100%; height: auto; } lets the image shrink to fit a narrow container while retaining its aspect ratio.
Dimensions are not a command to stretch the photo
Correct width and height attributes help the browser determine an aspect ratio before the image finishes loading. They do not require displaying a 1200-pixel image at 1200 CSS pixels inside a narrow article. Use dimensions that match the actual asset, and check the page at a narrow viewport. Reserving the wrong ratio or forcing unrelated CSS width and height values can still produce distortion or a layout change.
Use lazy loading selectively
Lazy loading can help for an image well below the initial viewport. It is usually the wrong choice for the main above-the-fold image that becomes the page’s Largest Contentful Paint element: delaying discovery or loading can delay the main content. Do not copy loading="lazy" onto every image without considering its position. Diagnose actual loading and rendering first; a particular attribute is not a guarantee of a good field performance result.
Give the browser useful source choices
A srcset with width descriptors can offer files at different pixel widths, while sizes describes the image’s expected display width under the relevant layout conditions. The browser uses these hints and the device’s pixel density when choosing a resource. Supply real matching assets and a sizes value that reflects your CSS; a very large original file plus a small CSS display box does not by itself avoid transferring the large file. Test which resource the browser actually requests.
Check the result as a reader
Consider the page without its images: is the important information still available? Check that informative alternatives make sense without seeing the picture, decorative images are not announced unnecessarily, image-only links have meaningful names, and the layout does not jump when images arrive. Then examine the Network panel and the page’s main-content timing. This checklist is an original synthesis of the documented decisions; it is not a claim that one markup sample establishes accessibility conformance for an entire site.
