About this question
I need to display a button which will display a text along with an icon. I tried similar to below code
But its displaying button with only text inside it. Is there any way to add both text and icon inside the button?
I need to display a button which will display a text along with an icon. I tried similar to below code
But its displaying button with only text inside it. Is there any way to add both text and icon inside the button?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Salesforce Expert
Answered on Apr 20, 2023
You just need to specify the label as well as the lightning button icon-name in the button.
Ranjana Admin JanBask Expert Latest answer
Answered on Jun 12, 2024
In Salesforce Lightning, you can have both an icon and text in a button using the lightning-button component. This can be achieved by using the icon-name attribute to specify the icon and placing the text content within the button tags. Additionally, you may need to use CSS to align the icon and text properly.
Here’s an example of how to create a button with both an icon and text:
In this example:
If you need more control over the positioning of the icon and the text, you can use the lightning-button-icon component along with custom styling. Here’s how you can do it:
.custom-button { display: flex; align-items: center; } .button-text {margin-left: 8px; }In this example:
The lightning-button-icon component is used to display the icon.
The text "New Record" is placed in a span element next to the icon.
Custom CSS is used to align the icon and text horizontally and add some spacing between them.
This approach gives you more flexibility in styling and positioning the icon and text within the button.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Salesforce guides from industry experts
Common Salesforce interview questions, answered
Guides, tips and career advice on Salesforce from JanBask experts.
Salesforce How to Become a Salesforce Administrator in 2027: A Step-by-Step Career Roadmap
Want to become a Salesforce Administrator? Get the complete 2026 roadmap skills, certification, salary & career path. Start your…
Salesforce Salesforce Admin Self Study vs Live Training: How to Choose the Right Path
Compare Salesforce Admin self-study and live training by cost, duration, flexibility, mentorship, and career support. Find the…
Salesforce How a Salesforce Admin Certification Shapes Your Career Growth
Wondering if a salesforce admin certification is worth it? See how it shapes hiring, salary, and long term salesforce admin…
Salesforce Salesforce Admin vs Developer Salary: Which Path Actually Pays More?
Salesforce admin vs developer salary: developers earn 15–25% more. See entry, mid and senior pay, why the gap exists, and how…