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.
<main>
<div class="anchor-wrapper">
<div class="anchor">
<svg class="boat-anchor" viewBox="0 0 576 512" title="anchor">
<path d="M12.971 352h32.394C67.172 454.735 181.944 512 288 512c106.229 0 220.853-57.38 242.635-160h32.394c10.691 0 16.045-12.926 8.485-20.485l-67.029-67.029c-4.686-4.686-12.284-4.686-16.971 0l-67.029 67.029c-7.56 7.56-2.206 20.485 8.485 20.485h35.146c-20.29 54.317-84.963 86.588-144.117 94.015V256h52c6.627 0 12-5.373 12-12v-40c0-6.627-5.373-12-12-12h-52v-5.47c37.281-13.178 63.995-48.725 64-90.518C384.005 43.772 341.605.738 289.37.01 235.723-.739 192 42.525 192 96c0 41.798 26.716 77.35 64 90.53V192h-52c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h52v190.015c-58.936-7.399-123.82-39.679-144.117-94.015h35.146c10.691 0 16.045-12.926 8.485-20.485l-67.029-67.029c-4.686-4.686-12.284-4.686-16.971 0L4.485 331.515C-3.074 339.074 2.28 352 12.971 352zM288 64c17.645 0 32 14.355 32 32s-14.355 32-32 32-32-14.355-32-32 14.355-32 32-32z" />
</svg>
</div>
</div>
<div class="boat">
<svg class="boaty" viewBox="0 0 236 236" fill="none" xmlns="http://www.w3.org/2000/svg">
<path class="boaty__wave" d="M206.107 226.167C195.683 226.167 185.85 223.708 176.607 218.792C158.513 228.625 135.798 228.625 117.705 218.792C99.6117 228.625 76.8967 228.625 59 218.792C46.905 225.577 33.04 226.658 19.6667 226.167V206.5C33.5317 206.992 46.905 205.517 59 196.667C76.11 208.958 100.398 208.958 117.705 196.667C135.11 208.958 159.3 208.958 176.607 196.667C188.505 205.517 201.977 206.992 215.743 206.5V226.167H206.107Z" />
<path class="boaty__body" d="M207.483 167.953C203.452 174.247 198.732 179.655 193.225 184.277C186.833 181.425 181.13 177 176.607 172.083C161.955 191.062 132.357 191.062 117.705 172.083C103.25 191.062 73.455 191.062 59 172.083C54.0833 177 48.675 181.425 42.2833 184.277C31.0733 175.033 22.6167 161.857 19.6667 147.5H215.743C214.17 154.875 211.417 161.66 207.483 167.953Z" />
<path class="boaty__sail" d="M29.5 132.75L108.167 19.9616V132.75H29.5ZM122.917 132.75C136.192 95.875 134.422 46.315 122.917 9.83331C169.723 24.9766 205.517 82.6 206.107 132.75H122.917Z" />
</svg>
</div>
</main>
@layer demo {
.anchor-wrapper {
position: relative;
}
.anchor {
anchor-name: --my-anchor;
position: absolute;
}
.boat {
bottom: anchor(--my-anchor top);
left: calc(anchor(--my-anchor center) - (var(--boat-size) * 0.5));
}
}
@layer base {
:root {
--anchor-size: 50px;
--boat-size: 250px;
}
*,
*:after,
*:before {
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
min-height: 100vh;
font-family: "Google Sans", sans-serif, system-ui;
background: var(--gradient-7);
position: relative;
overflow: hidden;
}
main {
height: 100vh;
width: 100vw;
display: grid;
place-items: center;
}
.anchor {
width: var(--anchor-size);
aspect-ratio: 1;
transition: all 0.2s ease;
background: var(--blue-1);
}
.boat {
position: absolute;
width: var(--boat-size);
aspect-ratio: 1;
background: var(--blue-6);
}
svg {
width: 100%;
height: 100%;
}
.boat-anchor {
fill: var(--gray-5);
}
.boaty {
fill: none;
}
.boaty__sail {
fill: var(--gray-1);
}
.boaty__wave {
fill: var(--blue-3);
}
.boaty__body {
fill: hsl(45 70% 30%);
}
}
import gsap from "https://cdn.skypack.dev/gsap@3.11.4";
import Draggable from "https://cdn.skypack.dev/gsap@3.11.4/Draggable";
gsap.registerPlugin(Draggable);
Draggable.create(".anchor", { type: "left,top", allowContextMenu: true });
Also see: Tab Triggers