Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

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.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <h1>Percentage based star rating</h1>
<p>With Font Awesome</p>
<div class="star-rating" title="70%">
    <div class="back-stars">
        <i class="fa fa-star" aria-hidden="true"></i>
        <i class="fa fa-star" aria-hidden="true"></i>
        <i class="fa fa-star" aria-hidden="true"></i>
        <i class="fa fa-star" aria-hidden="true"></i>
        <i class="fa fa-star" aria-hidden="true"></i>
        
        <div class="front-stars" style="width: 70%">
            <i class="fa fa-star" aria-hidden="true"></i>
            <i class="fa fa-star" aria-hidden="true"></i>
            <i class="fa fa-star" aria-hidden="true"></i>
            <i class="fa fa-star" aria-hidden="true"></i>
            <i class="fa fa-star" aria-hidden="true"></i>
        </div>
    </div>
</div>    

<input type="number" value="70" max="100" min="0"><span class="percent">%</span>
              
            
!

CSS

              
                /*---------- general ----------*/
body {
    background: #ff7070;
    color: #F3FCF0;
    font-family: sans-serif;
    text-align: center;
}
h1 {
    font-family: 'Raleway', sans-serif;
    text-shadow: 2px 2px 0 #843a3a;
    text-transform: uppercase;
    
}
p {
    font-size: 1.3em;
}

/*---------- star rating ----------*/
%flex-display {
    display: flex;
}
.star-rating {
    @extend %flex-display;
    align-items: center;
    font-size: 3em;
    justify-content: center;
    margin-top: 50px;
}
.back-stars {
    @extend %flex-display;
    color: #bb5252;
    position: relative;
    text-shadow: 4px 4px 10px #843a3a;
}
.front-stars {
    @extend %flex-display;
    color: #FFBC0B;
    overflow: hidden;
    position: absolute;
    text-shadow: 2px 2px 5px #d29b09;
    top: 0;
    transition: all .5s
}

input {
    background: transparent;
    border: solid 2px #bb5252;
    color: #fff;
    font-size: 1.5em;
    height: 50px;
    width: 60px;
    text-align: center;
    margin-top: 50px;
    margin-right: 10px;
    
    &:focus {
        outline: none;
    }    
}

.percent {
    color: #bb5252;
    font-size: 1.5em;
}
              
            
!

JS

              
                // I was working on a personal recipes website and wanted to add a simple percentage based star rating using Font Awesome icons. It needed to work in a way that I could add the rating percentage for each recipe to the html and make it reflect in the stars. 

// I searched the web and could only find star ratings that the user would be clicking in the stars to give their own rating, or the rating didn't use font awesome.

const numberInput = document.querySelector('input');
const starRatingWrapper = document.querySelector('.star-rating');
const frontStars =  document.querySelector('.front-stars');

const rate = e => {
    const percentage = e.target.value + '%';
    
    starRatingWrapper.title = percentage;
    frontStars.style.width = percentage;
};

numberInput.addEventListener('click', rate);
numberInput.addEventListener('keyup', rate);
              
            
!
999px

Console