Open In App

Responsive images in Bootstrap with Examples

Bootstrap offers different classes for images to make their appearance better and also to make them responsive. Making an image responsive means that it should scale according to its parent element. That is, the size of the image should not overflow its parent 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:






<!DOCTYPE html>
<html>
<head>
    <!-- Link Bootstrap CSS -->
    <link rel="stylesheet" href=
    <!-- Link Bootstrap JS and JQuery -->
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container">
        <h1>Responsive Image </h1>
        <br>
        <h3>.img-responsive class</h3>
         
<p>
            Change the size of the browser window
            to see effect
        </p>
 
        <img src=
            class="img-responsive" alt="Responsive image"
            width="307" height="240"/>
    </div>
</body>
</html>

Output:






<!DOCTYPE html>
<html>
<head>
    <!-- Link Bootstrap CSS -->
    <link rel="stylesheet" href=
    <!-- Link Bootstrap JS and JQuery -->
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container">
        <h3>.img-fluid class</h3>
         
<p>
            Change the size of the browser window
            to see effect.
        </p>
 
        <img src=
            class="img-fluid" alt="Responsive Image"
            width="307" height="240"/>
    </div>
</body>
</html>

Output:




<!DOCTYPE html>
<html>
<head>
    <!-- Link Bootstrap CSS -->
    <link rel="stylesheet" href=
    <!-- Link Bootstrap JS and JQuery -->
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container">
        <h3>.img-rounded class</h3>
         
<p>Rounded Corners</p>
 
        <img src=
            class="img-rounded" alt="Responsive Image"
            width="307" height="240"/>
    </div>
</body>
</html>

Output:




<!DOCTYPE html>
<html>
<head>
    <!-- Link Bootstrap CSS -->
    <link rel="stylesheet" href=
    <!-- Link Bootstrap JS and JQuery -->
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container">
        <h3>.img-circle class </h3>
         
<p>Circle</p>
 
        <img src=
            class="img-circle" alt="Responsive Image"
            width="307" height="240"/>
    </div>
</body>
</html>

Output:




<!DOCTYPE html>
<html>
<head>
    <!-- Link Bootstrap CSS -->
    <link rel="stylesheet" href=
    <!-- Link Bootstrap JS and JQuery -->
    <script src=
    </script>
    <script src=
    </script>
</head>
<body>
    <div class="container">
        <h3>.img-thumbnail class</h3>
         
<p>Thumbnail</p>
 
        <img src=
            class="img-thumbnail" alt="Responsive Image"
            width="307" height="240">
    </div>
</body>
</html>

Output:

Supported Browser:


Article Tags :