Formatted Text

lightning-formatted-text

Displays text, replaces newlines with line breaks, and linkifies if requested.

For Use In

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

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

By default, URLs and email addresses show as plain text. To show URLs and email addresses in a block of text as links, include linkify on the lightning-formatted-text tag.

linkify wraps URLs and email addresses in anchor tags with target="_blank". If you don’t specify the URL protocol in the text, the link’s href uses https:// or http:// to match the host domain’s protocol. For example, the component prefixes www.example.com 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<template>
2    <lightning-formatted-text
3        value="I like salesforce.com and trailhead.salesforce.com."
4        linkify
5    >
6    </lightning-formatted-text>
7</template>

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-formatted-text supports these protocols: http, https, ftp, and mailto.

If you’re working with hyperlinks and want to specify the target value, use lightning-formatted-url instead. If you’re working with email addresses only, use lightning-formatted-email.

For rich text that uses tags beyond anchor tags, use lightning-formatted-rich-text instead.

See Also 

Object Reference for the Salesforce Platform: Field Types

Attributes 

NameDescriptionTypeDefaultRequired
linkifyIf present, URLs and email addresses are displayed in anchor tags. They are displayed in plain text by default.booleanfalse
valueSets the text to display.string