Fractional SVG stars with CSS

Some ⭐️⭐️⭐️⭐️⭐️ star rating systems aren’t always exactly even stars. Say you want to support rating something 2.25 stars. To do that you could “fill” the shape of the stars partially. I like this idea by Samuel Kraft. The tricky …


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

Some ⭐️⭐️⭐️⭐️⭐️ star rating systems aren’t always exactly even stars. Say you want to support rating something 2.25 stars. To do that you could “fill” the shape of the stars partially. I like this idea by Samuel Kraft. The tricky part is:

The final step is making the overlay div only affect the star SVGs beneath, not the background. We can do this by using the CSS mix-blend-mode property with the color value.

Check out Samuel’s post for an interactive demo and deeper information, but I thought I’d give it a crack myself to get a feel for the idea:

The idea is that this is an overlay on top of the stars. You can’t see it and it doesn’t affect the stars because it’s either black or white and mix-blend-mode: color; means that overlay will only effect elements that do have color.

There are loads of ways to do rating stars, for the record. We covered five of them a little while back. One rather clever method in there is using unicode stars (like, as text), then filling their background with -webkit-background-clip: text; which means you can partially fill them (like with a hard-stop linear-gradient()). Solid trickery, that.

To Shared LinkPermalink on CSS-Tricks


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-12-02T15:42:37+00:00) Fractional SVG stars with CSS. Retrieved from https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/

MLA
" » Fractional SVG stars with CSS." Chris Coyier | Sciencx - Thursday December 2, 2021, https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/
HARVARD
Chris Coyier | Sciencx Thursday December 2, 2021 » Fractional SVG stars with CSS., viewed ,<https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/>
VANCOUVER
Chris Coyier | Sciencx - » Fractional SVG stars with CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/
CHICAGO
" » Fractional SVG stars with CSS." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/
IEEE
" » Fractional SVG stars with CSS." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/. [Accessed: ]
rf:citation
» Fractional SVG stars with CSS | Chris Coyier | Sciencx | https://www.scien.cx/2021/12/02/fractional-svg-stars-with-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.