Code Practice Lab
(current)
Run Code
Live Code Editor
Source Code
<!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"> <style type="text/css"> img{ width:100px; height:100px; } </style> </head> <body> <div class="container mt-4"> <h3 class="">Bootstrap 5 Image Alignment</h3> <div class="row"> <div class="col-sm-12 col-12"> <h4>Image:Left Alignment</h4> <p class="clearfix"> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail float-start m-3" alt="Thumbnail Image" > Image can be aligned in the left direction by assigning <code>.float-start</code> to the img element base class.Please keep in mind that ,float property should be cleared so that next HTML element can flow in normal way. </p> <h3>Image:Right Alignment</h3> <p class="clearfix">Image can be aligned in the right direction by assigning <code>.float-end</code> to the img element base class.Please keep in mind that ,float property should be cleared so that next HTML element can flow in normal <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail float-end" alt="Thumbnail Image" > </p> <h3>Image:Center Alignment</h3> <h4>Case:1</h4> <p class="text-justify">Image can be aligned in the center by placing the image inside the container having .text-center class. </p> <div class="text-center"> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail " alt="Thumbnail Image" > </div><!--/image center alignment--> <h4>Case:2</h4> <p class="text-justify">Image can be aligned in the center by assigning .d-block and .mx-auto to the img element base class. </p> <img src="../code-support/images/bootstrap/bird.jpg" class="img-thumbnail d-block mx-auto " alt="Thumbnail Image"> </div><!--/first column--> </div><!--/row--> </div><!--/container--> <!-- Option 1: Bootstrap Bundle with Popper --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"></script> </body> </html>
Output :
Running