Kit Library / Computer Science / Web Development

⚡ Topic Learning Kit

html images explain deeply

English 18 leveled MCQs 20 flashcards 9 games Free

Shared by a Veda teacher · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

The <img> Tag Is a Void Element

One tag, no closing — that's how images load.

HTML images are inserted with the <img> tag. It is a void (self-closing) element — it has no closing tag and no content inside it.

↳ <img> is self-contained: it references an external file, not inline content.

📖 Definition

Two Attributes You Cannot Skip

src and alt — the non-negotiables.

↳ Without src, nothing loads; without alt, the image is inaccessible.

⭐ Important Fact

alt Text Serves Three Purposes

alt is not just a fallback.

↳ alt is accessibility, fallback, and SEO in one attribute.

⚖️ Comparison

Absolute vs Relative Image Paths

Where does the browser look for your image?

↳ Use relative paths for your own files; absolute URLs for external images.

⭐ Important Fact

Common Web Image Formats

JPG, PNG, GIF, SVG, WebP — pick wisely.

↳ Match format to content: JPEG for photos, PNG/SVG for graphics.

💡 Key Idea

Sizing Images: width and height

Control size without breaking layout.

Setting width and height reserves space before the image loads, preventing layout shift.

↳ Always set width/height to avoid content jumping as images load.

⚠️ Common Mistake

Stretching Images Distorts Them

Don't squash your images.

↳ Preserve aspect ratio by scaling one dimension or using CSS.

✅ Best Practice

Make Images Responsive

One image, every screen size.

↳ max-width: 100% + height: auto = responsive images with one rule.

✏️ Example

Image as a Link

Click the picture, go somewhere.

↳ Wrap <img> in <a> to create image links.

🚫 Warning

Never Use alt for Decorative Images

Sometimes empty alt is correct.

↳ Decorative images get alt="" — meaningful images get real descriptions.

🎯 Exam Tip

Exam Favourite: src vs alt

Two attributes, one common trap.

↳ src loads the image; alt describes it when it can't load.

🧠 Memory Trick

Remember: S-A-W-H

Four letters, four attributes.

S-A-W-H: Src, Alt, Width, Height — the four most-used <img> attributes.

↳ S-A-W-H keeps the core <img> attributes in memory.

❓ Did You Know

Images Are Not Inside the HTML File

The HTML only points to them.

The <img> tag does not contain the image — it only references an external file. The browser fetches that file separately over the network.

↳ HTML links to images; it never embeds the pixel data itself.

🌍 Real World

Why alt Text Matters in Real Sites

Accessibility is a legal requirement.

↳ Real-world sites treat alt text as a legal and UX necessity.

🛠️ Application

Using <figure> and <figcaption>

Give your image a caption.

↳ <figure> + <figcaption> pairs an image with its caption semantically.

Smart notes

What you'll study, topic by topic

1

HTML Images: Embedding and Explaining Deeply

15 min

HTML images are embedded using the tag, a void element that pulls an external image file into a web page. Mastery involves understanding required attributes (src, alt), sizing, formats, responsiveness, and accessibility…

  • `` is a void element — it has no closing tag.
  • The `src` attribute holds the URL or path to the image file.
  • The `alt` attribute provides text for screen readers and broken-image fallback.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 18 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 6 questions

Q1. Which statement best describes what an `<img>` tag actually contains?

Beginner
A A pointer that tells the browser where to fetch the image
B A CSS rule that styles the image
C A JavaScript object that loads the image
D The image pixels stored inside the HTML file
Show the answer

A · A pointer that tells the browser where to fetch the image

The `` tag does not store pixels. It is a placeholder that instructs the browser to fetch an external file and paint it in place. The actual image data lives in a separate file such as `.jpg` or `.png`.

Q2. A student writes `<img src="logo.png">` with no other attributes. Which attribute is missing that is required for accessibility?

Beginner
A `width`
B `srcset`
C `loading`
D `alt`
Show the answer

D · `alt`

`alt` is the alternative-text attribute required for accessibility. Without it, screen readers may read the filename aloud and users on broken connections see nothing useful.

Q3. Which of these is a void element with no closing tag?

Beginner
A `<span>`
B `<img>`
C `<p>`
D `<div>`
Show the answer

B · `<img>`

`` is a void element — it has no closing tag and cannot contain child content. The other three are container elements that wrap content.

Q4. A designer places a purely decorative divider image on a page. What should the `alt` attribute be?

Beginner
A `alt="decorative"`
B `alt=""` (empty)
C The `alt` attribute should be omitted entirely
D `alt="divider image"`
Show the answer

B · `alt=""` (empty)

An empty `alt=""` tells assistive technology to skip the image, which is correct for decoration. Omitting `alt` entirely is worse because screen readers may then read the filename aloud.

Q5. Which format is the best choice for a photograph on a product page?

Beginner
A SVG
B GIF
C JPEG
D PNG
Show the answer

C · JPEG

JPEG is designed for photographs, producing small files with millions of colours. SVG is for vectors, GIF is limited to 256 colours, and PNG produces larger files for photographic content.

Q6. `<img>` is a void element, so it has no closing tag and cannot contain child content.

Beginner
A True
B False
Show the answer

A · True

`` is a void element, so it has no closing tag and cannot contain child content.

Building up · 7 questions

Q7. A developer writes `<img src="hero.jpg" width="1200" height="600">`. What is the main benefit of including those HTML width and height attributes?

Intermediate
A The image file is automatically compressed
B The browser reserves space early, preventing layout shift
C The image loads before the surrounding text
D The image becomes responsive on small screens
Show the answer

B · The browser reserves space early, preventing layout shift

HTML `width` and `height` communicate the intrinsic aspect ratio so the browser can reserve the correct box before the file arrives. This prevents the text-jumping layout shift when the image finally loads.

Q8. A page has a large footer logo far below the fold. Which attribute should be added to defer its download?

Intermediate
A `decoding="async"`
B `sizes="100vw"`
C `fetchpriority="low"`
D `loading="lazy"`
Show the answer

D · `loading="lazy"`

`loading="lazy"` defers off-screen images until the user scrolls near them. This is one of the cheapest performance wins available in HTML.

Q9. A developer writes: ```html <img src="small.jpg" srcset="small.jpg 480w, medium.jpg 1024w, large.jpg 1920w" sizes="(max-width: 600px) 480px, 1024px" alt="Mountain landscape"> ``` What does the browser do with this markup?

Intermediate
A Ignores `srcset` and uses only `src`
B Picks the smallest suitable file based on the `sizes` hint
C Downloads all three files and displays the largest
D Always downloads `small.jpg` regardless of screen
Show the answer

B · Picks the smallest suitable file based on the `sizes` hint

The `w` descriptors declare each file's real pixel width, and `sizes` tells the browser how wide the image will render at each breakpoint. The browser then downloads only the file that fits, saving bandwidth.

Q10. Why is omitting the `alt` attribute worse than writing `alt=""`?

Intermediate
A Because search engines will not index the page
B Because the image will not load without `alt`
C Because the browser will show a broken-image icon
D Because screen readers may read the filename aloud
Show the answer

D · Because screen readers may read the filename aloud

An empty `alt=""` deliberately silences decoration. Omitting `alt` entirely leaves assistive tech to fall back on the filename, which is more confusing than silence.

Q11. A developer sets `<img src="a.jpg" width="500">` and assumes this is the same as CSS sizing. Why is this assumption wrong?

Intermediate
A HTML `width` only works on SVG images
B HTML `width` sets the intrinsic aspect-ratio hint; CSS controls rendered size
C HTML `width` overrides CSS and prevents responsiveness
D HTML `width` is deprecated and does nothing
Show the answer

B · HTML `width` sets the intrinsic aspect-ratio hint; CSS controls rendered size

The HTML `width` and `height` attributes tell the browser the intrinsic aspect ratio so it can reserve space early. CSS `width` and `height` control the rendered size. Best practice is to set both.

Q12. A news site serves crisp photos to retina phones without punishing desktop users. Which pair of attributes makes this possible?

Intermediate
A `srcset` and `sizes`
B `alt` and `title`
C `loading` and `decoding`
D `width` and `height`
Show the answer

A · `srcset` and `sizes`

`srcset` offers multiple files at different widths, and `sizes` tells the browser how wide the image will render at each breakpoint. Together they let the browser pick the right file for each device.

Q13. Which of these is NOT a reason `alt` text matters?

Intermediate
A Search engines use it as a content signal
B It reduces the image file size on disk
C Screen readers announce it in place of the image
D It displays when the image fails to load
Show the answer

B · It reduces the image file size on disk

`alt` serves accessibility, broken-image fallback, and SEO. It has no effect on the file size of the image itself — that is determined by the format and compression.

Topper level · 5 questions

Q14. A developer needs an icon that stays sharp at any zoom level and has a tiny file size. Which format fits best?

Advanced
A GIF
B PNG
C SVG
D JPEG
Show the answer

C · SVG

SVG is vector-based, so it scales infinitely without quality loss and produces very small files for icons and charts. Raster formats like JPEG, PNG, and GIF would blur or bloat at large sizes.

Q15. A team is choosing between a 2 MB PNG and a 150 KB JPEG for a photograph that will look identical either way. Which is the better choice for a performance-conscious page?

Advanced
A Either, because file size does not affect page speed
B The PNG, because lossless quality always wins
C The PNG, because it supports transparency
D The JPEG, because it delivers the same look at a fraction of the bytes
Show the answer

D · The JPEG, because it delivers the same look at a fraction of the bytes

Matching format to content is one of the highest-leverage performance decisions on a page. A 2 MB PNG photograph where a 150 KB JPEG looks identical is a real, common waste that slows the page.

Q16. A developer is deciding between `<img>` and CSS `background-image` for a product photo that customers should be able to right-click and save. Which is the better choice and why?

Advanced
A `background-image`, because it supports `srcset`
B `<img>`, because it is real content that supports alt text and saving
C `<img>`, because CSS backgrounds cannot display photographs
D `background-image`, because it renders faster
Show the answer

B · `<img>`, because it is real content that supports alt text and saving

Meaningful content belongs in ``, which supports `alt` text, right-click saving, and SEO value. CSS `background-image` is for decoration and often does not allow saving.

Q17. A developer is optimizing a webpage that includes multiple images. They want to ensure that images below the fold do not start downloading until they are about to be viewed. Which attribute should they use in their `<img>` tags to achieve this?

Advanced
A sizes=''
B srcset=''
C loading='lazy'
D loading='eager'
Show the answer

C · loading='lazy'

The correct option is `loading='lazy'`, which defers the loading of off-screen images until the user scrolls near them, improving page load performance.

Q18. A web developer is tasked with creating a responsive image solution for a product page. They want to ensure that the browser selects the most appropriate image size based on the device's screen width. They write the following code: ```html <img src='small.jpg' srcset='small.jpg 480w, medium.jpg 1024w, large.jpg 1920w' sizes='(max-width: 600px) 480px, 1024px' alt='Product image'> ``` What will happen if the browser's viewport is 500 pixels wide?

Advanced
A The browser will not display any image.
B The browser will download 'large.jpg'.
C The browser will download 'small.jpg'.
D The browser will download 'medium.jpg'.
Show the answer

D · The browser will download 'medium.jpg'.

The correct option is that the browser will download 'medium.jpg' because the viewport width of 500 pixels falls within the range specified in the `sizes` attribute, which indicates that the image should be displayed at 1024 pixels.

Flashcards

Tap a card to flip it

20 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Learning games

Play your way through this kit

Every game is built from this kit's own content — scores feed your mastery, so playing counts as studying.

🎮

Word Match

Built from this kit's own content

🎮

True False

Built from this kit's own content

🎮

Memory Match

Built from this kit's own content

🎮

Flashcard Battle

Built from this kit's own content

🎮

Speed Quiz

Built from this kit's own content

🎮

Guess Term

Built from this kit's own content

🎮

Sequence Builder

Built from this kit's own content

🎮

Categorization

Built from this kit's own content

🎮

Revision Battle

Built from this kit's own content

Playable in the app

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.