Aligning Image

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

Syntax:

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

Example: In this example we are using Bootstrap 4’s float-left and float-right classes to align images to the left and right sides, respectively, within the container.

HTML
<!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=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
    </script>
    <script src=
"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js">
    </script>
    <script src=
"https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js">
    </script>
</head>

<body style="text-align:center;">
    <div class="container">
        <h2>Aligning Image</h2>
        <!-- Bootstrap float-left class -->
        <img class="float-left" 
             src=
"https://media.w3wiki.org/wp-content/uploads/20240611123517/image.png"
            alt="Responsive image" 
            width="250" 
            height="250" />
        <!-- Bootstrap float-right class -->
        <img class="float-right" 
             src=
"https://media.w3wiki.org/wp-content/uploads/20240611123517/image.png"
            alt="Responsive image" 
            width="250" 
            height="250" />
    </div>
</body>

</html>

Output:

Aligning Image Example Output

Bootstrap 4 Images

Bootstrap 4 provides classes to style images responsively, including responsive images that automatically adjust the size based on screen width, image shapes such as rounded or circular, and image thumbnails with optional borders and captions, facilitating flexible and attractive image layouts.

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

Table of Content

  • Responsive Images
  • Rounded Corners Image
  • Circle Image
  • Thumbnail Image
  • Aligning Image
  • Centered Image

Similar Reads

Responsive Images

The .img-fluid class is used within the tag to create the responsive image. The responsive image is used to adjust the image automatically to the specified box....

Rounded Corners Image

The .rounded class is used to create a rounded corner image. This class is used with tag....

Circle Image

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

Thumbnail Image

The .img-thumbnail class is used to create a thumbnail (bordered) image....

Aligning Image

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

Centered Image

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