Display Stars instead of Radio buttons

Display Stars instead of Radio buttons

July 10, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Display Stars instead of Radio buttons

Converting Radio Buttons to Star Ratings in Magent

As an experienced Laravel developer, I often receive queries from clients looking to enhance their user experience by replacing clunky radio buttons with sleek star ratings for product reviews. In this post, we’ll explore how to achieve this transformation using Magento 2.

The Current Situation: Radio Buttons Galore

Your current implementation likely looks something like this:

<!-- PHP code snippet from your PHTML file -->
<tbody>
  <tr>
    <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
    <?php foreach ($_rating->getOptions() as $_option): ?>
      <td class="value">
        <label for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>">
          <input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" />
        </label>
      </td>
    <?php endforeach; ?>
  </tr>
</tbody>

These radio buttons serve their purpose but don’t quite match the modern, intuitive feel of star ratings.

The Goal: Stars Instead of Radio Buttons

To achieve this, we’ll need to make some strategic changes:

  1. Hide the existing radio buttons: First, let’s hide those pesky radio buttons by adding a bit of CSS:
/* Add to your CSS file or place in a custom theme */
.review-summary-table .rating-box {
  display: none;
}
  1. Create new HTML for star ratings: Next, we’ll create the necessary HTML structure for our star ratings. Update your PHTML file accordingly:
<tbody>
  <tr>
    <th><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></th>
    <?php foreach ($_rating->getOptions() as $_option): ?>
      <td class="value">
        <div class="star-rating">
          <!-- Add your star rating HTML here -->
        </div>
      </td>
    <?php endforeach; ?>
  </tr>
</tbody>
  1. Style the star ratings: With the basic structure in place, we can now style our star ratings using CSS. You might use something like this as a starting point:
/* Add to your CSS file or place in a custom theme */
.star-rating {
  display: inline-block;
  position: relative;
}

.star-rating::before {
  content: '';
  display: block;
  width: 0;
  height: 15px;
  background-image: url('path/to/your/star-rating-sprite.png');
  background-repeat: no-repeat;
  opacity: 0.7; /* Adjust to your liking */
}
  1. Update the JavaScript: Finally, you’ll need to update your JavaScript (or use jQuery) to handle the click events on these new star ratings and submit the selected rating.

Conclusion

By following this approach, you can seamlessly replace those outdated radio buttons with sleek, modern star ratings that enhance both user experience and site aesthetics. Remember, the key lies in hiding the old elements, creating the new HTML structure, applying appropriate styling, and ensuring your JavaScript handles the updated functionality correctly.

For a more detailed walkthrough or to discuss how this can be incorporated into your specific Magento 2 setup, feel free to reach out to our expert team at Laravel Company. We’re always here to help transform your e-commerce platform into something truly exceptional.

Magento 2 Catalog Database Themes

Our network