Skip to content
Related Articles

Related Articles

Improve Article
Bootstrap 4 | Images
  • Last Updated : 31 May, 2019

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:






<!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>                    

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:




<!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>                    

Output:

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

Syntax:

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

Example:






<!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>                    

Output:

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

Syntax:

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

Example:




<!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>                    

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:




<!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>                    

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:




<!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>                    

Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :