HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<link href="https://fonts.googleapis.com/css2?family=Graduate&display=swap" rel="stylesheet" />
<button id="button" class="glitch-button" aria-label="uplink">
<svg xmlns="http://www.w3.org/2000/svg" width="900" height="240" viewBox="0 0 900 240" preserveAspecRatio="xmidYMid slice" xml:space="preserve">
<defs>
<filter id="dm-filter--hover" color-interpolation-filters="sRGB" preserveAspectRatio="none">
<feFlood x="0" y="0" width="120%" height="100%" flood-color="rgb(128, 0, 128)" result="FEIMG-NO-TRANSFORM" />
<feFlood x="0" y="0" width="120%" height="6px" flood-color="rgb(256, 0, 128)" result="FEIMG-XMAX">
<animate attributeName="height" values="6px; 1px; 6px" dur="4s" repeatCount="indefinite" begin="0" />
<animate attributeName="y" values="80px; 160px; 120px; 160px; 90px; 140px; 80px" dur="10s" repeatCount="indefinite" begin="0" />
</feFlood>
<feFlood x="0" y="0" width="120%" height="6px" flood-color="rgb(0, 0, 128)" result="FEIMG-XMIN">
<animate attributeName="height" values="6px; 12px; 4px" dur="6s" repeatCount="indefinite" begin="0" />
<animate attributeName="y" values="80px; 100px; 160px; 110px; 80px; 140px; 90px; 100px; 80px; 150px; 80px" dur="20s" repeatCount="indefinite" begin="0" />
</feFlood>
<feMerge result="MERGE">
<feMergeNode in="FEIMG-NO-TRANSFORM" />
<feMergeNode in="FEIMG-XMAX" />
<feMergeNode in="FEIMG-XMIN" />
</feMerge>
<feDropShadow in="SourceGraphic" dx="0" dy="0" stdDeviation="00" flood-color="lime" result="SHADOW_LIME">
<animate class="anim" calcMode="discrete" attributeName="dx" values="0; 0; 0; 0; 2; 0; 5; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; -3; 0; 0; -2; 0; 0; 0; 0; 0; 2; 0; 0; 4; 0; -3; 0; -4; 0; 0; 2; 0; 0; 5; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0" dur="7s" repeatCount="indefinite" begin="0" fill="freeze" />
<animate class="anim" calcMode="discrete" attributeName="dy" values="0; 0; -1; 0; 0; 0; 0; 0; 3; 0; 0; 0; 0; 0; 5; 0; 0; 0; 0; 0; 2; 0; 0; -4; -3; 0; 0; 0; 2; -1; 3; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0" dur="7.5s" repeatCount="indefinite" begin="0" fill="freeze" />
</feDropShadow>
<feDropShadow in="SourceGraphic" dx="0" dy="0" stdDeviation="00" flood-color="red" result="SHADOW_FUCHSIA">
<animate class="anim" calcMode="discrete" attributeName="dx" values="0; 0; 0; 0; 0; 0; .2; 0; 0; 0; -1; 0; 0; 0; 0; 0; 0; 4; 0; 0; 0; 0; 0; 0; 3; 0; 0; 0; 0; -3; 0; 0; 0; 2; 0; 1; 4; 0; 0; 0; 0; 0; 0; 5; 0; 0; -3; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0" dur="8s" repeatCount="indefinite" begin="0" fill="freeze" />
<animate class="anim" calcMode="discrete" attributeName="dy" values="0; 0; 2; 0; 0; 0; 0; 0; 0; 0; -2; 0; 0; 0; -4; 0; 0; 0; 0; -3; 0; 0; 0; 5; 3; 0; 0; 0; 0; 0; 0; 0; -2; 0; 0; 0; 4; 0; 0; 0; 0; 0; 0; 0; 0; 0; -1; 0; 0; 0; 0; 0; 0; 0; 0; 0" dur="7.7s" repeatCount="indefinite" begin="0" fill="freeze" />
</feDropShadow>
<feBlend in="SHADOW_LIME" in2="SHADOW_FUCHSIA" result="BLEND_SHADOW" mode="screen" />
<feDisplacementMap in="BLEND_SHADOW" in2="MERGE" scale="10" xChannelSelector="R" yChannelSelector="B">
<animate attributeName="scale" values="-10; 5; 0; 10; 3; 8; -2; -8; 4; -5; 10; 6" dur="10s" repeatCount="indefinite" begin="0" />
</feDisplacementMap>
</filter>
</defs>
<svg class="filter" xmlns="http://www.w3.org/2000/svg" width="600" height="400" viewBox="0 0 600 400" preserveAspecRatio="none">
<defs>
<filter id="dm-filter--active" color-interpolation-filters="sRGB" preserveAspectRatio="none">
<feImage id="feimage-glitchmask-r" preserveAspectRatio="none" result="FEIMG-GLITCH-R" width="150%" height="100%" x="0" y="0">
<animate class="glitch-anim" id="an" attributeName="width" values="100%; 200%; 100%" dur="0.3s" repeatCount="1" begin="click" />
<animate class="glitch-anim" attributeName="height" values="100%; 200%; 100%" dur="0.2s" repeatCount="1" begin="click" fill="freeze" />
<animate class="glitch-anim" attributeName="y" values="0; 50; 0" dur="0.25s" repeatCount="1" begin="click" />
</feImage>
<feImage id="feimage-glitchmask-b" preserveAspectRatio="none" result="FEIMG-GLITCH-B" width="150%" height="100%" x="0" y="0">
<animate class="glitch-anim" attributeName="width" values="300%; 100%; 300%" dur="0.25s" repeatCount="1" begin="click" fill="freeze" />
<animate class="glitch-anim" attributeName="height" values="80%; 100%; 80%" dur="0.3s" repeatCount="1" begin="click" fill="freeze" />
<animate class="glitch-anim" attributeName="y" values="0; 10; 0" dur="0.2s" repeatCount="1" begin="click" />
</feImage>
<feBlend in="FEIMG-GLITCH-R" in2="FEIMG-GLITCH-B" result="BLEND_DMMAP" mode="screen" />
<feDropShadow in="SourceGraphic" dx="0" dy="0" stdDeviation="00" flood-color="lime" result="SHADOW_LIME">
<animate class="glitch-anim" calcMode="discrete" attributeName="dx" values="6; 11; 5; 0; 4; 0; -3; -7; 12; -2; -8; 0; 0; 17; 0; 6; 14; 6; -13; 0; -7; 0; 0; 8; 11; 4; 15; -7" dur="0.3s" repeatCount="1" begin="click" />
<animate class="glitch-anim" calcMode="discrete" attributeName="dy" values="5; 0; -4; -9; 0; 11; 8; 0; 10; -8; 15; -12; 12; -6; 0; -8; -4; 6; 9; 16; 0; 4; -4; 5; 0; -10; 0" dur="0.4s" repeatCount="1" begin="click" />
</feDropShadow>
<feDropShadow in="SourceGraphic" dx="0" dy="0" stdDeviation="00" flood-color="red" result="SHADOW_RED">
<animate class="glitch-anim" calcMode="discrete" attributeName="dx" values="0; 10; 14; -13; 0; -9; -13; 0; 16; 12; 10; -10; 8; 5; -6; 13; 0; 9; 11; 0; 14; 0; 0; -8; 3" dur="0.3s" repeatCount="1" begin="click" />
<animate class="glitch-anim" calcMode="discrete" attributeName="dy" values="0; 7; 10; 3; -13; -8; -6; -8; 0; -12; 0; 0; 0; 14; 9; 0; 15; 17; 0; -6; 0; -9; 8; 14; -6; 0" dur="0.3s" repeatCount="1" begin="click" />
</feDropShadow>
<feBlend in="SHADOW_LIME" in2="SHADOW_RED" result="BLEND_SHADOW" mode="screen" />
<feDisplacementMap in="BLEND_SHADOW" in2="BLEND_DMMAP" scale="0" xChannelSelector="R" yChannelSelector="B">
<animate class="glitch-anim" attributeName="scale" values="0; 300; 0" dur="0.3s" repeatCount="1" begin="click" />
</feDisplacementMap>
</filter>
</defs>
</svg>
<g id="filtered">
<rect width="100%" height="100%" fill="transparent" />
<text class="glitch-button__text" y="50%" x="50%" text-anchor="middle">
<tspan dx="1" dy="31">[ T ickl       Beam ]</tspan>
</text>
<text class="glitch-button__text" y="50%" x="50%" text-anchor="middle">
<tspan dx="33" dy="31">[ By te       Cranc ]</tspan>
</text>
<circle cx="50%" cy="50%" r="50px" fill="white" style="display: none;" />
<image class="glitch-button__img" href="https://assets.codepen.io/100347/fedm_bot-1.svg" x="50%" y="50%" height="140" width="140" transform="translate(-70, -70)" />
<image class="glitch-button__img" href="https://assets.codepen.io/100347/fedm_bot-2.svg" x="50%" y="50%" height="140" width="140" transform="translate(-70, -70)" />
<g transform="translate(-90, -90)">
<svg x="50%" y="50%" width="180" height="180" viewBox="-90 -90 180 180" style="overflow: visible;">
<path class="spin1" id="arc1" d="" />
<path class="spin2" id="arc2" d="" /> <!-- -->
<path class="spin3" id="arc3" d="" />
</svg>
</g>
</g>
</svg>
</button>
@use postcss-preset-env;
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
height: 100%;
}
p {
margin-bottom: 1em;
}
.filter {
position: absolute;
top: 0;
left: -1;
width: 1px;
height: 1px;
visibility: hidden;
}
body {
margin: 0;
padding: 1.25em;
height: 100%;
color: white;
font: 0.85em -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
min-width: 320px;
display: flex;
align-items: center;
text-align: center;
background-color: #2e2d42;
background-size: auto, contain, 100% 100%;
@nest .jpg & {
background-image: radial-gradient(circle, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.9) 80%),
repeating-radial-gradient(circle, transparent, transparent 2px, #2a3d37 2px, #2a3d37 4px),
url('https://assets.codepen.io/100347/fedm_metal.jpg');
}
@nest .webp & {
background-image: radial-gradient(circle, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.9) 80%),
repeating-radial-gradient(circle, transparent, transparent 2px, #2a3d37 2px, #2a3d37 4px),
url('https://assets.codepen.io/100347/fedm_metal.webp');
}
}
.glitch-button {
display: block;
border: none;
background: transparent;
position: relative;
margin: 0 auto;
flex: 0 0 auto;
cursor: crosshair;
&:hover {
outline: none;
}
}
@media screen and (prefers-reduced-motion: no-preference) {
.glitch-button__filtered {
&:active,
&:hover,
&:focus {
filter: url('#dm-filter--hover');
}
@nest .glitch-button--morphing & {
filter: url('#dm-filter--active');
}
}
}
.glitch-button__text {
fill: white;
font: 80px/0.75 'Graduate', sans-serif;
text-transform: uppercase;
}
.glitch-button__text,
.glitch-button__img {
@nest .glitch-button--inactive &:nth-of-type(1) {
pointer-events: auto;
animation: swapTextIn 0.15s 1 forwards;
}
@nest .glitch-button--active &:nth-of-type(1) {
pointer-events: none;
animation: swapTextOut 0.15s 1 forwards;
}
&:nth-of-type(2) {
visibility: hidden;
pointer-events: none;
}
@nest .glitch-button--inactive &:nth-of-type(2) {
pointer-events: none;
animation: swapTextOut 0.15s 1 forwards;
}
@nest .glitch-button--active &:nth-of-type(2) {
pointer-events: auto;
animation: swapTextIn 0.15s 1 forwards;
}
}
.spin1,
.spin2,
.spin3 {
fill: none;
stroke-width: 6px;
stroke: white;
opacity: 1;
}
.spin2 {
stroke-width: 3px;
}
.spin3 {
stroke-width: 3px;
}
@keyframes swapTextOut {
0% {
visibility: visible;
}
100%,
50% {
visibility: hidden;
}
}
@keyframes swapTextIn {
0%,
50% {
visibility: hidden;
}
100% {
visibility: visible;
}
}
webpSupported();
new Spinner("#arc1", 88, 10, 50, 4000, -5000);
new Spinner("#arc2", 83.5, 90, 170, -6000, 10000);
new Spinner("#arc3", 92.5, 70, 260, 4500, 9000);
const button = document.getElementById("button");
async function fetchImage(imgURL, feImgID) {
const imageFetched = new Promise((resolve) => {
fetch(imgURL, {
method: "GET",
headers: new Headers(),
mode: "cors",
cache: "default"
})
.then((response) => {
return response.text();
})
.then((svgText) => {
const feImg = document.getElementById(feImgID);
const uri = encodeURIComponent(svgText);
if (feImg) {
feImg.setAttribute("href", `data:image/svg+xml;charset=utf-8,${uri}`);
resolve();
}
resolve(false);
});
});
return await imageFetched;
}
Promise.all([
fetchImage(
"https://assets.codepen.io/100347/fedm_glitch-blue.svg",
"feimage-glitchmask-b"
),
fetchImage(
"https://assets.codepen.io/100347/fedm_glitch-red.svg",
"feimage-glitchmask-r"
)
]).then(() => {
requestAnimationFrame(() => {
document
.getElementById("filtered")
.classList.add("glitch-button__filtered");
});
});
const animations = document.querySelectorAll(".glitch-anim");
let timeout;
const animate = (option) => {
for (let animation of animations) {
animation[`${option}Element`]();
}
};
const startAnim = () => {
button.removeEventListener("click", startAnim);
button.addEventListener("click", revertAnim);
button.classList.remove("glitch-button--inactive");
button.classList.add("glitch-button--active", "glitch-button--morphing");
setTimeout(() => {
button.classList.remove("glitch-button--morphing");
}, 300);
animate("begin");
timeout = setTimeout(revertAnim, 8000);
};
const revertAnim = () => {
clearTimeout(timeout);
button.removeEventListener("click", revertAnim);
button.addEventListener("click", startAnim);
button.classList.remove("glitch-button--active");
button.classList.add("glitch-button--inactive", "glitch-button--morphing");
setTimeout(() => {
button.classList.remove("glitch-button--morphing");
}, 300);
animate("begin");
};
button.addEventListener("click", startAnim);
Also see: Tab Triggers