Bootstrap 5 Images

Styling and optimizing images with Bootstrap classes

🖼️ What are Bootstrap Images?

Bootstrap provides utility classes to style images with rounded corners, circles, thumbnails, and responsive behavior. These classes make images look professional and adapt perfectly to different screen sizes automatically.


<img src="image.jpg" class="img-fluid" alt="Responsive image">
                                    

Output:

Responsive image

🔹 Responsive Images

Ensuring images scale properly is crucial for responsive design. Applying the .img-fluid class to an <img> element makes it responsive. This class sets the CSS properties max-width: 100%; and height: auto;. This means the image will never be wider than its containing parent element and will scale down proportionally on smaller screens, preventing horizontal scroll bars. Its height adjusts automatically to maintain the original aspect ratio. This simple utility is essential for any image displayed within a fluid grid column or container, guaranteeing it integrates perfectly into the responsive layout.

<img src="landscape.jpg" class="img-fluid" alt="Landscape">

Output:

Landscape

🔹 Rounded Images

The .rounded class adds a standard border-radius to images (and other elements), softening their edges for a more modern aesthetic. For finer control, Bootstrap offers a scale of rounding utilities: .rounded-0 (square), .rounded-1 through .rounded-5 (increasing radius), and .rounded-circle (50% radius for a perfect circle on square images). These classes are part of the larger utilities API, making it easy to create consistent visual styles across your project. They are commonly used for avatars, product thumbnails, or to integrate images more softly into card and container designs.

<img src="photo.jpg" class="rounded" alt="Rounded corners">

Output:

Rounded corners

🔹 Circle Images

To create a perfect circular image, use the .rounded-circle utility class. This applies a border-radius: 50%; CSS property. For the best visual result, the source image should be a perfect square (1:1 aspect ratio); otherwise, it will appear as an oval. This style is ubiquitous for user profile pictures, avatars in comment sections, team member photos, and logos where a circular frame is desired. It's a simple yet effective way to add visual interest and a touch of polish to user interface elements, and it works seamlessly with the .img-fluid class for responsive circles.

<img src="avatar.jpg" class="rounded-circle" alt="Profile picture">

Output:

Profile picture

🔹 Thumbnail Images

The .img-thumbnail class styles an image to resemble a photographic thumbnail or a framed picture. It adds a light border (with customizable color via theming), a small amount of padding, and a slight border-radius. This gives the image a distinct, contained appearance, setting it apart from the background. It's particularly useful for image galleries, product listings in e-commerce sites, portfolio projects, or any scenario where you want to present a collection of images with a consistent, bordered frame. The thumbnail remains fully responsive if used in conjunction with .img-fluid.

<img src="product.jpg" class="img-thumbnail" alt="Product thumbnail">

Output:

Product thumbnail

🔹 Aligned Images

Bootstrap provides utility classes to easily align images within their container or surrounding text. Use .float-start or .float-end to float an image left or right, allowing text to wrap around it—a classic magazine-style layout. To center an image, combine the display utility .d-block to make it a block-level element with the auto-margin utility .mx-auto (margin-left: auto; margin-right: auto). These utilities offer quick, responsive solutions for image placement without writing custom CSS, ensuring proper spacing and integration within your content flow across different screen sizes.

<img src="left.jpg" class="float-start" alt="Left aligned">
<img src="right.jpg" class="float-end" alt="Right aligned">
<img src="center.jpg" class="d-block mx-auto" alt="Centered">

Output:

Left aligned Right aligned
Centered

🔹 Image with Caption

For semantic and accessible image captions, use the HTML5 <figure> and <figcaption> elements with Bootstrap's helper classes. Wrap your image in a <figure class="figure">. The image itself should have .figure-img (which adds a bottom margin). The caption uses <figcaption class="figure-caption">, which applies subdued, smaller typography. This structure is ideal for blog posts, documentation, articles, or galleries where images require descriptive or attribution text. It's a best-practice approach that improves SEO, accessibility for screen readers, and maintains clean, styled presentation.

<figure class="figure">
  <img src="nature.jpg" class="figure-img img-fluid rounded" alt="Nature">
  <figcaption class="figure-caption">A beautiful landscape photo.</figcaption>
</figure>

Output:

Nature
A beautiful landscape photo.

🔹 Image Sizes

Bootstrap provides flexible utilities for responsive image sizing and control. Use percentage-based width classes such as .w-25, .w-50, .w-75, and .w-100 to quickly scale images relative to their container. For precise pixel-level control, apply custom inline styles or define specific CSS classes. This ensures images adapt seamlessly across different screen sizes while maintaining aspect ratios and visual quality. Combining these utilities with Bootstrap’s responsive grid system allows developers to create visually balanced layouts that enhance user experience and page performance, improving Core Web Vitals and SEO through optimized image delivery and faster loading times.

<img src="small.jpg" class="w-25" alt="25% width">
<img src="medium.jpg" class="w-50" alt="50% width">
<img src="large.jpg" class="w-75" alt="75% width">

Output:

25% width 50% width 75% width

🧠 Test Your Knowledge

Which class makes an image responsive?