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.
nav(class='rating')
ul
each number, i in [1, 2, 3, 4, 5]
- var cls = ''
- if(i == 0)
- cls = 'current'
li(class=cls)
- if(number >= 4)
span
svg
use(xlink:href='#star')
div
span
svg
use(xlink:href='#star')
svg(xmlns='http://www.w3.org/2000/svg' style='display: none')
symbol(xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 34' id='star')
path(fill='currentColor' d='M19.6859343,0.861782958 L24.8136328,8.05088572 C25.0669318,8.40601432 25.4299179,8.6717536 25.8489524,8.80883508 L34.592052,11.6690221 C35.6704701,12.021812 36.2532905,13.1657829 35.8938178,14.2241526 C35.8056709,14.4836775 35.6647294,14.7229267 35.4795411,14.9273903 L29.901129,21.0864353 C29.5299163,21.4962859 29.3444371,22.0366367 29.3872912,22.5833831 L30.1116131,31.8245163 C30.1987981,32.9368499 29.3506698,33.9079379 28.2172657,33.993502 C27.9437428,34.0141511 27.6687736,33.9809301 27.4085205,33.8957918 L18.6506147,31.0307612 C18.2281197,30.8925477 17.7713439,30.8925477 17.3488489,31.0307612 L8.59094317,33.8957918 C7.51252508,34.2485817 6.34688429,33.6765963 5.98741159,32.6182265 C5.90066055,32.3628116 5.86681029,32.0929542 5.88785051,31.8245163 L6.61217242,22.5833831 C6.65502653,22.0366367 6.46954737,21.4962859 6.09833466,21.0864353 L0.519922484,14.9273903 C-0.235294755,14.0935658 -0.158766688,12.8167745 0.690852706,12.0755971 C0.899189467,11.8938516 1.14297067,11.7555303 1.40741159,11.6690221 L10.1505113,8.80883508 C10.5695458,8.6717536 10.9325319,8.40601432 11.1858308,8.05088572 L16.3135293,0.861782958 C16.9654141,-0.0521682813 18.2488096,-0.274439442 19.1800736,0.365326425 C19.3769294,0.500563797 19.5481352,0.668586713 19.6859343,0.861782958 Z')
path(class='shadow' d='M18.7022469,29.7633426 L29.1611722,33.6861584 C28.8859085,33.8576358 28.5650147,33.9672494 28.2172657,33.993502 C27.9437428,34.0141511 27.6687736,33.9809301 27.4085205,33.8957918 L18.6506147,31.0307612 C18.2281197,30.8925477 17.7713439,30.8925477 17.3488489,31.0307612 L8.59094317,33.8957918 C7.98083887,34.0953792 7.34281791,33.9989813 6.83864817,33.6859784 L17.2977531,29.7633426 C17.7505234,29.5935537 18.2494766,29.5935537 18.7022469,29.7633426 Z')
a(class='dribbble' href='https://dribbble.com/shots/7170398-Stars-rating-animation' target='_blank')
img(src='https://dribbble.com/assets/logo-small-2x-9fe74d2ad7b25fba0f50168523c15fda4c35534f9ea0b1011179275383035439.png')
.rating {
--active: #FFED76;
--active-pale: rgba(255, 237, 118, .36);
--inactive: #121621;
--face-active: #121621;
--face-inactive: #1C212E;
display: flex;
position: relative;
ul {
margin: 0;
padding: 0;
list-style: none;
display: flex;
color: var(--inactive);
li {
--face: var(--face-inactive);
cursor: pointer;
position: relative;
&:before,
&:after {
content: '';
position: absolute;
z-index: 2;
transition: all .2s ease;
}
&:before {
--r: 0deg;
width: 2px;
height: 2px;
border-radius: 1px;
top: 15px;
left: 13px;
transform: rotate(var(--r));
filter: drop-shadow(8px 0 0 var(--face));
}
span {
width: 2px;
height: 2px;
display: block;
position: absolute;
left: 50%;
top: 50%;
border-radius: 50%;
margin: -1px 0 0 -1px;
transform: scale(.6);
opacity: 0;
box-shadow: 16px -16px 0 var(--active-pale), -16px -16px 0 var(--active-pale), -21px 8px 0 var(--active-pale), 21px 8px 0 var(--active-pale), 0 22px 0 var(--active-pale);
}
&:nth-child(1) {
&:after {
width: 10px;
height: 10px;
top: 20px;
left: 13px;
border-radius: 50%;
border: 1px solid transparent;
border-top-color: var(--face);
}
}
&:nth-child(3) {
&:after {
width: 6px;
left: 15px;
top: 20px;
height: 1px;
background: var(--face);
}
}
&:nth-child(4) {
&:after {
width: 10px;
height: 10px;
top: 12px;
left: 13px;
border-radius: 50%;
border: 1px solid transparent;
border-bottom-color: var(--face);
}
&.current {
animation: active-4 .4s ease;
span {
animation: active-span .32s ease;
}
}
}
&:nth-child(5) {
&:after {
width: 6px;
height: 3px;
left: 15px;
top: 20px;
border-radius: 0 0 3px 3px;
background: var(--face);
}
&.current {
animation: active-5 .72s ease;
span {
animation: active-span .32s ease;
}
}
}
&.current {
--face: var(--face-active);
svg {
color: var(--active);
fill: rgba(0, 0, 0, .2);
}
}
&:not(.current) {
svg {
transition: transform .2s ease;
}
&:active {
svg {
transform: scale(.9);
}
}
}
&:not(:last-child) {
margin: 0 16px 0 0;
&:before {
background: var(--face);
}
&.current {
&:before {
animation: blink 3s linear infinite;
}
}
}
&:last-child {
&:before {
--r: -45deg;
width: 3px;
height: 3px;
border-top: 1px solid var(--face);
border-right: 1px solid var(--face);
border-radius: 0 1px 0 0;
left: 12px;
filter: drop-shadow(6px 6px 0 var(--face));
}
}
}
}
svg {
width: 36px;
height: 34px;
display: block;
fill: rgba(0, 0, 0, .04);
}
& > div {
left: 0;
top: 0;
position: absolute;
display: none;
transform: translateX(var(--x));
transition: transform .3s cubic-bezier(0, 0, 0.265, 1.1) .24s;
span {
display: block;
svg {
color: var(--active);
fill: rgba(0, 0, 0, .2);
}
}
}
&.animate-left,
&.animate-right {
& > div {
display: block;
span {
animation: scale .28s linear .24s;
}
}
}
&.animate-left {
li {
&.move-to {
&:before {
animation: move-to-left .31s ease .36s;
}
}
&.move-from {
&:before {
animation: move-to-right .28s ease;
}
}
}
& > div {
animation: double-left .32s linear .24s;
span {
svg {
animation: left .3s ease, right-end .4s ease .4s;
}
}
}
}
&.animate-right {
li {
&.move-to {
&:before {
animation: move-to-right .31s ease .36s;
}
}
&.move-from {
&:before {
animation: move-to-left .28s ease;
}
}
}
& > div {
animation: double-right .32s linear .24s;
span {
svg {
animation: right .3s ease, left-end .4s ease .4s;
}
}
}
}
}
@keyframes active-4 {
40% {
transform: scale(1.25);
}
}
@keyframes active-span {
60% {
opacity: 1;
}
100% {
transform: scale(1.16);
opacity: 0;
}
}
@keyframes active-5 {
15% {
transform: rotate(180deg) scale(1.1);
}
30% {
transform: rotate(360deg) scale(1.2);
}
70% {
transform: rotate(360deg) translateY(14%) scaleY(.72);
}
100% {
transform: rotate(360deg);
}
}
@keyframes double-right {
60% {
filter: drop-shadow(-5px 0 1px var(--active-pale)) drop-shadow(4px 0 1px var(--active-pale));
}
}
@keyframes scale {
60% {
transform: scaleX(1.32);
filter: blur(.5px);
}
}
@keyframes blink {
0%,
5%,
15%,
100% {
transform: scaleY(1);
}
10% {
transform: scaleY(.4);
}
}
@keyframes double-left {
60% {
filter: drop-shadow(5px 0 1px var(--active-pale)) drop-shadow(-4px 0 1px var(--active-pale));
}
}
@keyframes right {
0%,
100% {
transform-origin: 17% 100%;
}
50% {
transform: rotate(-12deg) skewX(12deg);
}
}
@keyframes left {
0%,
100% {
transform-origin: 83% 100%;
}
50% {
transform: rotate(12deg) skewX(-12deg);
}
}
@keyframes right-end {
0%,
100% {
transform-origin: 17% 100%;
}
40% {
transform: rotate(-6deg) skewX(4deg) scaleX(.92);
}
70% {
transform: rotate(1deg) skewX(-8deg) scaleX(1.04);
}
}
@keyframes left-end {
0%,
100% {
transform-origin: 83% 100%;
}
40% {
transform: rotate(6deg) skewX(-4deg) scaleX(.92);
}
70% {
transform: rotate(-1deg) skewX(8deg) scaleX(1.04);
}
}
@keyframes move-to-right {
40% {
transform: translateX(3px) rotate(var(--r));
}
}
@keyframes move-to-left {
40% {
transform: translateX(-3px) rotate(var(--r));
}
}
html {
box-sizing: border-box;
-webkit-font-smoothing: antialiased;
}
* {
box-sizing: inherit;
&:before,
&:after {
box-sizing: inherit;
}
}
// Center & dribbble
body {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: #1C212E;
.dribbble {
position: fixed;
display: block;
right: 24px;
bottom: 24px;
img {
display: block;
width: 76px;
}
}
}
$('.rating ul li').on('click', function() {
let li = $(this),
ul = li.parent(),
rating = ul.parent(),
last = ul.find('.current');
if(!rating.hasClass('animate-left') && !rating.hasClass('animate-right')) {
last.removeClass('current');
ul.children('li').each(function() {
let current = $(this);
current.toggleClass('active', li.index() > current.index());
});
rating.addClass(li.index() > last.index() ? 'animate-right' : 'animate-left');
rating.css({
'--x': li.position().left + 'px'
});
li.addClass('move-to');
last.addClass('move-from');
setTimeout(() => {
li.addClass('current');
li.removeClass('move-to');
last.removeClass('move-from');
rating.removeClass('animate-left animate-right');
}, 800);
}
})
Also see: Tab Triggers