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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<div class="wrapper">
<div class="heart-wrap">
<svg class="heart" id="heart" viewBox="0 0 1920 3000" xmlns="http://www.w3.org/2000/svg">
<path
id="heart-path-3"
transform="translate(974.58,767.88) rotate(-400) scale(0.001)"></path>
<path
id="heart-path-2"
transform="translate(932.84,695.15) rotate(-400) scale(0.001)"></path>
<path
id="heart-path-1"
transform="translate(888.72,629.18) rotate(-400) scale(0.001)"></path>
</svg>
</div>
</div>
* {
box-sizing: border-box;
}
body {
margin: 0;
background: #013f92;
}
svg {
overflow: hidden;
}
.wrapper {
position: relative;
width: 100%;
min-height: 100vh;
}
.heart-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.heart {
z-index: 1;
position: absolute;
top: 0;
left: 50%;
width: 100%;
height: 3000px;
min-width: 1920px;
pointer-events: none;
transform: translate3d(-50%, 0, 0);
}
let config = {
// shape colors
shapes: [
{
fill: '#f8566a',
stroke: ''
},
{
fill: 'transparent',
stroke: '#f8566a'
},
{
fill: 'transparent',
stroke: '#f8566a'
}
],
// animation duration
duration: 1200,
// option allows you to rotate the second/end path in a way that the points
// travel the least possible distance during morph, and as an effect the morph
// animation feel more "natural".
morph: 60,
// get more easing functions
// http://thednp.github.io/kute.js/easing.html
easing: 'easingQuinticInOut'
}
let paths = [
'M709.498 158c-171.062 0-336.86 170.013-414.112 244.508-81.05 78.16-220.906 117.187-220.906 306.215 0 237.322 163.682 598.787 348.781 514.902 126.72-57.429 183.931-99.993 253.844-275.484 54.084-135.757 210.296-193.167 210.296-420.15C887.4 290.672 946.747 158 709.498 158z',
'M819.183 84C603.326 84 394.11 298.645 296.628 392.697 194.353 491.375 17.873 540.649 17.873 779.3c0 299.624 206.546 755.983 440.117 650.075 159.903-72.505 232.096-126.243 320.318-347.805 68.246-171.396 265.365-243.877 265.365-530.448C1043.673 251.499 1118.56 84 819.183 84z',
'M929.557 11C666.76 11 412.049 272.269 293.37 386.75 168.855 506.864-46 566.84-46 857.333c0 364.706 251.46 920.194 535.82 791.281 194.676-88.254 282.567-153.665 389.972-423.354 83.087-208.625 323.07-296.851 323.07-645.67C1202.862 214.883 1294.034 11 929.557 11z'
];
let updatePaths = i => {
document.querySelector(`#heart-path-${i + 1}`).setAttribute('d', paths[i]);
}
let transform = params => {
for (let i = 0; i < 3; i++) {
KUTE.to(`#heart-path-${i + 1}`,
{
path: paths[i],
svgTransform: params
}, {
duration: config.duration,
easing: config.easing,
morphIndex: config.morph,
complete() {
if (i === 2) {
params.callback();
updatePaths(i);
}
}
}
).start();
}
}
for (let i = 0; i < 3; i++) {
updatePaths(i);
let selector = document.querySelector(`#heart-path-${i + 1}`);
let fillColor = config.shapes[i].fill;
let strokeColor = config.shapes[i].stroke;
if (fillColor) {
selector.setAttribute('fill', fillColor);
}
if (strokeColor) {
selector.setAttribute('stroke', strokeColor);
}
}
const transformParams = [
{
translate: [-370, -500],
rotate: 0,
scale: 1.001,
callback() {
transform(transformParams[1])
}
},
{
translate: [390, -180],
rotate: 110,
scale: 0.9,
callback() {
transform(transformParams[2])
}
},
{
translate: [350, -50],
rotate: 45,
scale: 1.3,
callback() {
transform(transformParams[0])
}
},
];
transform(transformParams[0])
Also see: Tab Triggers