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.
- let stars = 7
- let i = 0
.rating(style=`--stars: ${stars}`)
.ratings
.rating__blank
while i < stars
span.star
- i++
- i = 0
.rating__people
while i < stars
span.star
- i++
- i = stars
.rating__you
while i > 0
input(type="radio" class="star" name="rating" this.value=`${i--}`)/
// I needed the line below to fix a weird white-space issue
span(style="margin: -.14em;")
<input type="radio" class="btn" name="rating" value="0" />
:root {
--stars: 'see html editor'; /* How many stars are there */
--votes: 20; /* How many people have voted? */
--score: 70; /* ...out of (stars * votes) */
}
body {
font-family: "Helvetica";
font-size: 62.5%;
}
input {
font-family: inherit;
}
/*
.rating Contains .ratings, which contains .rating__blank, .rating__people, and .rating__you
.ratings Acts as a cosmetic container for all the different ratings.
I needed it to help me give the stars some space away from the .rating's border.
Plus, if I simply tried to modify .rating's padding, .rating__people's content width would act up and display a bit of shading despite the lack of a score (if --score were to be set to 0).
.star Star Icon styling which houses the shade and the outline.
.star:before Star Shade
.star:after Star Outline
.rating__blank The first/base layer.
This is what will give the .rating bar shape as the other .rating__* elements will be absolutely positioned as well as positioned over the base.
.rating__people All the stars within this element are already shaded.
The magic comes from the overflow property being set to hidden as well as the width that gets readjusted based on the voting --score being calculated against the number of --votes multiplied by the number of --stars.
.rating__you The final layer as well as the most interactive aspect of the rating system.
All of the .star elements within it are radio buttons instead of span tags.
The yellow outlined stars highlight your current rating whereas the yellow shaded stars highlight the rating you want to give it.
*/
.rating {
background-color: #7bf;
border: 4px solid #0003;
border-radius: 32px;
display: inline-block;
overflow: hidden;
position: relative;
vertical-align: middle;
&s {
margin: 8px 16px;
position: relative;
}
& .star {
/* General Rating Star styles */
appearance: none;
box-sizing: border-box;
font-family: FontAwesome;
font-size: 3em;
margin: 0 -.1em;
position: relative;
&:before, &:after {
display: inline-block;
padding: .05em .15em;
vertical-align: top;
transition: all .25s;
}
&:before {
/* Filled Star icon */
content: "\f005";
position: relative;
}
&:after {
/* Outline Star icon */
content: "\f006";
position: absolute;
top: 0;
left: 0;
}
}
&__blank, &__people, &__you {
box-sizing: border-box;
white-space: nowrap;
transition: all 1s;
}
&__people, &__you {
position: absolute;
top: 0;
left: 0;
right: 0;
}
/* The base. Basically layer 0. */
&__blank {
& .star:before {
color: #ddd;
-webkit-text-stroke: 1px #000;
}
& .star:after {
color: #0003;
}
}
/* The people's votes. Layer 1. */
&__people {
width: calc(100% * (var(--score) / (var(--votes) * var(--stars))));
overflow: hidden;
& .star:before {
color: #39f;
}
& .star:after {
color: #0003;
}
}
/* Your vote. Layer 2. */
&__you {
/*
The following property was necessary to rearrange the radio button values from 1-5
as the radio buttons within the HTML was ordered from 5 to 1 in order to make use of
the CSS combinators without much issue.
You can comment/take out the direction property to see how this really works.
*/
direction: rtl;
& .star {
cursor: pointer;
&:before, &:after { opacity: 0; }
/* When you hover over a star, the hovered star along with the stars preceding it starts to highlight */
&:before {
color: #fc0;
text-shadow: 0px 0px 1px #000;
}
&:hover ~ .star, &:hover {
&:before { opacity: 1; }
}
/* When a rating is selected, you will see a yellow outline of a star along with a subtle dark stroke which will inform you which rating you picked */
&:after {
color: #ff0;
-webkit-text-stroke: .025em #0006;
}
&:checked ~ .star, &:checked {
&:after { opacity: 1; }
}
}
}
}
/* Clear Rating button */
.btn {
appearance: none;
background-color: #eee;
border-radius: 32px;
box-shadow: inset 0 0 0 1px #0003, inset 0 3px #fff6;
cursor: pointer;
display: inline-block;
margin-top: 8px;
padding: .4em .8em;
font-size: 1.25em;
transition: all .2s;
outline: none;
vertical-align: middle;
&:hover, &:focus { background-color: #fff; }
&:active { background-color: #ddd; }
&:after { content: "Clear Rating"; }
}
/* Rating Info box */
.info {
border-top: 1px solid #0001;
margin-top: 8px;
padding: 1em;
.num:before {
content: "???";
}
#rating_ {
¤t:before {
counter-reset: num var(--score);
content: counter(num);
}
&max:before {
counter-reset: num var(--score_max);
content: counter(num);
}
&percent:before {
counter-reset: num var(--a);
content: counter(num);
}
&votes:before {
counter-reset: num var(--votes);
content: counter(num);
}
}
}
Also see: Tab Triggers