Skip to main content
Brand and assets
Build
Monitor and contribute
/
Component library
  • All components
  • Buttons & actions
  • Forms & inputs
  • Layout & containers
  • Overlays
  • Feedback & status
  • Data display
  • Typography
    • A
    • AnimatedTypography
    • Code
    • Em
    • FormattedText
    • Heading
    • Highlight
    • List
    • Paragraph
    • Strike
    • Strong
    • Text
  • Accessibility
  • Contrib
  • Deprecated
  • Typography
  • FormattedText

FormattedText

Styles parts of a plain string by matching patterns. Use when the text comes from elsewhere and you cannot wrap the parts by hand.

Health
Component health
Source
View on Github
Playground
No Example
Accessibility

compliant

Platform
Universal
  • Overview
  • Props

Usage​

FormattedText takes a plain text and a list of rules, then styles the parts that match each rule's pattern. Use it when the text to format isn't known at build time — search results, user-generated content, server-driven copy with markdown-like markers — and you can't hand-write Strong, Em, Highlight or A inline.

For static text with known emphasis, prefer composing Text with those inline components directly.

Bold​

Each rule matches a pattern and applies typography props to the match. Use renderText to strip the markers from the displayed text.

This text has bold words and more bold in it.

Links​

Add onPress to make a match interactive. Matched capture groups are passed to both renderText and onPress, so you can show one string and act on another (e.g. label vs. url).

Click this link to open the url.

Highlighting​

Set mark: true to wrap the match in a semantic <mark> tag — appropriate for search-result highlighting.

Search results: matching words are wrapped in a semantic mark tag.

Multiple rules​

Pass several rules to format different patterns at once. Rules are applied in order, and each rule runs over the segments produced by the previous one — so a later rule can match text inside an earlier match.

This has bold and highlighted text together.

Rules apply in order, so matches can nest: highlighted with bold inside it.

Rule reference​

Each entry in rules is a TextFormattingRule:

FieldTypeDescription
patternRegExpMatched against the text. The g flag is applied automatically.
renderText(match: string, groups: string[]) => stringMaps a match to its displayed text (e.g. strip ** markers).
onPress(match: string, groups: string[]) => voidMakes the match an interactive A.
markbooleanWraps the match in a semantic <mark> tag.
weightTextProps["weight"]Font weight for the match.
italicTextProps["italic"]Renders the match italic.
colorTextProps["color"]Color token for the match.
fontFamilyTextProps["fontFamily"]Font family for the match.
sxTextProps["sx"]Extra styles, merged on top of the root sx.

groups is the full regex match array, so groups[1], groups[2]… are the capture groups.

tip
This component is universal, its usage is the same in murray and murray/mobile.

FormattedText props

NameTypeDefault ValueDescriptionUsage count
align
9 possibilities"unset""left""right""end""start""auto""center""justify"undefined
aria-disabledbooleanundefined
aria-labelstringundefined
aria-levelnumberundefinedHeading level when paired with `role="heading"`.
asChild
5 possibilitiesboolean"web""except-style""except-style-web"undefined
classNamestringundefined
color
4 possibilitiesundefined`$${string}`Variable<any>OpaqueColorValue
Color prop accepts Tamagui color tokens, ColorTokens, or dynamic token strings. Examples: "$grey900", "$indigo500", "$white", or dynamically constructed tokens like `$${name}900`
dir"auto"Directionundefined
ellipsizeMode"head""middle""tail""clip"undefined
fontFamilyFontTokensundefined
htmlForstringundefined
idstringundefined
italicbooleanundefined
langLocaleOrLanguageundefined
maxFontSizeMultipliernumbernullundefined
numberOfLinesnumberundefined
onLayout((e: LayoutChangeEvent) => void)undefined
onTextLayout
2 possibilitiesundefined(e: NativeSyntheticEvent<TextLayoutEventData>) => void
Fires on mobile with the list of rendered lines. Passes through to the underlying RN Text.
roleRoleundefined
rules*TextFormattingRule[]
size
9 possibilitiesundefinednumberVariable<any>"$text100""$text200""$text300""$text400""$text500"Partial<Record<"$xs" | "$ltVs" | "$vs" | "$ltSm" | "$sm" | "$ltMd" | "$md" | "$ltLg" | "$lg" | "$ltXl" | "$xl" | "$ltXxl" | "$xxl", TextSize>>
Font size and line height token, see `TypographyBaseProps["size"]`. Also accepts one size per breakpoint, e.g. `{ $xs: "$text200", $lg: "$text300" }`: widths that no key matches keep the default or inherited size.
sx
2 possibilitiesundefinedOmit<TextProps, "fontStyle" | "fontFamily" | "fontWeight">
tabIndexstringnumberundefined
tag"p""span"undefined
transform
6 possibilities"none""capitalize""uppercase""lowercase""unset"undefined
weightTextWeightundefined

Style API​

Use sx for one-off adjustments. It accepts these style keys:

accessibilityActionsaccessibilityElementsHiddenaccessibilityHintaccessibilityIgnoresInvertColorsaccessibilityLabelaccessibilityLabelledByaccessibilityLanguageaccessibilityLargeContentTitleaccessibilityLiveRegionaccessibilityRespondsToUserInteractionaccessibilityRoleaccessibilityShowsLargeContentVieweraccessibilityStateaccessibilityValueaccessibilityViewIsModalaccessibleadjustsFontSizeToFitalignContentalignItemsalignSelfallowFontScalingandroid_hyphenationFrequencyanimateOnlyanimatePresenceanimationaria-busyaria-checkedaria-disabledaria-expandedaria-hiddenaria-labelaria-labelledbyaria-livearia-modalaria-selectedaria-valuemaxaria-valueminaria-valuenowaria-valuetextasChildaspectRatiobackdropFilterbackfaceVisibilitybackgroundbackgroundAttachmentbackgroundBlendModebackgroundClipbackgroundColorbackgroundImagebackgroundOriginbackgroundPositionbackgroundRepeatbackgroundSizeblockSizeborderBlockColorborderBlockEndColorborderBlockEndStyleborderBlockEndWidthborderBlockStartColorborderBlockStartStyleborderBlockStartWidthborderBlockStyleborderBlockWidthborderBottomColorborderBottomEndRadiusborderBottomLeftRadiusborderBottomRightRadiusborderBottomStartRadiusborderBottomWidthborderColorborderCurveborderEndColorborderEndEndRadiusborderEndStartRadiusborderEndWidthborderImageborderInlineColorborderInlineEndColorborderInlineEndStyleborderInlineEndWidthborderInlineStartColorborderInlineStartStyleborderInlineStartWidthborderInlineStyleborderInlineWidthborderLeftColorborderLeftWidthborderRadiusborderRightColorborderRightWidthborderStartColorborderStartEndRadiusborderStartStartRadiusborderStartWidthborderStyleborderTopColorborderTopEndRadiusborderTopLeftRadiusborderTopRightRadiusborderTopStartRadiusborderTopWidthborderWidthbottomboxShadowboxSizingcaretColorchildrenclassNameclipPathcolorcolumnGapcomponentNamecontaincontainerTypecontentcursordangerouslySetInnerHTMLdataDetectorTypedebugdirectiondisableClassNamedisableOptimizationdisableddisabledStyledisplaydynamicTypeRampelevationellipseellipsizeModeendenterStyleexitStyleexperimental_backgroundImageexperimental_backgroundPositionexperimental_backgroundRepeatexperimental_backgroundSizefilterflexflexBasisflexDirectionflexGrowflexShrinkflexWrapfloatfocusStylefocusVisibleStylefocusWithinStylefontSizefontVariantfontVariationSettingsforceStylegapgridColumngridColumnEndgridColumnGapgridColumnStartgridRowgridRowEndgridRowGapgridRowStartgridTemplateAreasgridTemplateColumnsgroupheighthitSlophoverStylehtmlForidimportantForAccessibilityincludeFontPaddinginlineSizeinsetinsetBlockinsetBlockEndinsetBlockStartinsetInlineinsetInlineEndinsetInlineStartisolationjustifyContentleftletterSpacinglineBreakModelineBreakStrategyIOSlineHeightmarginmarginBlockmarginBlockEndmarginBlockStartmarginBottommarginEndmarginHorizontalmarginInlinemarginInlineEndmarginInlineStartmarginLeftmarginRightmarginStartmarginTopmarginVerticalmaskmaskBordermaskBorderModemaskBorderOutsetmaskBorderRepeatmaskBorderSlicemaskBorderSourcemaskBorderWidthmaskClipmaskCompositemaskImagemaskModemaskOriginmaskPositionmaskRepeatmaskSizemaskTypematrixmaxBlockSizemaxFontSizeMultipliermaxHeightmaxInlineSizemaxWidthminBlockSizeminHeightminInlineSizeminWidthminimumFontScalemixBlendModenativeIDnumberOfLinesobjectFitonAccessibilityActiononAccessibilityEscapeonAccessibilityTaponBluronFocusonHoverInonHoverOutonLongPressonMagicTaponMouseDownonMouseEnteronMouseLeaveonMouseUponPressonPressInonPressOutopacityoutlineColoroutlineOffsetoutlineStyleoutlineWidthoverflowoverflowBlockoverflowInlinepaddingpaddingBlockpaddingBlockEndpaddingBlockStartpaddingBottompaddingEndpaddingHorizontalpaddingInlinepaddingInlineEndpaddingInlineStartpaddingLeftpaddingRightpaddingStartpaddingToppaddingVerticalpassThroughperspectivepointerEventspositionpressRetentionOffsetpressStylerightrolerotaterotateXrotateYrotateZrotationrowGapscalescaleXscaleYscreenReaderFocusablescrollbarWidthselectableselectionColorseparatorshadowColorshadowOffsetshadowOpacityshadowRadiusskewXskewYspacespaceDirectionstartstylesuppressHighlightingtabIndextagtargettestIDtextAligntextAlignVerticaltextBreakStrategytextDecorationColortextDecorationDistancetextDecorationLinetextDecorationStyletextEmphasistextOverflowtextShadowColortextShadowOffsettextShadowRadiustextTransformtextWrapthemethemeInversethemeShallowtoptouchActiontransformtransformMatrixtransformOrigintransformStyletransitiontranslateXtranslateYuntilMeasureduserSelectverticalAlignwhiteSpacewidthwordWrapwritingDirectionxyzIndex

Each can be overridden per breakpoint with:

$group-focus$group-focusVisible$group-focusWithin$group-hover$group-lg$group-lg-focus$group-lg-focusVisible$group-lg-focusWithin$group-lg-hover$group-lg-press$group-ltLg$group-ltLg-focus$group-ltLg-focusVisible$group-ltLg-focusWithin$group-ltLg-hover$group-ltLg-press$group-ltMd$group-ltMd-focus$group-ltMd-focusVisible$group-ltMd-focusWithin$group-ltMd-hover$group-ltMd-press$group-ltSm$group-ltSm-focus$group-ltSm-focusVisible$group-ltSm-focusWithin$group-ltSm-hover$group-ltSm-press$group-ltVs$group-ltVs-focus$group-ltVs-focusVisible$group-ltVs-focusWithin$group-ltVs-hover$group-ltVs-press$group-ltXl$group-ltXl-focus$group-ltXl-focusVisible$group-ltXl-focusWithin$group-ltXl-hover$group-ltXl-press$group-ltXxl$group-ltXxl-focus$group-ltXxl-focusVisible$group-ltXxl-focusWithin$group-ltXxl-hover$group-ltXxl-press$group-md$group-md-focus$group-md-focusVisible$group-md-focusWithin$group-md-hover$group-md-press$group-press$group-sm$group-sm-focus$group-sm-focusVisible$group-sm-focusWithin$group-sm-hover$group-sm-press$group-vs$group-vs-focus$group-vs-focusVisible$group-vs-focusWithin$group-vs-hover$group-vs-press$group-xl$group-xl-focus$group-xl-focusVisible$group-xl-focusWithin$group-xl-hover$group-xl-press$group-xs$group-xs-focus$group-xs-focusVisible$group-xs-focusWithin$group-xs-hover$group-xs-press$group-xxl$group-xxl-focus$group-xxl-focusVisible$group-xxl-focusWithin$group-xxl-hover$group-xxl-press$lg$ltLg$ltMd$ltSm$ltVs$ltXl$ltXxl$md$platform-android$platform-ios$platform-native$platform-web$sm$vs$xl$xs$xxl
Edit this page
Previous
Em
Next
Heading
  • Usage
    • Bold
    • Links
    • Highlighting
    • Multiple rules
  • Rule reference