<div class="button-container">
  <button class="activate">Click Me!</button>
<div class="modal">
    <div class="the-content">
        <span class="close-button">&times;</span>
        <h1>Look at me! I'm an easy Modal!</h1>
        <p>What you can do with me is up to you!</p>
.button-container {
  text-align: center;
  padding-top: 50px;

.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: #00000067;
    opacity: 0;
    visibility: hidden;
    transform: scale(1.1);
    transition: visibility 0s linear 0.25s, opacity 0.25s 0s, transform 0.25s;

.the-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #ffffff;
    padding: 16px 24px;
    width: 384px;
    border-radius: 8px;

.close-button {
    float: right;
    width: 24px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    border-radius: 4px;
    background-color: #d3d3d3;

.close-button:hover {
    background-color: #a9a9a9;

.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1.0);
    transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s;
const modal = document.querySelector(".modal");
const activate = document.querySelector(".activate");
const closeButton = document.querySelector(".close-button");

/*toggle on button click*/
function toggleModal() {

function windowOnClick(event) {
    if (event.target === modal) {

/*event listeners*/
activate.addEventListener("click", toggleModal);
closeButton.addEventListener("click", toggleModal);
window.addEventListener("click", windowOnClick);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.