Performance: Responsive images
Responsive images affect page load speed by delivering appropriately sized images for different screen sizes, reducing data usage and improving loading times.
<img src="small-image.jpg" srcset="small-image.jpg 480w, medium-image.jpg 768w, large-image.jpg 1200w" sizes="(max-width: 600px) 480px, (max-width: 900px) 768px, 1200px" class="img-fluid" alt="Example image">
<img src="large-image.jpg" class="img-fluid" alt="Example image">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Single large image for all devices | Minimal | 1 reflow on image load | High due to large image decode | [X] Bad |
| Responsive images with srcset and sizes | Minimal | 1 reflow on image load | Lower due to smaller image decode | [OK] Good |
img-fluid do to an image?img-fluidimg-fluid class in Bootstrap applies CSS styles that make the image responsive by setting its max-width to 100% and height to auto. This means the image will scale to fit the width of its container without distortion.img-fluid to make images responsive, not img-responsive or other variants. <img src='photo.jpg' class='img-fluid' alt='Photo'> uses the correct class with proper HTML syntax and includes alt text for accessibility.<div style='width: 200px;'> <img src='image.jpg' class='img-fluid' alt='Sample Image'> </div>
img-fluid class sets max-width to 100%, so the image scales down to fit the container width (200px) and height adjusts automatically to keep aspect ratio.<img src='pic.jpg' class='img-fluid'>
img-fluid is correctly used on the <img> tag to make the image responsive. However, the alt attribute is missing, which is important for accessibility and SEO.img-fluid class makes the image scale with its container responsively. Adding style='max-width: 300px;' ensures it never grows wider than 300px even on large screens. Other options use fixed width (loses responsiveness below 300px), outdated class, or lack responsive class.Pass the test and this pattern moves unknown