The Figure component helps you show images with captions in a neat and easy way.
Figure component in Bootsrap
<figure class="figure"> <img src="image.jpg" class="figure-img img-fluid rounded" alt="Description"> <figcaption class="figure-caption">Caption text here.</figcaption> </figure>
The <figure> tag groups the image and caption together.
Use figure-img class for the image and figure-caption for the caption.
<figure class="figure"> <img src="flower.jpg" class="figure-img img-fluid rounded" alt="A red flower"> <figcaption class="figure-caption">A beautiful red flower.</figcaption> </figure>
text-end.<figure class="figure"> <img src="quote.png" class="figure-img img-fluid" alt="Quote image"> <figcaption class="figure-caption text-end">A famous quote.</figcaption> </figure>
This page shows the Bootstrap logo with a caption below it using the Figure component. The image is responsive and has rounded corners.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Figure Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <main class="container mt-5"> <h1>Figure Component Demo</h1> <figure class="figure"> <img src="https://getbootstrap.com/docs/5.3/assets/brand/bootstrap-logo.svg" class="figure-img img-fluid rounded" alt="Bootstrap Logo"> <figcaption class="figure-caption">This is the Bootstrap logo.</figcaption> </figure> </main> </body> </html>
Always add an alt attribute to images for accessibility.
The img-fluid class makes images scale nicely on different screen sizes.
You can align captions using Bootstrap text alignment classes like text-center or text-end.
The Figure component groups images and captions together.
Use Bootstrap classes figure-img and figure-caption for styling.
It helps make images responsive and captions clear on all devices.
Practice
figure component?Solution
Step 1: Understand the figure component role
The Bootstrap figure component is designed to group an image and its caption in a semantic and styled way.Step 2: Identify correct usage
It uses classes likefigure-imgfor the image andfigure-captionfor the caption, ensuring proper layout and responsiveness.Final Answer:
To group images and their captions together with proper styling -> Option CQuick Check:
Figure groups image + caption = A [OK]
- Thinking figure creates navigation menus
- Confusing figure with button groups
- Assuming figure makes images clickable
Solution
Step 1: Identify the semantic tag for captions in figures
The correct HTML tag for captions inside a figure is<figcaption>.Step 2: Confirm Bootstrap class usage
Bootstrap uses the classfigure-captionon the<figcaption>tag to style captions properly.Final Answer:
<figcaption class='figure-caption'>Caption text</figcaption> -> Option AQuick Check:
Use <figcaption> with figure-caption class = D [OK]
- Using <caption> instead of <figcaption>
- Using generic <div> or <span> without semantic meaning
- Omitting the figure-caption class
<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>
Solution
Step 1: Analyze image classes
The image usesfigure-img,img-fluidfor responsiveness, androundedfor rounded corners.Step 2: Analyze caption classes
The caption usesfigure-captionandtext-end, which aligns the caption text to the right below the image.Final Answer:
An image of a flower with a caption aligned to the right below it, image corners rounded -> Option DQuick Check:
Rounded image + right-aligned caption = A [OK]
- Assuming caption is centered by default
- Ignoring the rounded class effect
- Thinking caption appears above image
<figure> <img src='dog.jpg' class='figure-img img-fluid' alt='Dog'> <figcaption>A cute dog</figcaption> </figure>
Solution
Step 1: Check image classes
The image hasfigure-imgandimg-fluid, which is correct for Bootstrap figure images.Step 2: Check caption classes
The<figcaption>is missing thefigure-captionclass, which is needed for proper Bootstrap styling.Final Answer:
Missing figure-caption class on <figcaption> -> Option AQuick Check:
Caption needs figure-caption class = B [OK]
- Forgetting figure-caption class on caption
- Thinking alt attribute is optional
- Replacing semantic figure tag with div
Solution
Step 1: Ensure figure container and image classes
The figure uses classfigure. The image usesfigure-imgfor styling,img-fluidfor responsiveness, androunded-circlefor circular shape.Step 2: Check caption classes for alignment
The caption usesfigure-captionandtext-centerto center the caption below the image.Final Answer:
Code snippet with figure, figure-img img-fluid rounded-circle, and figure-caption text-center -> Option BQuick Check:
Circle image + centered caption + responsive = C [OK]
- Omitting img-fluid for responsiveness
- Using rounded instead of rounded-circle for circle shape
- Not centering caption text
Ready to prove it?
Pass the test and this pattern moves unknown
