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 Developer Without Experience
No coding background? Learn how to become a Salesforce Developer step by step - skills to build, projects to create, and how to…
Salesforce How to Become a Salesforce Admin With No Experience
No Salesforce Admin experience? Learn how to build real skills, create projects, and land an entry-level Salesforce Admin job…
Salesforce How Long Does It Take to Become a Salesforce Developer?
Wondering how long to learn Salesforce Developer? Most beginners need 6–12 months. See the study time, stage-by-stage roadmap and…
Salesforce How Long Does It Take to Become a Salesforce Admin?
Wondering how long to learn Salesforce Admin? Most beginners need 3–6 months. See the study time, stage-by-stage roadmap and…