How to Create a basic Modal Component in Bootstrap?

Modal windows are a popular feature in modern web development that enables web designers to display additional content or user input options without redirecting the user to a new page.


Step 1: Set up the HTML Structure

Step 2: Modify the Modal Window

Step 3: Modify the Modal Body

Step 4: Personalize the Modal Body


<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Bootstrap Modal Example</title>
  <link rel="stylesheet" href="">
  <script src=""></script>
  <script src=""></script>
  <script src=""></script>

  <div class="container mt-5">
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
      Open Modal
    <div class="modal" id="myModal">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">My Modal</h5>
            <button type="button" class="close" data-dismiss="modal">×</button>
          <div class="modal-body">
            <p>This is our modal body. You can add any content you want here.</p>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>



We covered how to make a basic modal component in Bootstrap and how to change its header, body, and footer in this article. Modals are a helpful web design element because they allow you to display material in a distinct layer on top of the page, eliminating the need for a new page or a pop−up window. Modals may be used to display messages, forms, photos, videos, or any other sort of material in a user−friendly manner.

Updated on: 18-Aug-2023


Kickstart Your Career

Get certified by completing the course

Get Started