Bootstrap ยท Chapter 9 of 43

Bootstrap Images

Bootstrap provides utility classes to make images responsive and nicely shaped. The most important one is .img-fluid, which makes an image scale with its parent container instead of overflowing.

Additional classes let you round image corners, make images fully circular, or add a thin border and padding, similar to a thumbnail.

Syntax
<img src="pic.jpg" class="img-fluid" alt="...">

Responsive images

Add .img-fluid to any <img> to apply max-width: 100% and height: auto, so the image shrinks on smaller screens but never stretches beyond its natural size.

Image shapes

.rounded adds rounded corners, .rounded-circle makes a square image fully circular, and .img-thumbnail adds a bordered, padded frame around the image.

Example 1 (html)
<img src="https://via.placeholder.com/600x300" class="img-fluid rounded" alt="Sample">
Output
An image that resizes with the screen and has rounded corners

img-fluid keeps the image responsive while rounded softens its corners.

Example 2 (html)
<img src="https://via.placeholder.com/150" class="rounded-circle" alt="Avatar">
Output
A perfectly circular profile-style image

rounded-circle is commonly used for avatar or profile pictures.

Key points

  • .img-fluid makes images scale responsively.
  • .rounded and .rounded-circle change the image's corner shape.
  • .img-thumbnail adds a bordered frame with padding.
  • Always include a meaningful alt attribute for accessibility.
๐Ÿ’ก Note: rounded-circle only looks circular if the image itself has equal width and height.

๐Ÿ“ Quick Quiz

1. Which class makes an image responsive?

2. Which class makes an image fully circular?

3. What does .img-thumbnail add?