This is an inline version suggested above by https://stackoverflow.com/users/383904/roko-c-buljan (with many thanks!)
<span style="--rating: 1.6; content: '★★★★★'; font-size: 2em; white-space: nowrap; background: linear-gradient(90deg, #fb0 calc(var(--rating) * 20%), #ddd calc(var(--rating) * 20%)); -webkit-background-clip: text; background-clip: text; color: transparent;">★★★★★</span>
<span style="--rating: 4.2; content: '★★★★★'; font-size: 2em; white-space: nowrap; background: linear-gradient(90deg, #fb0 calc(var(--rating) * 20%), #ddd calc(var(--rating) * 20%)); -webkit-background-clip: text; background-clip: text; color: transparent;">★★★★★</span>