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 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="container">
<canvas class="illo"></canvas>
<p>Click & drag to rotate</p>
</div>
html { height: 100%; }
body {
min-height: 100%;
margin: 0;
background: #FD0;
font-family: sans-serif;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
canvas {
display: block;
margin: 0px auto 20px;
cursor: move;
}
// Made with Zdog
var illoElem = document.querySelector('.illo');
var illoSize = 72;
var minWindowSize = Math.min( window.innerWidth - 20, window.innerHeight - 60 );
var zoom = Math.floor( minWindowSize / illoSize );
illoElem.setAttribute( 'width', illoSize * zoom );
illoElem.setAttribute( 'height', illoSize * zoom );
var isSpinning = true;
var TAU = Zdog.TAU;
var illo = new Zdog.Illustration({
element: illoElem,
zoom: zoom,
dragRotate: true,
onDragStart: function() {
isSpinning = false;
},
});
// colors
var colors = {
eye: '#333',
white: '#FFF',
hair: '#631',
overalls: '#24D',
cloth: '#E11',
skin: '#FC9',
leather: '#A63',
};
// -- illustration shapes --- //
// head
var head = new Zdog.Shape({
addTo: illo,
translate: { y: -12, z: 1 },
color: colors.skin,
stroke: 23,
});
// nose
new Zdog.Shape({
addTo: head,
translate: { y: 5, z: 13 },
color: colors.skin,
stroke: 7,
});
// chin
var chin = new Zdog.Shape({
addTo: head,
path: [
{ x: -5, y: 6, z: 4 },
{ x: 0, y: 8.5, z: 6 }
],
color: colors.skin,
stroke: 10,
});
chin.copy({
scale: { x: -1 },
});
// mouth
new Zdog.Shape({
path: [
{ x: -3, y: -3 },
{ x: -1, y: -1 },
{ x: 1, y: -1 },
{ x: 3, y: -3 },
],
translate: { y: 12, z: 9 },
color: colors.cloth,
fill: true,
stroke: 2,
addTo: head,
});
var hat = new Zdog.Anchor({
addTo: head,
translate: { y: -8 },
});
// hat front
var hatFrontA = new Zdog.Vector({ x: -8, y: 0, z: 5 });
var hatFrontB = new Zdog.Vector({ x: -4, y: -3, z: 7 });
var hatFrontC = hatFrontB.copy().multiply({ x: -1 });
var hatFrontD = hatFrontA.copy().multiply({ x: -1 });
// hat front
new Zdog.Shape({
path: [
hatFrontA,
hatFrontB,
hatFrontC,
hatFrontD,
],
color: colors.cloth,
closed: false,
fill: false,
stroke: 11,
addTo: hat,
});
var hatTopFront = new Zdog.Vector({ x: 10, y: 1, z: 5 });
var hatTopBackA = new Zdog.Vector({ x: 7, y: 3, z: -10 });
var hatTopBackB = hatTopBackA.copy().multiply({ x: -1 });
// hat top
new Zdog.Shape({
path: [
hatTopFront.copy().multiply({ x: -1 }),
hatTopFront,
hatTopBackA,
hatTopBackB,
],
color: colors.cloth,
fill: true,
stroke: 9,
addTo: hat,
});
// hat top back
new Zdog.Shape({
path: [
hatTopBackA,
hatTopBackB,
],
color: colors.cloth,
stroke: 9,
addTo: hat,
});
// hat top side
var hatTopSide = new Zdog.Shape({
path: [
hatTopFront,
hatTopBackA,
],
color: colors.cloth,
stroke: 9,
addTo: hat,
});
hatTopSide.copy({
scale: { x: -1 },
});
// hat top cover
new Zdog.Shape({
path: [
{ x: -3, y: 0, z: -8 },
{ x: 3, y: 0, z: -8 },
{ x: 3, y: -3, z: 4 },
{ x: -3, y: -3, z: 4 },
],
color: colors.cloth,
stroke: 6,
addTo: hat,
});
// hat brim
// brim has left & right side
var hatBrim = new Zdog.Shape({
path: [
{ x: 10, y: 4, z: -0 },
{ x: 8, y: 4, z: 5 },
{ x: 0, y: 2, z: 9 },
{ x: 0, y: 1, z: 2 },
],
translate: { z: 7 },
color: colors.cloth,
fill: true,
stroke: 4,
addTo: hat,
});
hatBrim.copy({
scale: { x: -1 },
});
// eyes pupil
var eye = new Zdog.Shape({
path: [
{ y: 2 },
{ y: 4 },
],
translate: { x: 5, z: 9 },
color: colors.eye,
stroke: 3,
addTo: head,
});
eye.copy({
translate: { x: -5, z: 9 },
});
var brow = new Zdog.Shape({
path: [
{ x: 3, y: 0, z: -0 },
{ x: 1.5, y: -0.5, z: 1 },
{ x: 0, y: 0, z: 1 },
],
translate: { x: 4, y: -1.5, z: 9 },
color: colors.hair,
closed: false,
stroke: 2.5,
addTo: head,
});
brow.copy({
scale: { x: -1 },
translate: { x: -4, y: -1.5, z: 9 },
});
var mustache = new Zdog.Group({
addTo: head,
translate: { y: 6.5, z: 10 },
});
// mustache line
new Zdog.Shape({
path: [
{ x: 2, y: 1, z: 1.5 },
{ x: 6.5, y: 0, z: -0 },
],
color: colors.hair,
stroke: 3,
addTo: mustache,
});
// mustache sections
var mustacheSection = new Zdog.Shape({
translate: { x: 1.75, y: 1.5, z: 1 },
color: colors.hair,
stroke: 4,
addTo: mustache,
});
mustacheSection.copy({
translate: { x: 4.5, y: 1, z: 0.75 }
});
mustache.copyGraph({
scale: { x: -1 },
});
var sideburns = new Zdog.Shape({
path: [
{ y: 0, z: 0 },
{ y: -4, z: 1.5 },
{ y: -4, z: 1 },
{ y: -1, z: 2 },
],
translate: { x: 10, y: 3, z: 2 },
color: colors.hair,
closed: false,
fill: true,
stroke: 3,
addTo: head,
});
sideburns.copy({
translate: sideburns.translate.copy().multiply({ x: -1 }),
});
var ear = new Zdog.Shape({
path: [
{ x: 0, y: 0, z: -0 },
{ x: 0, y: -4, z: -0 },
{ x: 1, y: -4, z: -2 },
{ x: 0, y: 0, z: -1 },
],
translate: { x: 10, y: 4, z: -2 },
color: colors.skin,
fill: true,
stroke: 4,
addTo: head,
});
ear.copy({
scale: { x: -1 },
translate: ear.translate.copy().multiply({ x: -1 }),
});
var sideHair = new Zdog.Anchor({
addTo: head,
});
// hair side panel
new Zdog.Shape({
path: [
{ x: 4, y: -7, z: -1 },
{ x: 3, y: 0, z: -0 },
{ x: 0, y: 0, z: -5 },
{ x: 2, y: -6.5, z: -6 },
],
translate: { x: 5, y: 7, z: -5 },
color: colors.hair,
fill: true,
stroke: 3,
addTo: sideHair,
});
// hair balls
var hairBall = new Zdog.Shape({
translate: { x: 6, y: 8, z: -8 },
color: colors.hair,
stroke: 6,
addTo: sideHair,
});
hairBall.copy({
translate: { x: 2, y: 8, z: -10 },
});
sideHair.copyGraph({
scale: { x: -1 },
});
// hair back panel
new Zdog.Shape({
path: [
{ x: 5, y: 0, z: -0 },
{ x: 6, y: -6.5, z: -1 },
{ x: -6, y: -6.5, z: -1 },
{ x: -5, y: 0, z: -0 },
],
translate: { y: 7, z: -10 },
color: colors.hair,
fill: true,
stroke: 3,
addTo: head,
});
var body = new Zdog.Shape({
translate: { x: 0, y: 10, z: 1 },
color: colors.overalls,
stroke: 20,
addTo: illo,
});
// right arm
var rightShoulder = { x: -8, y: -8, z: -3 };
var rightWrist = new Zdog.Vector({ x: -14, y: -17, z: -0 });
new Zdog.Shape({
path: [
rightShoulder,
rightWrist,
],
color: colors.cloth,
stroke: 8,
addTo: body,
});
// right hand
new Zdog.Shape({
path: [
{ x: -17, y: -23, z: 1 },
],
color: colors.white,
stroke: 12,
addTo: body,
});
// left arm
var leftShoulder = { x: 6, y: -7, z: -4 };
var leftElbow = { x: 8, y: -4, z: -8 };
new Zdog.Shape({
path: [
leftShoulder,
leftElbow,
],
color: colors.cloth,
stroke: 8,
addTo: body,
});
new Zdog.Shape({
path: [
leftElbow,
{ x: 12, y: -2, z: -9 },
],
color: colors.cloth,
stroke: 8,
addTo: body,
});
// left hand
new Zdog.Shape({
path: [
{ x: 17, y: 1, z: -8 },
],
color: colors.white,
stroke: 12,
addTo: body,
});
new Zdog.Shape({
path: [
leftShoulder,
rightShoulder,
],
color: colors.cloth,
stroke: 8,
addTo: body,
});
// right leg
var rightLeg = new Zdog.Shape({
path: [
{ y: 4, z: 2 },
{ y: 10, z: 1 },
{ y: 12, z: -0 }
],
translate: { x: -5 },
closed: false,
color: colors.overalls,
stroke: 10,
addTo: body,
});
var shoe = new Zdog.Rect({
addTo: rightLeg,
width: 4,
height: 7,
translate: { y: 15.5, z: -4 },
fill: true,
color: colors.leather,
stroke: 6,
});
// toe ball
new Zdog.Shape({
addTo: shoe,
translate: { y: 3, z: 2.5 },
color: colors.leather,
stroke: 11,
});
// left leg
var leftLeg = new Zdog.Shape({
path: [
{ y: 4, z: 2 },
{ y: 2, z: 7 },
{ y: 3, z: 11 },
],
translate: { x: 5 },
closed: false,
color: colors.overalls,
stroke: 10,
addTo: body,
});
shoe.copyGraph({
addTo: leftLeg,
translate: { y: 2, z: 18 },
rotate: { x: TAU * (160/360) },
});
// -- animate --- //
function animate() {
illo.rotate.y += isSpinning ? -0.05 : 0;
illo.updateRenderGraph();
requestAnimationFrame( animate );
}
animate();
Also see: Tab Triggers