Content · Web Development · HTML

HTML Image Width and Height Attributes

Width and height tell the browser an image's natural aspect ratio before the file has finished loading. This helps the page reserve space and reduces jumping content.

1 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

Width and height tell the browser an image's natural aspect ratio before the file has finished loading. This helps the page reserve space and reduces jumping content. Think about what the picture adds to the story, not just whether it looks nice on the screen.

What You Need to Know


Use dimensions that match the original image's ratio, then let CSS scale the display when needed. Width and height HTML attributes are numeric pixel dimensions, not values like 50%.

Pictures can make a page much easier to understand, but they are useful only when the file loads and the important meaning is also available as text.

Example: See It in Action


This example keeps the idea small. Copy it carefully, then follow the explanation instead of guessing what the browser will do.

This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.

<img
src="images/landscape.jpg"
alt="Sunset over mountains"
width="1200"
height="800">

Let’s Understand the Example


  • Img displays an image. Src chooses the file and alt provides a useful text alternative.
  • Width gives a useful size hint; for images, accurate dimensions help the browser reserve space.
  • Height works with width to communicate an image or media element’s aspect ratio.
  • Src tells the browser where to find an image or other embedded resource.
  • Alt supplies a text alternative for an image. Empty alt is appropriate for purely decorative images.

An image appears only if its file path is correct. If it is informative, its alt text should share the same useful meaning; if it is decoration, empty alt text is often right.

What Should You See?


If the image file is available, the picture appears in the page. If not, the browser may show a broken image or fallback text. The example alt text is “Sunset over mountains”. Check that the text alternative fits the picture’s purpose.

Cover the picture and read the surrounding text aloud. If essential information has disappeared, add a useful text alternative or nearby explanation.

Try It Yourself


  1. Try scaling a 1200-by-800 image to 600 pixels wide without changing its ratio.
  2. Save your changes, open or refresh the page, and compare the result with the original example.
  3. Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.

Common Beginner Mistakes


  • Giving width and height in the wrong ratio and making the picture look stretched.
  • Never guess at an image description. Write alternative text that matches the picture and its purpose on this page.

Key Takeaways


  • Width and height tell the browser an image's natural aspect ratio before the file has finished loading.
  • Img displays an image. Src chooses the file and alt provides a useful text alternative.
  • Use dimensions that match the original image's ratio, then let CSS scale the display when needed. Width and height HTML attributes are numeric pixel dimensions, not values like 50%.
Share this resourceSend this page to someone who may find it useful.