I need to create a form in a visualforce page and use slds to style it. I know we can't use slds in apex:inputField and apex:pageBlock. If I dont use pageBlock I'm not able to see the label for each field. How to get it to work? Is there an alternative way?

<div style="slds-form-element" id="modalbody">
              <apex:pageBlockSection columns="1">
                <apex:inputText styleClass="slds-input" required="true" label="{!$ObjectType.CA_Additional_Information__c.fields.First_Name__c.label}" value="{!creditApplicantRecord.First_Name__c}"/>
                <apex:inputText styleClass="slds-input" required="true" label="{!$ObjectType.CA_Additional_Information__c.fields.Last_Name__c.label}" value="{!creditApplicantRecord.Last_Name__c}"/>
                <apex:inputText styleClass="slds-input" required="true" label="{!$ObjectType.CA_Additional_Information__c.fields.Phone_No__c.label}" value="{!creditApplicantRecord.Phone_No__c}"/>
  • did you try to standardStylesheets="false" or lightningStylesheets="true" – Tushar Sharma Jan 24 at 10:09
  • Yes. lightningStyleSheets is set to true. I've even added <apex:slds/>. The thing is that I can't see the label of the field without pageblock. – vedant gupta Jan 24 at 10:11
  • But you can use {!$ObjectType.Account.fields.Name.Label} to getthe field label – Tushar Sharma Jan 24 at 10:13
  • But the label is not showing up on the page if I dont include the fields inside a pageblock. Actually I used apex:outputLabel for the labels now. That is working – vedant gupta Jan 24 at 10:41
  • If it solves your problem then you can accept the answer and close the question. – Tushar Sharma Jan 24 at 10:50

You can use table/ div to create custom UI. To display a label with the field you can use {!$ObjectType.Account.fields.Name.Label}. Here you can change your object and field API name.

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.