[SalesForce] Unable to use SLDS Icons in Lightning Web Component

I am developing an app and I need to add SLDS icon with custom color (i.e. green or blue) to the UI.
Which is why I can't use <lightning-icon> component because you can override it style.

Thus I tried tu use a bare SLDS Svg with the folowing markup :

<span class="slds-icon_container slds-icon-utility-comments">
      <svg xmlns="http://www.w3.org/2000/svg" style="fill: #3496ec" class="slds-icon slds-icon-text-default" aria-hidden="true">
           <use xlink:href="/assets/icons/standard-sprite/svg/symbols.svg#comments"></use>
      </svg>
</span>

However the icon is not rendered and I have a 404 not found error in the console about the icon's link.

Any idea about that ?

Best Answer

Change "/assets" to "/_slds" in the use element.

<use xlink:href="/_slds/icons/standard-sprite/svg/symbols.svg#comments"></use>
Related Topic