HTML Layouts

Preview Source code Open standalone

Set width: full 320 480 640 768 1024 1920 custom

Source code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Responsive Modal/Popup Dialog</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 0; padding: 0; }
    .open-modal-btn {
      margin: 2rem;
      padding: 0.75rem 1.5rem;
      font-size: 1rem;
      background: #444;
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
    }
    .modal-overlay {
      display: none;
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.5);
      z-index: 1000;
      justify-content: center;
      align-items: center;
    }
    .modal-overlay.active { display: flex; }
    .modal {
      background: #fff;
      border-radius: 8px;
      max-width: 90vw;
      width: 400px;
      padding: 2rem 1.5rem 1.5rem 1.5rem;
      box-shadow: 0 8px 32px rgba(0,0,0,0.2);
      position: relative;
      animation: fadeIn 0.2s;
    }
    @keyframes fadeIn {
      from { transform: translateY(40px); opacity: 0; }
      to { transform: translateY(0); opacity: 1; }
    }
    .modal-close {
      position: absolute;
      top: 1rem;
      right: 1rem;
      background: none;
      border: none;
      font-size: 1.5rem;
      color: #888;
      cursor: pointer;
    }
    @media (max-width: 500px) {
      .modal { width: 95vw; padding: 1.5rem 1rem; }
    }
  </style>
</head>
<body>
  <button class="open-modal-btn" id="openModalBtn">Open Modal</button>
  <div class="modal-overlay" id="modalOverlay">
    <div class="modal">
      <button class="modal-close" id="closeModalBtn" aria-label="Close">&times;</button>
      <h2>Modal Title</h2>
      <p>This is a responsive modal dialog. You can put any content here.</p>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </div>
  </div>
  <script>
    const openBtn = document.getElementById('openModalBtn');
    const overlay = document.getElementById('modalOverlay');
    const closeBtn = document.getElementById('closeModalBtn');
    openBtn.addEventListener('click', () => overlay.classList.add('active'));
    closeBtn.addEventListener('click', () => overlay.classList.remove('active'));
    overlay.addEventListener('click', (e) => {
      if (e.target === overlay) overlay.classList.remove('active');
    });
    document.addEventListener('keydown', (e) => {
      if (e.key === 'Escape') overlay.classList.remove('active');
    });
  </script>
</body>
</html>