Layout · 01 of 23

Modal Scale

iOS-style spring scale

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<button class="trigger-btn" id="modalBtn">Open Modal</button>

<div class="modal-backdrop" id="modalBackdrop">
  <div class="modal-content">
    <h2>Modal Title</h2>
    <p>This is a modal window with a smooth scale and backdrop blur animation.</p>
    <button class="close-modal">Close</button>
  </div>
</div>

CSS

.trigger-btn {
  padding: 0.6rem 1.2rem;
  background: #7c5cff;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #12121a;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: #f0f0f5;
  padding: 2rem;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  transform: scale(0.8);
  /* Overshooting cubic-bezier gives the iOS-style spring */
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.open .modal-content {
  transform: scale(1);
}

.close-modal {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  background: #333;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

JavaScript

var modalBtn = document.getElementById('modalBtn');
var modalBackdrop = document.getElementById('modalBackdrop');
var closeModal = document.querySelector('.close-modal');

modalBtn.addEventListener('click', function () {
  modalBackdrop.classList.add('open');
});
closeModal.addEventListener('click', function () {
  modalBackdrop.classList.remove('open');
});
// Clicking the dimmed backdrop (not the dialog) also closes it
modalBackdrop.addEventListener('click', function (e) {
  if (e.target === modalBackdrop) modalBackdrop.classList.remove('open');
});