Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Images | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 53 of 55

·HTML

Images

9 min

Course progress96%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Essential `<img>` attributes (`src`, `alt`, `width`, `height`)
  • Responsive images with `srcset` and `sizes`
  • Lazy loading and its impact on Core Web Vitals
  • Choosing optimal image formats (WebP, AVIF)
  • Accessibility checklist for images
  • Embedding Images (<img>)

    <img src='images/photo.jpg' alt='Sunset over the mountains' width='600' height='400' loading='lazy' srcset='images/photo-600.jpg 600w, images/photo-1200.jpg 1200w' sizes='(max-width: 600px) 100vw, 600px' />
    

    Essential attributes

    • src – Path to the image file.
    • alt – Mandatory text for screen readers and when the image fails to load. Write concise, descriptive sentences.
    • width/height – Reserve the exact space the image will occupy; this prevents layout shift (important for Core Web Vitals).
    • loading='lazy' – Defers off‑screen images until they approach the viewport.
    • srcset and sizes – Serve responsive images for different viewport widths and pixel densities.

    Optimization tips

    • Compress images (ImageOptim, Squoosh) and serve modern formats (WebP, AVIF) when possible.
    • Provide a low‑quality placeholder (blur‑up) or a tiny SVG LQIP to avoid a blank space during loading.
    • Use srcset to offer 1× and 2× (or higher) variants for high‑DPI displays.
    • For decorative images, use an empty alt='' to hide them from assistive technology.

    Quick checklist for image accessibility

    1. alt attribute present and meaningful? ✅
    2. Width & height defined to reserve space? ✅
    3. loading='lazy' for non‑above‑the‑fold images? ✅
    4. srcset/sizes for responsive delivery? ✅
    5. Modern format (WebP/AVIF) provided? ✅

    Tip: Run your page through Google Lighthouse → Performance → Avoid large layout shifts to confirm images are not causing CLS.


    Try it yourself

    Replace the src with a WebP version, add a srcset that includes a 2× image, and watch the network panel show the appropriate file being downloaded based on your screen’s pixel density.

    Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
    Previous lessonHyperlinks and NavigationContinue to lesson 54ListsBack to HTML Course curriculum