apex:outputText

Displays text on a Visualforce page. You can customize the appearance of <apex:outputText> using CSS styles, in which case the generated text is wrapped in an HTML <span> tag. You can also escape the rendered text if it contains sensitive HTML and XML characters.

Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputField> and <apex:outputField> can be used with sObject fields.

Use with nested param tags to format the text values, where {n} corresponds to the n-th nested param tag. The value attribute supports the same syntax as the MessageFormat class in Java.

In API version 31.0 and earlier, encrypted custom field values that are embedded in the <apex:outputText> component display in clear text. The <apex:outputText> component doesn’t respect the View Encrypted Data permission for users. To prevent showing sensitive information to unauthorized users, use the <apex:outputField> tag instead.

In API version 32.0 and later, encrypted custom field values are masked.

Note

This component supports HTML pass-through attributes using the “html-” prefix. Pass-through attributes are attached to the generated container <span> tag.

Basic formatting example 

1<apex:page>
2    <apex:outputText style="font-style:italic" value="This is {0} text with {1}.">
3       <apex:param value="my"/>
4       <apex:param value="arguments"/>
5    </apex:outputText>
6</apex:page>

The example above renders the following HTML:

1<span id="theText" style="font-style:italic">This is my text with arguments.</span>

Date formatting example 

1<apex:page>
2   <apex:outputText value="The unformatted time right now is: {! NOW() }" />
3   <br/>
4   <apex:outputText value="The formatted time right now is:
5         {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">
6       <apex:param value="{! NOW() }" />
7   </apex:outputText>
8</apex:page>

The example above renders the following HTML:

1The unformatted time right now is: 11/20/2004 3:49 PM
2<br />
3The formatted time right now is: 2004.11.20 AD at 23:49:02 GMT

Currency formatting example 

1<!-- For this example to render properly, you must associate the Visualforce page
2with a valid account record in the URL.
3For example, if 001D000000IeChM is the account ID, the resulting URL should be:
4https://MyDomain_login_URL/apex/myPage?id=001D000000IeChM
5See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
6
7<apex:page standardController="Account">
8It is worth:
9<apex:outputText value="{0, number, 000,000.00}">
10       <apex:param value="{!Account.AnnualRevenue}" />
11 </apex:outputText>
12</apex:page>

The example above renders the following HTML:

1It is worth: 500,000,000.00

Attributes 

Attribute NameAttribute TypeDescriptionRequired?API VersionAccess
dirStringThe direction in which the generated HTML component is read. Possible values include “RTL” (right to left) or “LTR” (left to right). 10.0global
escapeBooleanA Boolean value that specifies whether sensitive HTML and XML characters should be escaped in the HTML output generated by this component. If you don’t specify escape=“false”, the character escape sequence displays as written. Be aware that setting this value to “false” may be a security risk because it allows arbitrary content, including JavaScript, that could be used in a malicious manner. 10.0global
idStringAn identifier that allows the outputText component to be referenced by other components in the page. 10.0global
labelStringA text value that allows to display a label next to the output text 23.0
langStringThe base language for the generated HTML output, for example, “en” or “en-US”. For more information on this attribute, see the W3C specifications. 10.0global
renderedBooleanA Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. 10.0global
styleStringThe style used to display the outputText component, used primarily for adding inline CSS styles. 10.0global
styleClassStringThe style class used to display the outputText component, used primarily to designate which CSS styles are applied when using an external CSS stylesheet. 10.0global
titleStringThe text to display as a tooltip when the user’s mouse pointer hovers over this component. 10.0global
valueObjectThe text displayed when this component is rendered. This value supports the same syntax as the MessageFormat class in Java. 10.0global