Creating CSS Star Rating Widget without javascript

| Page Views: 204

Pure HTML CSS Star Rating System Implementation Tutorial

In this tutorial we want to see how you can implement a star rating widget in pure html and css without any javascript library.


In many types of sites these days, there is always a need to provide interactivity. User retention increases and bounce rate goes down in interactive sites. One of the best ways to provide users with opportunities for interactivity is to allow them to rate content. This also provides you with valuable feedback and that's why we have emoticons in our site.

However in this class we want to see how we can implement interactivity via star rating widgets. We don't want to use third party libaries or javascript, instead we create it in pure HTML and CSS

Let's go.

Video Tutorial

You can view the video tutorial below:

It is just a single index.html file with css inlined.

<!doctype html>

    <title>Star Rating - Pure CSS</title>
    <!-- We need to load font awesome to show our star icons. -->
    <link rel="stylesheet" 

        /* Let's define an import rule at the top. @import allows you to import
        a stylesheet into another */
        @import url(,100,300,700,400);

        * {
            margin: 0;
            padding: 0;
            font-family: roboto;

        body {
            background: #009968;
        /* Select all class movie_item */
        .movie_item {
            width: 93%;
            max-width: 350px;
            text-align: center;
            margin: 4% auto;
            padding: 30px 0;
            background: #111;
            color: #EEE;
            border-radius: 5px;
            border: thin solid #444;
            overflow: hidden; /* overflow controls what happens to content 
            larger than specified area */

        /* Let's define title class' properties.It's contained in a div element */
        div.title {
            font-size: 2em;

        /* Let's define stars class' properties.It's contained in a div element */
        div.stars {
            width: 270px;
            display: inline-block;
        /* Let's define star css class properties.It's contained in an input element */ {
            display: none;
        } {
            float: right;
            padding: 10px;
            font-size: 36px;
            color: #444;
            transition: all .2s; /* provide a way to control animation speed when
            changing CSS properties*/
        } { /* checked is a property of radiobuttons
        and checkboxes */
            content: '\f005';
            color: #FD4;
            transition: all .25s;
        } {/*If you are wondering what ~ means it
        means preceds. Left precedes right. */
            color: #FE7;
            text-shadow: 0 0 20px #952;
        } {
            color: #F62;
        } {
            transform: rotate(-15deg) scale(1.3);
        } {
            content: '\f006';
            font-family: FontAwesome;

    <!-- Let's now define two movie items -->
    <div class="movie_item" style="margin-top:100px;">
        <div class="title">
            <h3>Star Wars - Attack of the Clones</h3>
        <div class="stars">
            <form action="">
                <input class="star star-5" id="star-5" type="radio" name="star" />
                <label class="star star-5" for="star-5"></label>
                <input class="star star-4" id="star-4" type="radio" name="star" />
                <label class="star star-4" for="star-4"></label>
                <input class="star star-3" id="star-3" type="radio" name="star" />
                <label class="star star-3" for="star-3"></label>
                <input class="star star-2" id="star-2" type="radio" name="star" />
                <label class="star star-2" for="star-2"></label>
                <input class="star star-1" id="star-1" type="radio" name="star" />
                <label class="star star-1" for="star-1"></label>
        <p>Please rate the Movies for us</p>
    <div class="movie_item">
        <div class="title">
            <h3>Stranger Things - Season 2</h3>
        <div class="stars">
            <form action="">
                <input class="star star-5" id="s_things_5" type="radio" name="star" />
                <label class="star star-5" for="s_things_5"></label>
                <input class="star star-4" id="s_things_4" type="radio" name="star" />
                <label class="star star-4" for="s_things_4"></label>
                <input class="star star-3" id="s_things_3" type="radio" name="star" />
                <label class="star star-3" for="s_things_3"></label>
                <input class="star star-2" id="s_things_2" type="radio" name="star" />
                <label class="star star-2" for="s_things_2"></label>
                <input class="star star-1" id="s_things_1" type="radio" name="star" />
                <label class="star star-1" for="s_things_1"></label>
        <p>Select a Rating for this show</p>


Codepen Demo

See the Pen Pure CSS Star Rating System by Oclemy (@Oclemy) on CodePen.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section.

About Me.

After completing his Software Engineering bachelors program, Oclemy(Clement Ochieng) these days is a man of two lives. At day he works for a startup in Nairobi, Kenya. At night he works tirelessly on building ProgrammingWizards TV, a tv channel for student coders and this website to help share the source code. In between he practices Meditation and Self actualization to help him keep balance. He also likes going for long solo walks to connect more with nature.


What do You Think

Previous Post Next Post