function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tizian KirchmannTizian Kirchmann 

&nbsp; at beginning of every row in <apex:outputField>

Hi guys,

I created a visualforce page which displays the content of a field called 'Description'. This field can be several rows long and I want to add a whitespace with &nbsp; at the beginning of every row.

At the moment it looks like that:
&nbsp;<apex:outputField value="{!Rapport__c.Description__c}"/>

But obviously I will only have a whitespace in the first row and not in the following ones. So how do I ensure that at the beginning of every row, there is a whitespace before the text begins?

Thanks for your help.
SandhyaSandhya (Salesforce Developers) 

You can try below code.
<apex:outputText value="{!HTMLENCODE(Rapport__c.Description__c)}" 
  style="white-space:pre;" escape="false"/>

Best Regards,
Tizian KirchmannTizian Kirchmann
Hi Sandhya,

thanks for your answer. Sadly this does not work, I just tested it.
It doesnt not create any white spaces.
Chandrashekhar GoudChandrashekhar Goud

You can use this code, according to your req you can change the px.

<apex:outputField value="{!Rapport__c.Description__c}" style="margin-right:3px;" />
Tizian KirchmannTizian Kirchmann
Hi Chandrashekhar,

thanks for the advice. It actually worked. But there is another problem now.
When I enter a text in the description field like this:
- testing
- implementing

It gets displayed like this:
- testing - implementing

Isnt there any possibility​ to get a new line after pressing "return/enter" on the keyboard?

Tizian KirchmannTizian Kirchmann
I did it like that: 
<div class="fieldsTaetigkeitenBericht">
<apex:outputText value="{!HTMLENCODE(Rapport__c.Description__c)}" 
  style="white-space:pre;" escape="false"/>

And went to my static resource pdfStyle2 and added there:
.fieldsTaetigkeitenBericht {
margin-left: 3px;

Now it does do the line break and the white space :)


Chandrashekhar GoudChandrashekhar Goud

Use this 
​<div class="fieldsTaetigkeitenBericht">
<apex:outputField  value="{!HTMLENCODE(Rapport__c.Description__c)}"   style="white-space:pre;"/>