Display Star in Front End based on rating

5 star rating javascript
percentage based star ratings
bootstrap star rating
star rating w3schools
half star rating css
javascript star rating
css star rating display
turn a number into star rating display using css

I have created a field in backend where using radio button am selecting the rating of product as 1 star, 2 star, 3 star, 4 star and 5 Star

In front end when displaying same

<p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $this->prodDet->v_child_safety?></p>

It displays the rating in numeric form as - 1 star, 2 star, 3 star, 4 star and 5 Star

Can any one guide on the best way to have front end display a Star like rating instead of numeric value without making the page load slow

This is not duplicate I just want users to view star type rating in front end They can not modify rating or add a rating, its just that the administrator assigns a rating as 1 star to 5 star and its viewable in the front end Now instead of numeric value as 2 star or 3 star i want stars to be displayed in


First, make sure $this->prodDet->v_child_safety only returns a number. So instead of 1 star, 2 star, it should just return 1, 2, 3 etc. Then replace your code with this:


$stars = (int)$this->prodDet->v_child_safety;
$count = 1;
$result = "";

for($i = 1; $i <= 5; $i++){
    if($stars >= $count){
        $result .= "<span>&#x2605</span>";
    } else {
        $result .= "<span>&#x2606</span>";
<p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $result?></p>

If you want to use images of a star instead, use this code:


$stars = (int)$this->prodDet->v_child_safety;
$result = "";

for($i = 1; $i <= $stars; $i++){
    $result .= "<img src='link_to_image_here.png'/>";
<p class="tool-tip"><a href="#" onMouseover="ddrivetip('Expert Rating')"; onMouseout="hideddrivetip()">Expert Rating</a> - <?php echo $result?></p>

Star Ratings With Very Little CSS, Here's a much newer article: Five Methods for Five-Star Ratings, although it doesn't cover this exact Learn Development at Frontend Masters .rating { unicode-bidi: bidi-override; direction: rtl; } .rating > span { display: inline-block; position:  Pure CSS Star Rating. Star ratings made with pure css. Stars will highlight on hover and you can also click on the star rating and display that rating. Made form input fields so the form can be processed. Compatible browsers: Chrome, Edge, Firefox, Opera, Safari. Dependencies: -

This solution uses hidden radio buttons. The label is presented as a star thanks to fontAwesome. The value of the star can be sent to your PHP script or you can set the correct star based on any value you have.

input[type="radio"] {
  display: none;

label {
  display: inline-block;

input[type="radio"]:checked+label {
  cursor: default;
  color: red;
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
  <input id="star1" name="star" type="radio">
  <label for="star1"><i class="fa fa-star"></i></label>
  <input id="star2" name="star" type="radio">
  <label for="star2"><i class="fa fa-star"></i></label>
  <input id="star3" name="star" type="radio" checked>
  <label for="star3"><i class="fa fa-star"></i></label>
<!-- Use <?php echo("checked") ?> to set the correct star -->
  <input id="star4" name="star" type="radio">
  <label for="star4"><i class="fa fa-star"></i></label>
  <input id="star5" name="star" type="radio">
  <label for="star5"><i class="fa fa-star"></i></label>

Five Methods for Five-Star Ratings, Learn Development at Frontend Masters and relevant for the long haul, so we should base our decisions on consistent, stable tooling. additional events before displaying the stars: That would be (1) the CSS to download,  Chances are, JavaScript is going to be involved with rating stars anyway. When a user clicks a star, the rating is reported back via Ajax, and the widget itself gains a class to permanently display their selected number of stars.

Use below condition in each input:

<?php if($this->prodDet->v_child_safety=="1 star"){?>checked="checked"<?php } ?>

and use disabled to disable all input so that no one can change value if you just want to display rating.

div.stars {
  width: 270px;
  display: inline-block;

input.star { display: none; }

label.star {
  float: right;
  padding: 10px;
  font-size: 36px;
  color: #444;
  transition: all .2s;

input.star:checked ~ label.star:before {
  content: '\2605';
  color: #FD4;
  transition: all .25s;

input.star-5:checked ~ label.star:before {
  color: #FE7;
  text-shadow: 0 0 20px #952;

input.star-1:checked ~ label.star:before { color: #F62; }

label.star:hover { transform: rotate(-15deg) scale(1.3); }

label.star:before {
  content: '\2605';
<p class="tool-tip"><a href="#">Expert Rating</a>
<div class="stars">
<input disabled class="star star-5" id="star-5" type="radio" name="star"/>
    <label class="star star-5" for="star-5"></label>
    <input disabled class="star star-4" id="star-4" type="radio" name="star" />
    <label class="star star-4" for="star-4"></label>
    <input disabled class="star star-3" id="star-3" type="radio" name="star"/>
    <label class="star star-3" for="star-3"></label>
    <input disabled class="star star-2" id="star-2" type="radio" name="star"/>
    <label class="star star-2" for="star-2"></label>
    <input disabled class="star star-1" id="star-1" type="radio" name="star" checked="checked"/>
    <label class="star star-1" for="star-1"></label>

21 CSS Star Ratings, Collection of hand-picked free HTML and CSS star rating code examples. For the rating value to be displayed, data-rating-value HTML attribute must A CSS rating system that changes the facial expression based on how  .rating-star:hover, .rating-star:hover ~ .rating-star, .rating-input:checked ~ .rating-star { background-position: 0 0; } Selection now does stick but there’s still a problem. If you select a third star and try to hover second one you won’t get the desired effect — third one will still be active.

This question is about displaying a value, not creating an input

There is a very simple way to do that supporting half stars, rounding to the closest half, using font awesome (v4 classes in code, v5 classes in comment) and some basic arithmetic

echo $rating;
echo "<span class='stars'>"
for ( $i = 1; $i <= 5; $i++ ) {
    if ( round( $rating - .25 ) >= $i ) {
        echo "<i class='fa fa-star'></i>"; //fas fa-star for v5
    } elseif ( round( $rating + .25 ) >= $i ) {
        echo "<i class='fa fa-star-half-o'></i>"; //fas fa-star-half-alt for v5
    } else {
        echo "<i class='fa fa-star-o'></i>"; //far fa-star for v5
echo '</span>';

Change the color of the icons

.stars {
    color: #ff7501;
    font-size: 1.2em;

And voilà, you got yourself a rating display

Star Ratings, It is very common to set the maximum to 5. Save your form. The field will now look like this on the front-end: Star Rating Stars Displayed  The first two selectors target a star that is being hovered over, and any following stars; these selectors let the widget show the new rating. The final selector targets the checked star, and any following stars, so long as the widget is not being hovered over; these selectors let the widget show the current rating.

BootstrapVue, “BootstrapVue — Star Rating Customization” is published by John Au-Yeung in To make our lives easier, we can use components with styles built-in. We can change the number if starts to display with the stars prop. Basically interpreting a number <5 into stars filled in a 5-star rating system using jQuery/JS/CSS. Note that this would only display/show the stars rating from an already available number and not accept new ratings submissions.

Pure CSS Star Rating, And the base CSS code where we hide inputs while keeping labels .rating { overflow: hidden; display: inline-block; } .rating-input { float: right;  Game should display the current number of moves a user has made; The game should show a star rating (from 1–3) that reflects the player’s performance based on the number of moves made. When a player starts a game, a displayed timer should also start and once the player wins the game, the timer stops.

A simple star rating system using vanilla JS, CSS and HTML, The job entails a lot of frontend design and UI with heavy JS, CSS and HTML. A simple star rating system using vanilla JS, CSS and HTML to render appropriately depending on the facility selected and current user logged  Average rating: 3.2 out of 5 stars, based on 14 reviews 14 ratings Current Price $25.99 $ 25 . 99 List List Price $38.99 $ 38 . 99 Sold & shipped by Novashion