Skip to main content

Text

Renders text in a <span>, or the element that its role picks.

import { Text } from 'react-native'

export function Byline({ author }) {
return (
<Text numberOfLines={1}>
By <Text style={{ fontWeight: 'bold' }}>{author}</Text>
</Text>
)
}

A Text starts at 14 px, black, in the system font, and keeps its spaces and line breaks, as on native. A Text inside a Text takes the font, color, alignment, and decoration of its parent.

Props​

PropOn the web
styleCompiles to atomic CSS. See Styles.
numberOfLines1 keeps the text on one line and ends it with an ellipsis. A larger number clamps the text to that many lines.
ellipsizeModetail (the default) and clip. head and middle show the ellipsis at the end for now.
selectableThe text is selectable by default, as web users expect. On native the default is false. false turns selection off.
selectionColorThe background color of selected text.
onPress, onPressIn, onPressOutAs on Pressable: a pointer, Enter or Space, or a click. The event is a GestureResponderEvent.
onLongPressA press held for 500 ms. onPress then doesn't fire.
pressRetentionOffsetHow far a pointer can leave the text and still press it, as on Pressable.
suppressHighlightingIgnored, as on Android. Only iOS highlights a pressed Text.
disabledSets aria-disabled. The Text isn't pressable, so a pressable parent gets the press.
role, accessibility propsSee Semantic HTML.
onLayout, pointerEventsAs on View.
nativeID, id, testIDid, id, and data-testid.
hrefWeb only. Renders an <a>.
target, rel, downloadWeb only. Pass to the anchor.
langWeb only. The language of the text, for screen readers and hyphenation.
aria-levelWeb only. The heading level of role="heading", 1 to 6.
onClick and the other DOM handlersWeb only. Pass to the element. On a pressable Text, they run before the press handlers, and both run.

As on native, only onPress or onLongPress makes a Text pressable. A Text with only onPressIn or onPressOut doesn't respond. A pressable Text that isn't disabled shows the pointer cursor, and a cursor in style wins.

A pressable text is a link

As on native, a pressable Text with no role has the role link. It's in the tab order, and Enter or Space presses it. With an href, it renders an <a>. For an action, set role="button", and it renders a <button>.

Ref​

The ref is the DOM element. It has the measure methods of View. The type is TextInstance.