Hi Friends 👋,
Welcome To aGuideHub! ❤️
Today, I am going to show you. How to use iframe in bootstrap modal popup with code example.
Table of contents
- Framework and cdn link
- Included JS 5 bootstrap
- Define its class name
This article will guide you to adding .modal-dialog
in Bootstrap with example.
Step 1: Framework and cdn link
First of all, load the Bootstrap framework CSS into the head tag of your webpage.
link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
Step 2: Included JS bootstrap
Now, load the Bootstrap JavaScript file before closing the body tag and done.
script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">script>
Step 3: Define its class name
After that, create the iframe with a id name #myModal
.
div class="container mt-3">
h3>Modal Exampleh3>
p>Click on the button to open the modal.p>
button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">
Open modal
button>
div>
div class="modal" id="myModal">
div class="modal-dialog">
div class="modal-body">
iframe width="560" height="315" src="https://www.youtube.com/embed/rBd0h-g59dg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>iframe>
div>
div>
div>
Example.
Let’s look at the following example to understand how it basically works:
DOCTYPE html>
html lang="en">
head>
title>Bootstrap Exampletitle>
meta charset="utf-8">
meta name="viewport" content="width=device-width, initial-scale=1">
link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">script>
head>
body>
div class="container mt-3">
h3>Modal Exampleh3>
p>Click on the button to open the modal.p>
button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#myModal">
Open modal
button>
div>
div class="modal" id="myModal">
div class="modal-dialog">
div class="modal-body">
iframe width="560" height="315" src="https://www.youtube.com/embed/rBd0h-g59dg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>iframe>
div>
div>
div>
body>
html>
Check the output of the above code example.
All the best 👍