When I use Material Icons, I can switch the style by replacing the class name. (between material-icons and material-icons-outlined)
Now I am trying to use Material Symbols. Let's say I use star icon and want to make the icon filled.
public/index.html
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@48,400,1,0" />
<span class="material-symbols-outlined">
star
</span>
For Material Symbols, the class name will be the same between filled and outlined and I am wondering if I can switch the style programaitically.
You can use the CSS
font-variation-settingsproperty to set the symbol style per element. Check the codepen example here: Variable font with Google Fonts.I used example code found in Google: Material Symbols guide and modified it to create a little demo showcasing how to set the symbol style using a CSS custom property.
--variationfont-variation-settingsunset: sets it to the Google default setting for.material-symbols-outlinedfont-variation-settings: 'FILL' 0, 'wght' 100, 'GRAD' 0, 'opsz' 48font-variation-settings: 'FILL' 1, 'wght' 700, 'GRAD' 0, 'opsz' 48snippet give the symbol font file time to load...