For the complete documentation index, see llms.txt. This page is also available as Markdown.

Rich Text Field Formatting Considerations

Clean up extra spacing from rich text fields and control paragraph tags in merge fields and related lists.

Rich text fields often create extra spacing in generated documents.

This behavior is most common when the rich text value is saved in Lightning Experience.

Problem

Salesforce rich text values usually contain HTML such as <p> and <br>.

That can cause a few common issues:

  • Extra blank lines between paragraphs

  • Missing bold or italic styles when Unicode fonts are fully enabled

  • Font substitution in PDF output, such as Times New Roman

Solution 1: Clean up a merge field

Use this pattern when you output a single rich text field directly in the template.

merge-field-example.html
<div style="font-family: sans-serif;">{{{!Object.fieldname replaceall="#LT#/p#GT##LT#
p#GT##LT#br#GT#,#LT#br#GT#,#LT#/p#GT##LT#p#GT#,#LT#br#GT#,#LT#p#GT#, ,#LT#/p#GT#, "}}}</div>

This replaces paragraph tags with single break tags and removes extra spacing.

Example

Field value stored in Salesforce

<p>First line</p><p><br></p><p>Second line</p>

Rendered output

Use this option when a related list column should render as plain text with line breaks only.

Example

Field value stored in Salesforce

Rendered output

Use this option when you want to preserve the outer paragraph wrapper and still remove the extra blank line in the middle.

Example

Field value stored in Salesforce

Rendered output

Tag reference

Use encoded tokens inside merge fields.

Use literal HTML tags inside related list column attributes.

Token
Represents

#LT#p#GT#

<p>

#LT#/p#GT#

</p>

#LT#br#GT#

<br>

#QUOT#

"

#AMP#

&

Last updated

Was this helpful?