How to create a modal in Bootstrap?

Published on : April 16,2023
How to create a modal in Bootstrap?

Creating a Modal in Bootstrap is a straightforward process. A modal is a dialog box or popup window that is displayed on top of the current page.

Here are the steps to create a modal in Bootstrap:

  • First, include the Bootstrap CSS and JS files in the head section of your HTML document.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  • Add a button or a link that will trigger the modal. Set the data-toggle attribute to "modal" and the data-target attribute to the ID of the modal.
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
  Open Modal
</button>
  • Create the modal HTML code. Set the ID of the modal to match the data-target attribute of the button.
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        <h4 class="modal-title">Modal Header</h4>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
  • Customize the modal by adding or removing content in the modal-header, modal-body, and modal-footer sections.
  • Test the modal by clicking on the button that triggers it.

That's it! You have successfully created a modal in Bootstrap.

Categories : Bootstrap

Tags : HTML Bootstrap CSS popup window dialog box modal

Praful Sangani
Praful Sangani
I'm a passionate full-stack developer with expertise in PHP, Laravel, Angular, React Js, Vue, Node, Javascript, JQuery, Codeigniter, and Bootstrap. I enjoy sharing my knowledge by writing tutorials and providing tips to others in the industry. I prioritize consistency and hard work, and I always aim to improve my skills to keep up with the latest advancements. As the owner of Open Code Solution, I'm committed to providing high-quality services to help clients achieve their business goals.


0 Comments

Leave a comment

We'll never share your email with anyone else. Required fields are marked *

Related Articles

Bootstrap Alerts
Praful Sangani By Praful Sangani - August 03,2022
What is Bootstrap?
Praful Sangani By Praful Sangani - April 16,2023