Bootstrap 4 | Images

Bootstrap offers different classes for images to make their appearance better and also to make them responsive. Making an image responsive means it should scale according to its parent element. That is, the size of the image should not overflow its parent element and will grow and shrink according to the change in the size of its parent without losing its aspect ratio.

The different classes available in Bootstrap for images are as explained below:

Responsive Images: The .img-fluid class is used within <img> tag to create the responsive image. The responsive image is used to adjust the image automatically to the specified box.



Syntax:

<img src="image_source" class="img-fluid" ...>

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body style="text-align:center;"
    <div class="container"
      
        <h1 style="color:green;">
            GeeksforGeeks
        </h1
      
        <h2>Responsive Image</h2>
          
        <img class="img-fluid" src=
             alt="Responsive image" width="667" height="440" /> 
    </div
</body
  
</html>                    

chevron_right


Output:

Rounded Corners Image: The .rounded class is used to create a rounded corner image. This class is used with <img> tag.

Syntax:

<img src="image_source" class="rounded" ...>

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body style="text-align:center;"
    <div class="container"
      
        <h1 style="color:green;">
            GeeksforGeeks
        </h1
      
        <h2>Rounded Corner Image</h2>
          
        <img class="rounded" src=
             alt="Responsive image" width="367" height="340" /> 
    </div
</body
  
</html>                    

chevron_right


Output:

Circle Image: The .rounded-circle class is used to create the circle shape image.

Syntax:

<img src="image_source" class="rounded-circle" ...>

Example:


filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body style="text-align:center;"
    <div class="container"
      
        <h1 style="color:green;">
            GeeksforGeeks
        </h1
      
        <h2>Circle Image</h2>
          
        <img class="rounded-circle" src=
             alt="Responsive image" width="467" height="340" /> 
    </div
</body
  
</html>                    

chevron_right


Output:

Thumbnail Image: The .img-thumbnail class is used to create thumbnail (bordered) image.

Syntax:

<img src="image_source" class="img-thumbnail" ...>

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body style="text-align:center;"
    <div class="container"
      
        <h1 style="color:green;">
            GeeksforGeeks
        </h1
      
        <h2>Thumbnail Image</h2>
          
        <img class="img-thumbnail" src=
             alt="Responsive image" width="467" height="340" /> 
    </div
</body
  
</html>                    

chevron_right


Output:

Aligning Image: The .float-left and .float-right class is used to set the left and right alignment of image.

Syntax:

<img src="image_source" class="float-left/float-right" ...>

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body style="text-align:center;"
    <div class="container"
      
        <h1 style="color:green;">
            GeeksforGeeks
        </h1
      
        <h2>Aligning Image</h2>
          
        <!-- Bootstrap float-left class -->
        <img class="float-left" src=
             alt="Responsive image" width="250" height="250" /> 
          
        <!-- Bootstrap float-right class -->     
        <img class="float-right" src=
             alt="Responsive image" width="250" height="250" /> 
    </div
</body
  
</html>                    

chevron_right


Output:

Centered Image: The .mx-auto (margin:auto) and .d-block (display:block) classes are used to set the image into center.

Syntax:

<img src="image_source" class="mx-auto d-block" ...>

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html> 
<html lang="en"
<head
    <title>Bootstrap Images</title
      
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  
    <link rel="stylesheet" href=
      
    <script src=
    </script>
      
    <script src=
    </script>
      
    <script src=
    </script>
</head
  
<body
    <div class="container"
      
        <h1 style="color:green;text-align:center;">
            GeeksforGeeks
        </h1
      
        <h2 style="text-align:center;">Centered Image</h2>
          
        <img class="mx-auto d-block" src=
             alt="Responsive image" width="350" height="250" /> 
    </div
</body
  
</html>                    

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.