Formatted Text

lightning:formattedText

Displays text, replaces newlines with line breaks, and linkifies if requested. This component requires API version 41.0 and later.

For Aura components only. For LWC development, use lightning-formatted-text.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:formattedText component displays a read-only representation of text, and can convert URLs and email addresses to links, or “linkify” them. It also converts the \r or \n characters into <br /> tags.

By default, URLs and email addresses display as plain text. To display URLs and email addresses in a block of text as links, set linkify="true".

Setting linkify="true" wraps URLs and email addresses in anchor tags with target="_blank". If the URL protocol isn’t specified in the text, the link’s href uses https:// or http:// to match the host domain’s protocol. For example, www.example.com is prefixed with https:// if the host domain’s protocol is https://. The href uses mailto:// for email addresses.

This example uses domain names without protocols in the text.

1<aura:component>
2  <lightning:formattedText
3    linkify="true"
4    value="I like salesforce.com and trailhead.salesforce.com."
5  />
6</aura:component>

The example renders like this.

1I like <a target="_blank" href="https://salesforce.com">salesforce.com</a> and
2<a target="_blank" href="https://trailhead.salesforce.com"
3  >trailhead.salesforce.com</a
4>.

Usage Considerations 

lightning:formattedText supports the following protocols: http, https, ftp, and mailto.

If you’re working with hyperlinks and need to specify the target value, use lightning:formattedURL instead. If you’re working with email addresses only, use lightning:formattedEmail.

For rich text that uses tags beyond anchor tags, use lightning:formattedRichText instead.

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS class for the outer element, in addition to the component's base classes.String
linkifySpecifies whether the text should be converted to a link. If set to true, URLs and email addresses are displayed in anchor tags.Boolean
titleDisplays tooltip text when the mouse moves over the element.String
valueText to output.String