Discover how a simple wrapper can make your images and captions look perfect everywhere!
Why Figure component in Bootsrap? - Purpose & Use Cases
Imagine you want to show a photo with a caption below it on your webpage. You write an <img> tag and then add a separate <p> tag for the caption.
If you want to style the image and caption together or keep them aligned nicely, you have to write extra CSS and HTML. It's easy to make mistakes, and the caption might not stay close to the image on different screen sizes.
The Bootstrap Figure component groups the image and caption in a simple, clean way. It automatically styles and aligns them so they look good on all devices without extra work.
<img src="photo.jpg" alt="A mountain"> <p>Beautiful mountain view</p>
<figure class="figure"> <img src="photo.jpg" class="figure-img img-fluid rounded" alt="A mountain"> <figcaption class="figure-caption">Beautiful mountain view</figcaption> </figure>
You can easily add images with captions that look polished and stay well aligned on any screen size.
On a travel blog, you want to show photos with descriptions under each picture. Using the Figure component keeps your posts neat and readable on phones and computers.
Manually pairing images and captions is tricky and needs extra styling.
The Figure component groups and styles them automatically.
This saves time and ensures consistent, responsive layouts.
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
