How to create a modal using bootstrap?

You have probably seen dialog box/popup window on some websites. In the bootstrap world, it is called Modal. Modal is a great way to display some extra content. You can use modal to show lightboxes, user notifications, or custom contents.

In this post, we will create a simple page that contains a navbar. The navbar contains a login button that shows our login modal when clicked.

First, let me show you a screenshot of the page that I have created so that you have a visual idea of what our modal look like.

You can see in the above screenshot that our modal body contains two input fields and two buttons and the modal header contains the title and a dismiss button.

Now, let’s see the HTML file.

<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <meta http-equiv="x-ua-compatible" content="ie=edge">

        <!-- CSS only -->
        <link href="" 

        <title>Modal Example</title>


        <!-- Navbar -->
        <nav class="navbar navbar-dark navbar-expand-sm fixed-top bg-dark">
            <div class="container ps-5">
                <a class="navbar-brand ms-5" href="modal_example.html">
                    <img src="logo.png" alt="logo" width="41" height="31">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
                    <li class="nav-item"><a class="nav-link" href="#">Menu</a></li>
                    <li class="nav-item"><a class="nav-link" href="#">About us</a></li>
                    <li class="nav-item"><a class="nav-link" href="#">Contact us</a></li>
                <span class="navbar-text">
                    <a role="button" id="loginButton" data-bs-target="#modalExample" data-bs-toggle="modal">Login</a>

        <!-- Modal -->
        <div class="modal fade" id="modalExample">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header bg-dark">
                        <h5 class="modal-title text-white">Login</h5>
                        <button type="button" class="btn-close bg-white" data-bs-dismiss="modal"></button>
                    <div class="modal-body">
                            <div class="row mb-3">
                                <label for="email" class="col-form-label col-md-3">Email</label>
                                <div class="col-md-9">
                                    <input type="email" id="email" placeholder="Email" class="form-control">
                            <div class="row mb-3">
                                <label for="password" class="col-form-label col-md-3">Password</label>
                                <div class="col-md-9">
                                    <input type="password" id="password" placeholder="Password" class="form-control">
                            <div class="row mb-3">
                                <div class="col-md-9 offset-3">
                                    <button class="btn btn-dark">Login</button>
                                    <button class="btn btn-secondary">Cancel</button>

        <!-- JavaScript Bundle with Popper -->
     <script src="" 

So, that’s our HTML file that contains a navbar and a modal.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: