3

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 ?

1 Answer 1

9

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

<use xlink:href="/_slds/icons/standard-sprite/svg/symbols.svg#comments"></use>
4
  • I just tested and it doesn't work in my case
    – Ombrelin
    Feb 13, 2020 at 15:23
  • 3
    I can confirm this works in Winter 2020. My example: <use xlink:href="/_slds/icons/utility-sprite/svg/symbols.svg#check"></use>
    – Mattisdada
    Jun 24, 2020 at 5:22
  • This works with Edge
    – Cray Kao
    Jan 4, 2021 at 4:38
  • Still working in Winter 2022 Apr 29 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.