Resize Lightning Field Label: Modify Font Size

When working with Lightning Components in Salesforce, you may want to customize the appearance of field labels, including their font size. In this post, we’ll go through the steps to modify the font size of a Lightning field label effectively.

Step 1: Create Your Lightning Component

First, let’s create a simple Lightning component with a lightning:select field. This will serve as our example where we will modify the label size.

<aura:component> <lightning:select name="select1" label="How many tickets?" required="true"> <option value="">Choose one...</option> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </lightning:select> </aura:component>

Explanation:

  • The lightning:select component is created with a label "How many tickets?" and three options.
  • The required attribute ensures that the user must select an option before submitting the form.

Step 2: Add Custom CSS to Modify Font Size

To change the font size of the field label, you will need to add custom CSS to the component’s style section. This can be achieved by using the .THIS selector to ensure your styles are scoped correctly.

.THIS .slds-form-element__label { font-size: 1.2rem !important; }

Explanation:

  • The CSS rule targets the label within the lightning:select component using the Salesforce Lightning Design System (SLDS) class .slds-form-element__label.
  • The font-size property is set to 1.2rem to increase the label size.
  • The !important declaration is used to ensure that this style takes precedence over any existing styles defined by the SLDS.

Conclusion

By following these steps, you can easily resize the font of Lightning field labels to better suit your application's design needs. Customizing your components enhances user experience and ensures that your application stands out.

Feel free to apply this approach to other Lightning components where you need to adjust label sizes. Happy coding!

Comments

Popular posts from this blog

Best Practices for Creating Salesforce Roll-Up Summary Triggers

CREATE WEB-FORM USING LIGHTNING WEB COMPONENTS SALESFORCE

Utilizing a Generic Pagination Class in Lightning Web Components - Part 1