Bootstrap’s image classes help in making images responsive and visually appealing with minimal effort.
Use the .img-fluid
class to make an image responsive.
Use .rounded
, .rounded-circle
, or .img-thumbnail
to style images.
<img src="https://via.placeholder.com/400" class="img-fluid" alt="Responsive Image">
Bootstrap provides multiple styling options for images.
.rounded
→ Adds rounded corners.
.rounded-circle
→ Creates a circular image.
<img src="https://via.placeholder.com/100" class="rounded" alt="Rounded Image">
<img src="https://via.placeholder.com/100" class="rounded-circle" alt="Circular Image">
β Explanation:
The first image has rounded corners.
The second image is circular.
Bootstrap provides .img-thumbnail
for adding a border and padding around an image.
<img src="https://via.placeholder.com/150" class="img-thumbnail" alt="Thumbnail Image">
Bootstrap allows image alignment using .float-start
, .float-end
, and .mx-auto d-block
.
<img src="https://via.placeholder.com/100" class="float-start" alt="Left Aligned">
<img src="https://via.placeholder.com/100" class="float-end" alt="Right Aligned">
<img src="https://via.placeholder.com/100" class="mx-auto d-block" alt="Centered">
β Explanation:
float-start
→ Aligns image left.
float-end
→ Aligns image right.
mx-auto d-block
→ Centers the image.
Figures allow captioned images using the <figure>
and <figcaption>
elements.
Wrap an image inside a <figure>
tag.
Add a <figcaption>
for image description.
Use .figure
, .figure-img
, and .figure-caption
classes.
<figure class="figure">
<img src="https://via.placeholder.com/200" class="figure-img img-fluid rounded" alt="Sample Image">
<figcaption class="figure-caption text-center">This is a sample caption.</figcaption>
</figure>
β Explanation:
.figure
→ Creates a figure container.
.figure-img
→ Styles the image inside the figure.
.figure-caption
→ Adds a caption below the image.
You can create a responsive image grid using Bootstrap’s grid system.
<div class="container text-center">
<div class="row">
<div class="col">
<img src="https://via.placeholder.com/100" class="img-fluid rounded" alt="Image 1">
</div>
<div class="col">
<img src="https://via.placeholder.com/100" class="img-fluid rounded" alt="Image 2">
</div>
<div class="col">
<img src="https://via.placeholder.com/100" class="img-fluid rounded" alt="Image 3">
</div>
</div>
</div>
β Explanation:
row
& col
→ Organize images in a grid layout.
.img-fluid
→ Makes images responsive.
.rounded
→ Adds rounded corners.
You can overlay text on an image using Bootstrap’s positioning utilities.
<div class="position-relative">
<img src="https://via.placeholder.com/300" class="img-fluid" alt="Overlay Image">
<h5 class="position-absolute top-50 start-50 translate-middle text-white bg-dark p-2 rounded">Overlay Text</h5>
</div>
β Explanation:
position-absolute
→ Positions text over the image.
top-50 start-50 translate-middle
→ Centers the text.
bg-dark p-2 rounded
→ Adds a dark background with padding.
Bootstrap’s carousel component allows image sliders.
<div id="carouselExample" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://via.placeholder.com/400" class="d-block w-100" alt="Slide 1">
</div>
<div class="carousel-item">
<img src="https://via.placeholder.com/400" class="d-block w-100" alt="Slide 2">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
<span class="carousel-control-prev-icon"></span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
<span class="carousel-control-next-icon"></span>
</button>
</div>
β Explanation:
carousel
→ Creates an image slider.
carousel-item active
→ First image is active by default.
carousel-control-prev
& carousel-control-next
→ Add navigation buttons.
Bootstrap’s Images & Figures help create beautiful and responsive images effortlessly.
Images: Use .img-fluid
for responsiveness.
Styling: Apply .rounded
, .rounded-circle
, .img-thumbnail
.
Alignment: Use .float-start
, .float-end
, .mx-auto
.
Figures: Wrap images with <figure>
and add captions.
Advanced: Create image grids, overlays, and carousels.
π‘ Now, you can easily style and manage images in Bootstrap projects! π