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/css?family=Varela+Round" rel="stylesheet" />
<div class="layer">
<svg id="wrapper" class="wrapper" xmlns="http://www.w3.org/2000/svg">
<defs>
<svg xmlns="http://www.w3.org/2000/svg" class="displacementmap" id="absolute-displacementmap" width="256" height="256" preserveAspectRatio="none" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<style type="text/css">
.red-gradient {
fill: url(#red-gradient);
}
.blue-gradient {
fill: url(#blue-gradient);
mix-blend-mode: screen;
}
</style>
<linearGradient id="red-gradient" x1="0" x2="1" y1="0" y2="0" color-interpolation="sRGB" gradientUnits="objectBoundingBox">
<stop offset="0%" stop-color="#FF0000" />
<stop offset="1" stop-color="#FF0000" stop-opacity="0" />
</linearGradient>
<linearGradient id="blue-gradient" x1="0" x2="0" y1="0" y2="1" color-interpolation="sRGB" gradientUnits="objectBoundingBox">
<stop offset="0%" stop-color="#0000FF" />
<stop offset="1" stop-color="#0000FF" stop-opacity="0" />
</linearGradient>
</defs>
<rect width="100%" height="100%" x="0" y="0" fill="black" />
<rect id="red-gradient-rect" width="100%" height="100%" x="0" y="0" class="red-gradient" />
<rect id="blue-gradient-rect" width="100%" height="100%" x="0" y="0" class="blue-gradient" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" id="radial-waves-fragment" class="waves" width="480" height="480" preserveAspectRatio="none">
<defs>
<radialGradient id="radial-wave-gradient" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:0" />
<stop offset="0%" style="stop-color:rgb(128,0,128); stop-opacity:1" />
<stop offset="100%" style="stop-color:rgb(128,0,128);stop-opacity:1" />
</radialGradient>
</defs>
<rect id="rect" x="-20%" y="-20%" width="140%" height="140%" fill="url(#radial-wave-gradient)" />
</svg>
<filter id="dm-filter" x="0" y="0%" width="100%" height="100%" color-interpolation-filters="sRGB" preserveAspectRatio="none">
<!-- Feimage referencing an absolute map -->
<feImage id="absoluteMap" x="0" y="0" width="100%" height="100%" result="ABSOLUTEMAP" href="#absolute-displacementmap" />
<!-- A second feImage that defaults to a URL encoded neutral map. Here we will reference an SVG containing a radial gradient for the waves. Animation will then be achieved with javascript, updating the href of the feimage on each interval -->
<feImage id="radial-waves-feimage" x="0" y="0" width="100%" height="100%" result="WAVES" href="data:image/svg+xml;charset=utf-8,%3Csvg%20id%3D%22displacementmap%22%20width%3D%22256%22%20height%3D%22256%22%20preserveAspectRatio%3D%22none%22%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20id%3D%22rect%22%20x%3D%22-20%25%22%20y%3D%22-20%25%22%20width%3D%22140%25%22%20height%3D%22140%25%22%20fill%3D%22rgb%28128%2C0%2C128%29%22%2F%3E%3C%2Fsvg%3E" />
<!-- Merging absolutemap and animation -->
<feMerge result="MERGE_IMG">
<feMergeNode in="ABSOLUTEMAP" />
<feMergeNode in="WAVES" />
</feMerge>
<!-- Using the merged result as input for our displacement map -->
<feDisplacementMap in="SourceGraphic" in2="MERGE_IMG" scale="80" xChannelSelector="R" yChannelSelector="B" />
</filter>
</defs>
<g id="content" class="content">
<rect width="480" height="480" fill="black" fill-opacity="0" />
<image x="40" y="40" width="400px" height="400px" preserveAspectRatio="xMidYMid" href="https://assets.codepen.io/100347/fedm_pattern-a.svg" />
<svg aria-label="Button for opening a Layer" role="button" id="klikbut" class="klikbut" x="200" y="200" width="80px" height="80px" style="overflow: visible">
<desc>Click to open modal</desc>
<rect class="klikbut__bg" width="80px" height="80px" />
<text class="klikbut__text" x="7" y="53">cliq</text>
</svg>
<g id="modal" aria-label="Button for closing this Layer" role="dialog" class="modal">
<rect class="modal__bg" width="360" height="360" x="60" y="60" />
<text class="modal__text" text-anchor="middle" width="360" height="360" x="60" y="200">
<tspan x="240">That</tspan>
<tspan x="240" dy="1.1em">was one</tspan>
<tspan x="240" dy="1.1em">hell of a</tspan>
<tspan x="240" dy="1.1em">ripple!</tspan>
</text>
<svg role="button" id="closebut" class="closebut" x="220" y="100" width="40px" height="40px" style="overflow: visible">
<desc>Click to close modal</desc>
<text class="closebut__text" text-anchor="right" width="360" height="360" x="-44" y="24">close</text>
<rect class="closebut__bg" width="40px" height="40px" />
<line x1="10" y1="10" x2="30" y2="30" style="stroke:white;stroke-width:3;stroke-linecap: round;" />
<line x1="30" y1="10" x2="10" y2="30" style="stroke:white;stroke-width:3;stroke-linecap: round;" />
</svg>
</g>
</g>
</svg>
</div>
@use postcss-preset-env;
:root {
--bgCol: #424a5e;
--btnTxt: white;
--btnTxt--hover: #9f6dd8;
--modalBgCol: rgba(232, 224, 235, 0.8);
--modalTxt: #697277;
--btnCloseBgCol: #4b5969;
--btnCloseBgCol--hover: #d9a7f2;
}
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
height: 100%;
}
.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;
justify-content: center;
background: var(--bgCol);
font-family: 'Varela Round', sans-serif;
}
::selection {
background: var(--bgCol);
}
.waves {
pointer-events: none;
}
.klikbut {
overflow: hidden;
cursor: pointer;
}
.klikbut__text {
font-size: 40px;
fill: var(--btnTxt);
pointer-events: none;
transition: fill 0.3s;
@nest .klikbut:hover & {
fill: var(--btnTxt--hover);
}
}
.klikbut__bg {
fill: var(--btnTxt--hover);
cursor: pointer;
transition: fill 0.2s, transform 0.2s cubic-bezier(0.005, 0.625, 0.37, 1.65) 0.2s;
transform: scale(1);
@nest .klikbut:hover & {
fill: var(--btnTxt);
transform: translate(-20px, -20px) scale(1.5);
}
}
.layer {
position: relative;
display: flex;
justify-content: stretch;
margin: auto;
width: 480px;
height: 480px;
}
.modal {
display: none;
will-change: display, opacity, transform;
}
.content {
will-change: filter;
filter: url(#dm-filter);
}
.modal--active {
display: block;
pointer-events: auto;
animation: modalin 1s ease-out forwards;
}
.modal--inactive {
display: block;
pointer-events: none;
animation: modalout 0.8s 0.4s ease-out forwards;
}
.modal__bg {
fill: var(--modalBgCol);
}
.modal__text {
fill: var(--modalTxt);
font-size: 46px;
}
.closebut {
cursor: pointer;
}
.closebut__bg {
fill: var(--btnCloseBgCol);
transition: fill 0.3s;
@nest .closebut:hover & {
fill: var(--btnCloseBgCol--hover);
}
}
.wrapper {
display: block;
position: relative;
top: 0;
left: 0;
width: 480px;
height: 480px;
}
@keyframes modalin {
from {
opacity: 0;
transform: translate(40%, 40%) scale(0.2);
}
to {
opacity: 1;
transform: translate(0) scale(1);
}
}
@keyframes modalout {
from {
transform: translate(0) scale(1);
opacity: 1;
}
99% {
transform: translate(-25%, -25%) scale(1.5);
opacity: 0;
display: block;
}
100% {
opacity: 0;
transform: translate(-1000px, 0) scale(1);
display: none;
}
}
@keyframes trigger {
from {
opacity: 1;
}
50% {
opacity: 0.1;
}
to {
opacity: 1;
}
}
const modal = document.getElementById("modal");
const klikbut = document.getElementById("klikbut");
const closebut = document.getElementById("closebut");
const modalEvt = new CustomEvent("triggerModal");
const setupMap = () => {
const feImage = document.querySelector("#absoluteMap");
const absMapUrl = feImage.getAttribute("href");
const absMap = document.querySelector(absMapUrl);
feImage.setAttribute(
"href",
`data:image/svg+xml;charset=utf-8,${encodeURIComponent(absMap.outerHTML)}`
);
};
const fadeIn = () => {
modal.classList.remove("modal--inactive");
modal.classList.add("modal--active");
klikbut.removeEventListener("click", fadeIn);
closebut.addEventListener("click", fadeOut);
document.body.dispatchEvent(modalEvt);
};
const fadeOut = () => {
modal.classList.remove("modal--active");
modal.classList.add("modal--inactive");
closebut.removeEventListener("click", fadeOut);
klikbut.addEventListener("click", fadeIn);
document.body.dispatchEvent(modalEvt);
};
function initUI() {
klikbut.addEventListener("click", fadeIn);
}
setupMap();
testSVGFragmentToFeImg().then((fragmentInFeImageSupported) => {
const animDur = 1350;
const ripplFragment = document.getElementById("radial-waves-fragment");
const ripplFeImg = document.getElementById("radial-waves-feimage");
const numOfStops = ripplFragment.querySelectorAll('[offset="0%"]').length;
const timelineOffsetDelta = Math.floor(animDur / numOfStops);
const animeTimelineConf = {
duration: animDur,
autoplay: false,
easing: "easeOutQuad",
round: 10
};
let timelineOffset = 0;
let animeTimeline;
if (!fragmentInFeImageSupported) {
const animeTgt = {};
const uriArr = encodeURIComponent(
ripplFragment.outerHTML.replace(/offset="0%"/g, 'offset="~"')
).split("~");
animeTimelineConf.update = () => {
let hrefVal = "data:image/svg+xml;charset=utf-8,";
for (let i = 0; i < numOfStops; i++) {
hrefVal += `${uriArr[i]}${animeTgt[`offset_${numOfStops - i - 1}`]}`;
}
hrefVal += `${uriArr[uriArr.length - 1]}`;
ripplFeImg.setAttribute("href", hrefVal);
};
animeTimeline = anime.timeline(animeTimelineConf);
for (let i = 0; i < numOfStops; i++) {
const id = `offset_${i}`;
animeTgt[id] = "0%";
const conf = {
targets: animeTgt,
[id]: "100%"
};
animeTimeline.add(conf, timelineOffset);
timelineOffset += timelineOffsetDelta;
}
} else {
adjustSafariScreenDensity(ripplFragment);
animeTimeline = anime.timeline(animeTimelineConf);
for (let i = 0; i < numOfStops; i++) {
const className = `offset_${i}`;
const el = ripplFragment.querySelector(
`[offset="0%"]:nth-of-type(${numOfStops - i})`
);
el.classList.add(className);
const conf = {
targets: `.${className}`,
offset: "99%"
};
animeTimeline.add(conf, timelineOffset);
timelineOffset += timelineOffsetDelta;
}
ripplFeImg.setAttribute("href", "#radial-waves-fragment");
}
document.body.addEventListener("triggerModal", animeTimeline.restart);
initUI();
});
Also see: Tab Triggers