Performance: Figure component
This affects page load speed and rendering performance by how images and captions are loaded and displayed.
<figure class="figure"> <img src="optimized-image.webp" class="figure-img img-fluid rounded" alt="Example image" loading="lazy" width="600" height="400"> <figcaption class="figure-caption">A caption for the image.</figcaption> </figure>
<figure class="figure"> <img src="large-unoptimized-image.jpg" class="figure-img img-fluid rounded" alt="Example image"> <figcaption class="figure-caption">A caption for the image.</figcaption> </figure>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large unoptimized image in figure | Minimal (1 img + 1 figcaption) | 1 reflow due to image load | High paint cost due to large image | [X] Bad |
| Optimized image with lazy loading | Minimal (1 img + 1 figcaption) | Single reflow with fixed dimensions | Lower paint cost with smaller image | [OK] Good |
figure component?figure-img for the image and figure-caption for the caption, ensuring proper layout and responsiveness.<figcaption>.figure-caption on the <figcaption> tag to style captions properly.<figure class='figure'> <img src='flower.jpg' class='figure-img img-fluid rounded' alt='Flower'> <figcaption class='figure-caption text-end'>A beautiful flower</figcaption> </figure>
figure-img, img-fluid for responsiveness, and rounded for rounded corners.figure-caption and text-end, which aligns the caption text to the right below the image.<figure> <img src='dog.jpg' class='figure-img img-fluid' alt='Dog'> <figcaption>A cute dog</figcaption> </figure>
figure-img and img-fluid, which is correct for Bootstrap figure images.<figcaption> is missing the figure-caption class, which is needed for proper Bootstrap styling.figure. The image uses figure-img for styling, img-fluid for responsiveness, and rounded-circle for circular shape.figure-caption and text-center to center the caption below the image.Pass the test and this pattern moves unknown