Flowbite::Rating

Renders a star rating, showing a value out of a maximum number of stars.

The number of filled stars is the value rounded to the nearest whole number (halves round up), clamped between 0 and +max+. The remaining stars are rendered as empty stars. The exact value is announced to screen readers.

Basic usage

<%= render(Flowbite::Rating.new(value: 4)) %>

With text and a custom size

<%= render(Flowbite::Rating.new(size: :lg, text: "4.95 out of 5", value: 4.95)) %>

Examples

Rating With Text

Use this example to show the rating score next to the stars.

Sizes

Control the size of the stars.

Number Of Stars

Change the total number of stars using the max argument.

API reference

Inherits from Flowbite

In namespace

Constructor

def initialize(value:, class: nil, max: 5, size: :default, text: nil, **options)

Parameters

class String, Array<String> Additional CSS classes for the container element.
max Integer The total number of stars to render (default: 5).
options Hash Additional HTML options for the container element.
size Symbol The size of the stars (:default, :md, :lg).
text String Optional text rendered after the stars, e.g. "4.95 out of 5".
value Numeric The rating value, e.g. 4 or 4.95.

See also

Ruby API documentation for class Flowbite::Rating