
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.
In Salesforce Visualforce, the apex:outputText component renders Apex controller variable values as HTML text. When a Visualforce page performs a partial postback (using the rerender attribute on a commandButton or other action component), the Visualforce engine processes the output using an HTML parsing library called Tidy. Tidy is designed to fix invalid HTML — however, it also strips multiple consecutive spaces and line break characters (such as \r\n) from text content inside HTML tags such as <span> (which apex:outputText renders as).
As a result, if a controller variable contains multiple consecutive spaces between words or blank line characters, these whitespace elements appear correctly on the initial page load. However, after any partial postback that rerenders the component, the spaces and line breaks are stripped, causing the displayed text to lose its formatting.
To reproduce this behavior: Bind an apex:outputText component to a String variable in the controller that contains multiple spaces between words and newline characters. Wrap it in an apex:outputPanel with an apex:commandButton that rerenders the panel. On the initial load the spacing appears correctly. After clicking the button to trigger a rerender, the extra spaces and line breaks are removed.
Note: This behavior is caused by the Tidy parser operating on the generated HTML output, not by a Tidy bug related to attribute-level whitespace (such as JBoss RF-1710). The Tidy parser does not preserve whitespace inside SPAN tag content unless the content is wrapped in a PRE tag.
Replace regular space characters in the controller string with HTML non-breaking space entities ( ). Set the escape attribute on apex:outputText to "false" to prevent Visualforce from HTML-escaping these entities before output.
Important: Use escape="false" only with fully trusted and sanitized content. Setting escape to false allows raw HTML to be rendered, which creates a cross-site scripting (XSS) risk if the content contains user-supplied data.
Example: In the controller, replace spaces between words with entities. In the Visualforce page, use <apex:outputText escape="false" value="{!yourVariable}"/>.
The apex:outputField component renders SObject field values using the field's native data type formatting, which can preserve spacing for certain field types such as Long Text Area fields. If your use case involves displaying SObject field values, switching from apex:outputText to apex:outputField may resolve the whitespace stripping issue.
The Tidy parser preserves whitespace inside HTML <pre> (preformatted text) tags. Wrapping the content rendered by apex:outputText inside a <pre> tag in the Visualforce page prevents Tidy from stripping spaces and line breaks on postback.
If the whitespace issue occurs within apex:selectList / apex:selectOptions / apex:selectOption components displaying options with multiple spaces, set the itemEscaped attribute to "false" on apex:selectOption, or call setEscapeItem(false) on each SelectOption object in the controller that contains entities.
000387212