0
0
HTMLmarkup~10 mins

Image tag usage in HTML - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Image tag usage
[Read <img>] -> [Create IMG element node] -> [Load image from src URL] -> [Calculate image size] -> [Reserve space in layout] -> [Paint image pixels] -> [Composite image on page]
The browser reads the <img> tag, creates an image element, loads the image from the source URL, calculates its size, reserves space in the page layout, paints the image pixels, and finally composites it into the visible page.
Render Steps - 3 Steps
Code Added:<img src="https://via.placeholder.com/150" alt="Placeholder Image">
Before
[Empty page]

_________________________
|                       |
|                       |
|                       |
|                       |
|                       |
|_______________________|
After
[Image placeholder box appears]

_________________________
|  [150x150 image]       |
|  ██████████████████    |
|  ██████████████████    |
|  ██████████████████    |
|                       |
|_______________________|
The browser inserts the image element and loads the image from the URL, reserving space and displaying the image pixels.
🔧 Browser Action:Creates IMG element node, loads image resource, triggers layout and paint.
Code Sample
This code shows a simple image displayed on the page with alternative text for accessibility.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Image Example</title>
</head>
<body>
  <img src="https://via.placeholder.com/150" alt="Placeholder Image">
</body>
</html>
Render Quiz - 3 Questions
Test your understanding
After applying step 1, what do you see on the page?
AA 150x150 pixel image displayed
BOnly alt text shown
CEmpty space with no image or text
DA broken image icon
Common Confusions - 3 Topics
Why does my image not show but space is reserved?
If the src URL is broken or image fails to load, the browser still reserves space based on width and height attributes or natural image size, showing empty space or alt text.
💡 Check src URL and alt text; reserved space stays even if image missing (see render_step 3).
Why doesn't my alt text appear when the image loads?
Alt text only shows if the image fails to load or for screen readers. When image loads correctly, alt text is hidden visually but used for accessibility.
💡 Alt text is invisible if image loads; it is for screen readers or fallback (see render_step 2).
Why does my image look stretched or squished?
If width and height attributes do not match the image's natural ratio, the browser stretches or squishes the image to fit those dimensions.
💡 Use matching width and height or CSS object-fit to keep proportions (see render_step 3).
Property Reference
AttributePurposeEffect on VisualCommon Use
srcURL of the image fileDisplays the image from this sourceRequired to show image
altAlternative text for accessibilityShows text if image fails or for screen readersImportant for accessibility
widthWidth of the image in pixelsResizes image width and layout spaceControl image size
heightHeight of the image in pixelsResizes image height and layout spaceControl image size
titleTooltip text on hoverShows text when mouse hovers over imageOptional descriptive tooltip
Concept Snapshot
The <img> tag displays images on a webpage. Key attributes: src (image URL), alt (text for accessibility), width and height (control size). Browser loads the image, reserves space, and paints it. Alt text is invisible but important for screen readers. Width and height resize the image and layout space. Broken images show alt text or empty space.