October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Write an HTML Tag Correctly and Professionally

Write an accessible, well-formed HTML img element with meaningful alt text, intrinsic dimensions, and optional responsive sources or lazy loading when appropriate.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A well-formed HTML image uses a valid src, alternative text chosen for the image’s purpose, and intrinsic width and height values. Add responsive image sources or deferred loading only when they suit the page. The <img> element is void: it has no closing tag.

A solid default image tag

For an informative image, write markup like this, replacing the example path, dimensions and description with values that match the actual asset and its role on your page:

As an Amazon Associate I earn from qualifying purchases.

<img
  src="/images/field-guide.jpg"
  alt="Red fox standing in a snowy field"
  width="1200"
  height="800"
  loading="lazy"
/>

This is an illustrative example, not a tested implementation. The alternative text is appropriate only if it accurately describes the image and fits the surrounding content. See MDN’s <img> reference and HTML images guide.

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

Choose alt text for the image’s purpose

The alt attribute provides a textual replacement for an image’s content or purpose. Write a concise description that conveys what matters in context; do not use a filename or generic text such as “image.” The right wording depends on the surrounding page, not just the pixels.

#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
  • Informative image: Describe the relevant content or meaning.
  • Decorative, redundant or supplemental image: Use alt="" when the image adds no information that needs to be conveyed separately. This avoids redundant output for assistive technology.
  • Image that is a link: Make the alternative identify the link’s destination or purpose, rather than merely describing its appearance.

The HTML Standard discusses these alternative-text cases in its embedded content section.

Set dimensions without distorting the image

Include the image’s intrinsic width and height so the browser can reserve space with the correct aspect ratio before the file loads. This helps reduce layout shifts. Use CSS to control the displayed size, and provide image files appropriate to the display rather than stretching or squeezing an image with mismatched dimensions. MDN explains this distinction in its HTML images guide.

Serve responsive image candidates when useful

Responsive markup lets the browser select an image file suited to the rendered slot or display density. The two common srcset patterns address different needs; do not combine their descriptor types in one srcset.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Markup approach Key detail
Different file widths for a responsive layout srcset with w descriptors, paired with sizes sizes describes the expected rendered slot width so the browser can choose a candidate.
Same rendered size, different display pixel densities srcset with x descriptors This density-selection pattern does not require sizes.
Different crop or art direction by viewport <picture> with conditional <source> elements Keep an <img> fallback with appropriate alternative text.

For example, a width-based pattern looks like this:

<img
  src="/images/field-guide-800.jpg"
  srcset="/images/field-guide-400.jpg 400w,
          /images/field-guide-800.jpg 800w,
          /images/field-guide-1200.jpg 1200w"
  sizes="(max-width: 600px) 100vw, 600px"
  alt="Red fox standing in a snowy field"
  width="1200"
  height="800"
/>

Here sizes is an example of a layout description, not a universal value: adapt it to the space the image actually occupies. For guidance on width and density descriptors, sizes, and art direction, see MDN’s responsive images guide.

Use lazy loading selectively

loading="lazy" can defer an image that is outside the initial viewport. It can suit images farther down a page; do not apply it automatically to every image. An image expected to be visible immediately should not be deferred by default. Keep its dimensions present so the browser can reserve its space while it loads. MDN covers the attribute in the <img> reference.

Rank #4
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

Common mistakes to avoid

  • Omitting alt, using a filename, or writing only “image.”
  • Giving decorative or redundant imagery a description that repeats nearby information instead of using empty alt text.
  • Leaving out intrinsic dimensions, or using them to resize an image inaccurately.
  • Using width-based srcset without a useful sizes value, or mixing w and x descriptors.
  • Putting essential instructions in title. MDN notes that its support is unpredictable and it may appear only on mouse hover; put important content in page text or appropriate alt text instead. See the MDN reference.
  • Lazy-loading every image without considering whether it should appear immediately.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use images you have the right to publish

When selecting an image, make sure you own it, have permission to use it, or comply with its licensing conditions. MDN’s HTML images guide discusses this practical consideration; it is not a substitute for legal advice.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.