<article>
<h1>How to create a pop-up without JavaScript</h1>
<p>Ever wanted a pop-up mechanism on your website, but you don't want to use JavaScript? Here's how:</p>
<ol>
<li>Add a <code><details></code> and <code><summary></code> to your document</li>
<li>Insert a <code><div></code> to your <code><details></code> element</li>
<li>Add a scaling animation to this <code><div></code></li>
<li>Add this animation to the <code><div></code> when the <code>[open]</code> attribute is toggled on the <code><details></code> element</li>
</ol>
<p>Toggle the <strong>How it works</strong> button for more info.</p>
</article>
<details>
<summary>How it works<svg xmlns="http://www.w3.org/2000/svg" width="192" height="192" fill="currentColor" viewBox="0 0 256 256"><rect width="256" height="256" fill="none"></rect><circle cx="128" cy="128" r="96" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></circle><circle cx="128" cy="180" r="12"></circle><path d="M127.9995,144.0045v-8a28,28,0,1,0-28-28" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="16"></path></svg></summary>
<div>
<p>The scaling effect you see when you open this <code><details></code> element is created by using a keyframe animation.</p>
<p><pre><code>@keyframes scale {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
}
}</code></pre> </p>
<p>This animation is added to the <code><div></code>, but only when the <code>[open]</code> attribute is toggled.</p>
<p><pre><code>details[open] div {
animation: scale .15s ease;
}</code></pre></p>
<p>Sadly there's no way (that I know of) to animate the <code><div></code> when the <code><details></code> is closing.</p>
</div>
</details>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap");
*,
*:after,
*:before {
box-sizing: border-box;
}
body {
font-family: "Inter", sans-serif;
line-height: 1.5;
min-height: 100vh;
background-color: #f4f5f7;
padding-top: 10vh;
padding-bottom: 10vh;
}
strong {
font-weight: 600;
}
article {
width: 90%;
max-width: 600px;
margin-left: auto;
margin-right: auto;
font-size: 1.125rem;
padding: 2rem;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 15px 20px -10px rgba(#000, 0.1);
& > * + * {
margin-top: 1em;
}
&:is(h1, h2, h3) + * {
margin-top: 0.5em;
}
h1 {
font-weight: 900;
font-size: 2rem;
line-height: 1.125;
}
code {
background-color: #eee;
font-weight: 600;
font-family: monospace;
}
p {
}
ol {
counter-reset: sickstuff;
li {
position: relative;
padding-left: 32px;
counter-increment: sickstuff;
& + li {
margin-top: 0.5em;
}
&:before {
content: counter(sickstuff);
width: 24px;
height: 24px;
position: absolute;
left: 0;
top: calc((1.125rem * 1.5) - 24px);
font-size: 0.75em;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
background-color: #185adb;
color: #fff;
font-weight: 600;
}
}
}
}
details {
position: fixed;
right: 1rem;
bottom: 1rem;
margin-top: 2rem;
color: #6b7280;
display: flex;
flex-direction: column;
div {
background-color: #1e1e27;
box-shadow: 0 5px 10px rgba(#000, 0.15);
padding: 1.25rem;
border-radius: 8px;
position: absolute;
max-height: calc(100vh - 100px);
width: 400px;
max-width: calc(100vw - 2rem);
bottom: calc(100% + 1rem);
right: 0;
overflow: auto;
transform-origin: 100% 100%;
color: #95a3b9;
&::-webkit-scrollbar {
width: 15px;
background-color:#1e1e27;
}
&::-webkit-scrollbar-thumb {
width: 5px;
border-radius: 99em;
background-color: #95a3b9;
border: 5px solid #1e1e27;
}
& > * + * {
margin-top: 0.75em;
}
p > code {
font-size: 1rem;
font-family: monospace;
}
pre {
white-space: pre-line;
// background-color: #2c2d38;
border: 1px solid #95a3b9;
border-radius: 6px;
font-family: monospace;
padding: 0.75em;
font-size: 0.875rem;
color: #fff;
}
}
&[open] div {
animation: scale 0.25s ease;
}
}
summary {
display: inline-flex;
margin-left: auto;
margin-right: auto;
justify-content: center;
align-items: center;
font-weight: 600;
padding: 0.75em 3em .75em 1.25em;
border-radius: 99em;
color: #fff;
background-color: #185adb;
box-shadow: 0 5px 15px rgba(#000, 0.1);
list-style: none;
text-align: center;
cursor: pointer;
transition: 0.15s ease;
position: relative;
&::-webkit-details-marker {
display: none;
}
&:hover,
&:focus {
background-color: mix(#000, #185adb, 20%);
// color: #6366f1;
}
svg {
position: absolute;
right: 1.25em;
top: 50%;
transform: translateY(-50%);
width: 1.5em;
height: 1.5em;
}
}
@keyframes scale {
0% {
transform: scale(0);
}
100% {
transform: scale(1);
}
}
View Compiled
// Nope
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.