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.
<!-- Learning Pure CSS Art by making "Koala" by following mikemang's tutorial -->
<body>
<!-- Begin Image -->
<!-- Invisible Box-->
<div class="box"> <!-- No closing div tag until near the end -->
<!--Circular Head-->
<div class="head">
<!-- Nested divs:
All other shapes will be on top of the
head-->
<!-- Circular Head Copy -->
<!-- used to allow the ears to appear
behind the head -->
<div class="head-copy"></div>
<!--Left Ear ~ Light Gray -->
<div class="ear-left">
<!-- Inner ear ~ Dark Gray -->
<div class="inner-ear"></div> <!-- Closing div tag of Left ear -->
</div>
<!-- Nested divs:
Ear-right is the parent div; inner-ear is a child div; percentage for widths and
heights of shapes applies to parent div -->
<!-- Right Ear ~ Light Gray -->
<div class="ear-right">
<!-- Inner Ear ~ Dark Dray -->
<div class="inner-ear"></div>
</div>
<!-- Left Outer Eye ~ White -->
<div class="eye-left">
<!-- Pupil ~ Black -->
<div class="pupil"></div>
</div>
<!-- Right Outer Eye ~ White -->
<div class="eye-right">
<!-- Pupil ~ Black -->
<div class="pupil"></div>
</div>
<!-- Nose ~ Brown -->
<div class="nose">
</div>
<!-- Challenge: Add Mouth ~ Coral -->
<div class="mouth"></div>
<!--Challenge: Add Tongue ~ Red -->
<div class="tongue"></div>
<!-- Hair ~ Light Gray -->
<div class="hair-left"></div>
<div class="hair-right"></div>
<!-- End Head -->
</div>
<!-- End Invisibile Box -->
</div>
</body>
<!-- Check understanding of:
<div>, position property, top, percentage -->
<!--
<div> element: generic container for flow content; doesn't inherently represent anything; used to group element for styling (using class or id attribute), marking a section of a document in a different language (using lang attribute), etc.
flow content: elements in this catebory contain text or embedded content. See MDN for the whole list.
position property: specifies the type of positioning method used for an element (static, relative, fixed, absolute, sticky); elements are then positioned using the top, bottom, left, and right properites -- set position property first.
position: absolute
{the element with this property is positioned relative to the nearest positioned ancestor; if element has no positioned ancestors, it uses the document body and moves along with page scrolling}
-->
body {
background: #25A9FC;
}
.box {
position: relative;
margin: auto;
display: block;
margin-top: 10%;
width: 600px;
height: 420px;
background: none;
border: solid 4px red;
}
/* position: relative -- the element is positioned relative to its normal position, which is the very top left corner
$ margin: auto centers the box
$ margin-top: 8% lowers the box by 8%
$ margin: auto was not overwritten
*/
.head {
position: absolute;
top: 16.5%;
left: 25%;
width: 50%;
height: 67%;
background: #A6BECF;
border-radius: 50%;
}
/* Position percentages to ABSOLUTELY CENTER:
left = (100 - width of parent div)/2
top = (100 - height of parent div)/2
*/
.head-copy {
width: 100%;
height: 100%;
/* head-copy's parent div is head; it will be positioned and measured
relative to head */
position: absolute;
/* significance of width and height at 100% and before position: absolute? */
background: #A6BECF;
border-radius: 50%;
z-index: 2;
}
/*
$ z-index indicates the depth of the div (think layers) ; the highter the z-index, the closer that div is to the top. Example:
Have 2 divs. z-index: 1 would be like the bottom layer; z-index: 2 would be the top layer.
$ ears will the bottom layer and will have z-index: 1
$ giving head div a value of z-index: 2 won't put the ears behind the head - WHY?
$ giving head-copy div a vlue of z-index: 2 will put ears behind the head
*/
.ear-left{
position: absolute;
width: 60%;
height: 65%;
left: -20%;
/* negative sign: shift in the specified direction */
top: 5%;
background: #A6BECF;
border-radius: 50%;
z-index: 1;
}
.ear-right{
position: absolute;
width: 60%;
height: 65%;
right: -20%;
top: 5%;
background: #A6BECF;
border-radius: 50%;
z-index: 1;
}
/* inner-ear's parent div is ear-left and ear-right*/
.inner-ear{
position: absolute;
border-radius: 50%;
width: 80%;
height: 80%;
top: 10%;
left: 10%;
/* top and left are relative to the ears */
background: #819CAF;
}
/*parent div is head */
.eye-left {
position: absolute;
border-radius: 50%;
width: 30%;
height: 33%;
top: 25%;
left: 21%;
background: white;
z-index: 3;
}
/*parent div is head */
.eye-right {
position: absolute;
border-radius: 50%;
width: 30%;
height: 33%;
top: 25%;
right: 21%;
/* original position is at the top left corner of head. And no right property applied does not mean right: 100% (which is not the maximum furthest distance)
$default right: percentage is at top left corner of parent div */
background: white;
z-index: 2;
}
.pupil {
position: absolute;
width: 28%;
height: 30%;
top: 35%;
left: 36%;
border-radius: 50%;
background: #27354A;
}
.nose {
position: absolute;
background: #BE845F;
width: 25%;
height: 40%;
left: 37%;
top: 45%;
border-radius: 50px; /* round the corners of the rectangle - when rounding slightly, easier to use px instead of percentage. */
z-index: 4; /*on top of eyes */
}
.mouth{
position: absolute;
background: #F08080;
width: 40%;
height: 22%;
left: 30%;
top: 70%;
z-index: 3;
border-radius: 50%;
}
/*parent div of tongue div is mouth div*/
.tongue {
position: absolute;
background: red;
border-radius: 50%;
width: 29%;
height: 30%;
left: 35%;
top: 65%;
z-index: 3;
}
.hair-left {
position: absolute;
top: -8%; /*to stick out above head */
left: 30%;
width: 20%;
height: 20%;
background: #A6BECF;
-webkit-clip-path: polygon (50% 0%, 0% 100%, 100% 100%);
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.hair-right{
position: absolute;
top: -4%; /* to stick out above head */
left: 48%;
width: 20%;
height: 20%;
background: #A6BECF;
-webkit-clip-path: polygon(50% 0%, 0% 100%, 100% 100%); clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
/*clip-path used to make any shape outside a square, rectangle, and circle. This method is supported by Safari, Chrome, and Opera, but not Firefox.
$ the tool called Clippy automatically gives us the clip-path for different shapes */
Also see: Tab Triggers