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.
<div class="part">
<p>Display only:</p>
<div class="stars" data-percent="10"></div><br>
<div class="stars" data-percent="40"></div><br>
<div class="stars" data-percent="90"></div><br>
</div>
<div class="part">
<p>With user interaction:</p>
<div class="stars rate" data-percent="30"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
<div class="stars rate" data-percent="50"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
<div class="stars rate" data-percent="80"><a href="?1" title="awful">★</a><a href="?2" title="ok">★</a><a href="?3" title="good">★</a><a href="?4" title="great">★</a><a href="?5" title="awesome">★</a></div><br>
</div>
/*
ignore this. it's just used to put the two example panels next to each other.
*/
.part {
float:left;
margin:0 5px;
}
/*
start by styling the box around the star.
the only important parts are display and width, which force the container to constrain to the star widths. Note that using padding is problematic and unadvised.
*/
.stars {
display:inline-block;
width:auto;
position:relative;
font-size:28px;
border:2px outset #FC0;
border-radius:5px;
background-color:navy;
margin:5px;
}
/*
the BEFORE:pseudo element. This will represent the number of stars in the actual rating.
it floats above the AFTER element.
*/
.stars:BEFORE {
content:"★★★★★";
position:absolute;
overflow:hidden;
z-index:1;
left:0px;
top:0px;
/* everything below here is optional. */
color:#FC0;
text-shadow:0px 1px 0 #000, 0 -1px 0 #fff;
}
/*
the AFTER:pseudo element. This will represent the total possible stars available. It is set to relative to ensure it takes up the proper amount of space.
*/
.stars:AFTER {
content:"★★★★★";
position:relative;
color:#fff;
}
/*
if including user rating controls, float the AFTER element.
*/
.stars.rate:AFTER {
position:absolute;
left:0px;
}
/*
default state for the user rating controls. invisible, but floating above the BEFORE and AFTER elements
*/
.stars.rate > A {
color:transparent;
text-decoration:none;
position:relative;
z-index:2;
}
/*
if the user is floating thier mouse above the rating, hide the display stars.
*/
.stars.rate:HOVER:BEFORE,
.stars.rate:HOVER:AFTER {
display:none;
}
/*
turn all sthe start "ON" by default.
*/
.stars.rate:HOVER > A {
color:#FC0;
text-shadow:0px 1px 0 #000, 0 -1px 0 #fff;
}
/*
optional style for the specific star control a user is directly above.
*/
.stars.rate:HOVER > A:HOVER {
color:#FC0;
text-shadow:0px 2px 0 #000, 0 -1px 0 #fff;
top:-1px;
}
/*
turn "OFF" all stars after the one the user is hovering over.
*/
.stars.rate >A:HOVER ~ A {
color:#fff;
text-shadow:none;
}
/*
all the styles below are used to display the apropriate portion of the BEFORE element based on percentage rating. unfortunately you will need to create a specific rule for each level of granularity you wish to display.
if the CSS3 attr() function proposal ever gets implimented
the remaining rules could all be replaced with the following:
.stars[data-percent]:BEFORE {
width:attr(data-percent,%,0);
}
*/
.stars:NOT([data-percent]):BEFORE,
.stars[data-percent="0"]:BEFORE {
display:none;
}
/* 1/2 a star */
.stars[data-percent="10"]:BEFORE {
width:10%;
}
/* 1 star */
.stars[data-percent="20"]:BEFORE {
width:20%;
}
/* 1 & 1/2 stars */
.stars[data-percent="30"]:BEFORE {
width:30%;
}
/* etc. */
.stars[data-percent="40"]:BEFORE {
width:40%;
}
.stars[data-percent="50"]:BEFORE {
width:50%;
}
.stars[data-percent="60"]:BEFORE {
width:60%;
}
.stars[data-percent="70"]:BEFORE {
width:70%;
}
.stars[data-percent="80"]:BEFORE {
width:80%;
}
.stars[data-percent="90"]:BEFORE {
width:90%;
}
.stars[data-percent="100"]:BEFORE {
width:100%;
}
Also see: Tab Triggers