Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

Lightning : Icon color is not changing using the fill CSS

Asked by Carolyn Buckland Apr 22, 2021 3.9K views 2 answers
Share

About this question

 According to the documentation (https://www.lightningdesignsystem.com/components/icons/ ) we can change the icon color by using the CSS. I am not able to do it. It always overrides with the Salesforce style. My Style class is as below:  THIS .icn{ fill: white; } Other CSS properties like background color are applying but fill is always getting overridden by salesforce default color (grey). Anyone have any idea on how to fix this?


Your answer

2 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Jun 4, 2024

If the color of a Lightning icon is not changing using the fill CSS property, try these steps:


1 .Use slds-icon-text-default Class: 

Add the slds-icon-text-default class to the icon to use the standard SLDS color classes.

2. Override fill Property:

Ensure that your CSS is correctly overriding the default styles:

.custom-icon {
    fill: red !important;
}

Inline SVG Styles:

If the icon is an inline SVG, directly set the fill attribute within the SVG element:   

Use SLDS Utility Classes:

Use Salesforce Lightning Design System (SLDS) utility classes to change the color:

By following these steps, you should be able to change the icon color successfully.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.