Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap 4 Image Alignment</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script> <style> .bs-example{ margin: 20px; } .box{ padding: 15px; border: 4px solid #666; margin-bottom: 20px; } </style> </head> <body> <div class="bs-example"> <h4>Horizontal alignment using float classes</h4> <div class="box clearfix"> <img src="/examples/images/avatar.svg" class="float-left" alt="Sample Image"> <img src="/examples/images/avatar.svg" class="float-right" alt="Sample Image"> </div> <h4>Left alignment using text alignment classes</h4> <div class="box text-left"> <img src="/examples/images/avatar.svg" alt="Sample Image"> </div> <h4>Right alignment using text alignment classes</h4> <div class="box text-right"> <img src="/examples/images/avatar.svg" alt="Sample Image"> </div> <h4>Center alignment using text alignment classes</h4> <div class="box text-center"> <img src="/examples/images/avatar.svg" alt="Sample Image"> </div> <h4>Center alignment of block-level image using auto margin</h4> <div class="box"> <img src="/examples/images/avatar.svg" class="d-block mx-auto" alt="Sample Image"> </div> </div> </body> </html>