[SalesForce] How to apply CSS styles to a Rich text field in a Visualforce page

I have a Object 'A' with field 'testField1' and it has html formatted text value..

Something like this:

testField1 = "<div class="text">sample text </div><div class = "boldthis"> bold this text</div>"

I have overriden the object detail page for object A with visualforce page and it has style attributes, so how do i apply these styles for the field "testField1" on the detail page?

I am trying to do with <apex:outputText value="{!A.testField1}"> but it is just printing raw html text?

Best Answer

Your question implies that the HTML markup is being shown onscreen.

If that's the case, you can use the escape attribute on the outputText tag and VisualForce will not convert the values from the text into the HTML entities when rendering the markup.

Documentation: <apex:outputText />

Example:

<apex:outputText value="{!A.testField1}" escape="false" />
Related Topic