I’ve shared a way to add a pop-up or modal lightbox with CSS only on my earlier post, Easy Modal Lightbox Pop-Up. I’ve received many request how to make this modal pop up on page load instead of using a button. So, here’s how-to:
HTML
Copy the code below and paste into your HTML document.
<div id="modal-1" class="modal animate-opacity"> <div class="modal-content"> <div class="modal-inner"> <span onclick="document.getElementById('modal-1').style.display='none'" class="modal-close">×</span> <h4>Modal Headline</h4> <p>Modal description goes here.</p> </div> </div> </div>
CSS
Copy the code below and paste into your CSS document.
.modal { z-index: 10; display: block; padding-top: 100px; position: fixed; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.5) } .modal-content { margin: auto; background-color: #fff; position: relative; padding: 0; outline: 0; max-width: 600px } .modal-inner { padding: 20px 30px; } .modal-close { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; position: absolute; right: 0; top: 0; background: #ccc; padding: 6px 10px; } .animate-opacity { animation: opac 0.8s }@keyframes opac{from{opacity:0} to{opacity:1}}
.animate-opacity
is optional as it’s the animated effect when modal opens.
You can tweak the animation time. It’s currently 0.8 seconds opac 0.8s
, but change the timing as your need.