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.
<!--
Underwater Background #2
Copyright (c) 2024 by Wakana Y.K. (https://codepen.io/wakana-k/pen/KKYmxYq)
-->
<div id='surface'></div>
<div id='caustics'></div>
<div id='bg'></div>
<div id='sun'>
<div id='sun_layer1'></div>
<div id='sun_layer2'></div>
<div id='sun_layer3'></div>
</div>
<svg>
<filter id="noise1">
<feTurbulence type="turbulence" baseFrequency=".05" numOctaves="1" seed="3" stitchTiles='stitch' />
<feDisplacementMap in="SourceGraphic" scale="10" />
</filter>
</svg>
<main>
<section>
<div>
<h1>Underwater #2</h1>
<p><small>CSS texture animation</small></p>
</div>
<div class="arrows">
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
</section>
<section>
<div>
<p>This water animation uses image textures from <a href='https://unsplash.com/' target='_blank'>unsplash.com</a>.</p>
</div>
<div class="arrows">
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
</section>
<section>
<div>
<h2>Photo credits</h2>
<p><br></p>
<ul>
<li>
Matt Hardy - <a target="_blank" href="https://unsplash.com/photos/body-of-water-under-sky-6ArTTluciuA">body of water under sky</a></li>
<li>Artem Militonian - <a target="_blank" href="https://unsplash.com/photos/blue-ocean-UYW6FZLlnL8">blue ocean</a></li>
</ul>
<p><br></p>
<p>Thanks!</p>
</div>
</section>
<section>
<div class="arrows">
<div></div>
<div></div>
<div></div>
</div>
</section>
<section>
</section>
<section>
</section>
<section>
<div>
<h2>Related works</h2>
<div>
<figure>
<a target="_top" href="https://codepen.io/wakana-k/pen/eYovJJe"><img src="https://shots.codepen.io/username/pen/eYovJJe-1280.jpg"></a>
<figcaption>Underwater #1</figcaption>
</figure>
<figure>
<a target="_top" href="https://codepen.io/wakana-k/pen/jORywbO"><img src="https://shots.codepen.io/username/pen/jORywbO-1280.jpg"></a>
<figcaption>Cloud and Sunbeam #1</figcaption>
</figure>
<figure>
<a target="_top" href="https://codepen.io/wakana-k/pen/zYXwLPq"><img src="https://shots.codepen.io/username/pen/zYXwLPq-1280.jpg"></a>
<figcaption>Cloud and Sunbeam #2</figcaption>
</figure>
<figure>
<a target="_top" href="https://codepen.io/wakana-k/pen/XWQpVNB"><img src="https://shots.codepen.io/username/pen/XWQpVNB-1280.jpg"></a>
<figcaption>Sky and Birds</figcaption>
</figure>
</div>
</div>
</section>
<section>
</section>
<section>
</section>
<section>
<div>
<p>Fin.</p>
</div>
</section>
</main>
@import url("https://fonts.googleapis.com/css2?family=Asap&display=swap");
:root {
--ratioW: 1;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
*::before,
*::after {
box-sizing: border-box;
}
html,
body {
overscroll-behavior-x: none;
overscroll-behavior-y: none;
scroll-behavior: smooth;
min-height: 100%;
}
body {
font-family: "Asap", sans-serif;
position: relative;
width: 100vw;
min-height: 100vh;
text-align: center;
overflow-x: hidden;
background: linear-gradient(
to bottom,
oklch(60% 0.2 230),
oklch(60% 0.2 180)
);
color: #333;
font-size: clamp(12px, 5.5vw, 28px);
}
main {
position: relative;
}
section {
position: relative;
width: 100vw;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
h1,
h2,
p,
figcaption {
overflow-wrap: break-word;
max-width: 80vw;
mix-blend-mode: overlay;
transform: translate3d(0, 0, 0); /* for safari */
}
a {
text-decoration: underline dotted;
color: currentColor;
}
h2 {
font-size: 1.3em;
}
ul {
max-width: 80vw;
overflow-x: hidden;
overflow-y: visible;
}
li {
list-style: none;
font-size: 0.8em;
text-align: left;
margin: 0.8em 0;
}
figure {
margin: 3rem 0;
font-size: 0.7em;
color: currentColor;
}
figure img {
display: block;
width: clamp(100px, 50vw, 300px);
border-radius: 10px;
filter: drop-shadow(3px 4px 2px rgba(0, 0, 0, 0.2));
background-color: lightgray;
}
figure a {
color: currentColor;
}
svg {
display: none;
}
#bg {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: linear-gradient(
to bottom,
white,
gray 25%,
gray 60%,
khaki
);
opacity: 0.5;
mix-blend-mode: overlay;
}
#surface {
mix-blend-mode: overlay;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
#surface::before,
#surface::after {
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: url("https://images.unsplash.com/photo-1518837695005-2083093ee35b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTEyMTIwOTZ8&ixlib=rb-4.0.3&q=80&w=400");
background-repeat: repeat-x;
--duration: 8s;
--lowHeight: 30vh;
--highHeight: 70vh;
--layerNum: 2;
--index: 0;
--opacity: 0.4;
animation: surface var(--duration) linear infinite;
animation-delay: calc(
(var(--duration) / var(--layerNum)) * var(--index) * -1
);
opacity: 0;
mask-image: linear-gradient(to top, white, transparent var(--lowHeight));
}
#surface::before {
--index: 0;
transform: scale3d(1, -1, 1);
}
#surface::after {
--index: 1;
transform: scale3d(-1, -1, 1);
}
#caustics {
position: fixed;
bottom: 0;
top: 0;
width: 100vw;
height: 100vh;
filter: url(#noise1);
}
#caustics::before,
#caustics::after {
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: url("https://images.unsplash.com/photo-1568145675395-66a2eda0c6d7?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE3MTEyMTAwNjh8&ixlib=rb-4.0.3&q=80&w=400");
background-repeat: repeat;
--duration: 10s;
--gapY: 0px;
background-size: calc(100vw / var(--ratioW)) 30vh;
animation: caustics calc(var(--duration) * (var(--ratioW))) linear infinite;
opacity: 0.3;
mask-image: linear-gradient(
to top,
white,
transparent,
transparent,
transparent
);
}
#caustics::after {
--duration: 11s;
--gapY: 10vh;
animation-delay: -2s;
transform: scale3d(-1, 1, 1);
}
#sun {
mix-blend-mode: overlay;
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
}
#sun div {
content: "";
display: block;
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: 50vw 0;
animation: sun 7s ease infinite alternate;
mask-image: linear-gradient(
to bottom,
transparent 15%,
white 50%,
white 55%,
transparent 80%
);
}
#sun #sun_layer1 {
background: linear-gradient(
to right,
transparent 39%,
white 40%,
transparent 41%,
transparent 48.5%,
white 50%,
transparent 51.5%,
transparent 53%,
white 54%,
transparent 55%,
transparent 70%,
white 71%,
transparent 72%
);
}
#sun #sun_layer2 {
animation-delay: -2s;
animation-duration: 7.8s;
animation-direction: alternate-reverse;
background: linear-gradient(
to right,
transparent 32%,
white 33%,
transparent 34%,
transparent 38%,
white 39%,
transparent 40%,
transparent 53%,
white 54%,
transparent 55%,
transparent 63.5%,
white 65%,
transparent 66.5%
);
}
#sun #sun_layer3 {
animation-delay: -5s;
animation-duration: 8.5s;
background: linear-gradient(
to right,
transparent 38.5%,
white 40%,
transparent 41.5%,
transparent 47%,
white 48%,
transparent 49%,
transparent 52%,
white 53%,
transparent 54%,
transparent 60%,
white 61%,
transparent 62%
);
}
.arrows {
width: auto;
height: auto;
position: absolute;
bottom: 0.5rem;
text-align: center;
mix-blend-mode: overlay;
}
.arrows div {
--arrowSize: 1.3rem;
--arrowColor: currentColor;
width: var(--arrowSize);
height: var(--arrowSize);
margin: calc(var(--arrowSize) * -1.5) 0;
background: transparent;
border: calc(var(--arrowSize) * 0.11) solid;
border-color: transparent transparent var(--arrowColor) var(--arrowColor);
transform: rotate(-45deg);
animation: arrow 2s infinite linear;
}
@keyframes arrow {
0% {
opacity: 0;
}
40% {
opacity: 1;
}
80% {
opacity: 0;
}
100% {
opacity: 0;
}
}
.arrows div:nth-of-type(3) {
animation-delay: -0.8s;
}
.arrows div:nth-of-type(2) {
animation-delay: -0.4s;
}
.arrows div:nth-of-type(1) {
animation-delay: 0s;
}
@keyframes surface {
0% {
opacity: 0;
background-position: center bottom;
background-size: 100% var(--highHeight);
}
20% {
opacity: var(--opacity);
}
100% {
opacity: 0;
background-position: center bottom calc(-1 * var(--lowHeight));
background-size: 100% var(--lowHeight);
}
}
@keyframes caustics {
0% {
background-position: bottom var(--gapY) left;
}
100% {
background-position: bottom var(--gapY) left -100vw;
}
}
@keyframes sun {
0% {
opacity: 0.1;
transform: skew(5deg) scale3d(3, 1.5, 1);
}
50% {
opacity: 0.08;
transform: skew(0deg) scale3d(1.5, 1, 1);
}
100% {
opacity: 0.1;
transform: skew(-5deg) scale3d(3, 1, 1);
}
}
@media (orientation: portrait) {
:root {
--ratioW: 1;
}
}
@media (min-aspect-ratio: 1/1) {
:root {
--ratioW: 1;
}
}
@media (min-aspect-ratio: 2/1) {
:root {
--ratioW: 2;
}
}
@media (min-aspect-ratio: 3/1) {
:root {
--ratioW: 3;
}
}
@media (min-aspect-ratio: 4/1) {
:root {
--ratioW: 4;
}
}
@media (min-aspect-ratio: 5/1) {
:root {
--ratioW: 5;
}
}
Also see: Tab Triggers