androidx.compose.material3
Text
Composable function
Text shows text. Pick a style from the theme with MaterialTheme.typography, instead of setting sizes by hand.

Column {
Text("Headline", style = MaterialTheme.typography.headlineSmall)
Text("Body text in the default style.")
Text("Label", style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary)
}
The Material Text uses the theme: its color comes from the surrounding component (LocalContentColor), and its style from LocalTextStyle. Inside a Button, it gets the button's text color automatically.
String
Plain text.
@Composable
fun Text(
text: String,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
autoSize: TextAutoSize? = null,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
onTextLayout: ((TextLayoutResult) -> Unit)? = null,
style: TextStyle = LocalTextStyle.current,
)
text: StringRequired
text: StringRequiredThe text to show. A String, or an AnnotatedString for mixed styles.

Text(
buildAnnotatedString {
append("Delivery ")
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) { append("tomorrow") }
append(", before ")
withStyle(SpanStyle(color = MaterialTheme.colorScheme.primary)) { append("12:00") }
},
)
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position of the text. See the Modifier guide.
color: ColorOptional
color: ColorOptionalDefault: Color.Unspecified
The text color. Default: taken from style, or else from the surrounding component.
In the "changing color" forms, pass a function that returns the color. This avoids recomposing while the color animates.
autoSize: TextAutoSize?OptionalSince 1.9
autoSize: TextAutoSize?OptionalSince 1.9Default: null
Makes the text shrink or grow to fit its space, for example TextAutoSize.StepBased().
fontSize: TextUnitOptional
fontSize: TextUnitOptionalDefault: TextUnit.Unspecified
The size of the text, in sp. Prefer a style from the theme.
fontStyle: FontStyle?Optional
fontStyle: FontStyle?OptionalDefault: null
fontWeight: FontWeight?Optional
fontWeight: FontWeight?OptionalDefault: null
How bold the text is, for example FontWeight.Bold.
fontFamily: FontFamily?Optional
fontFamily: FontFamily?OptionalDefault: null
The typeface. Default: the theme's font.
letterSpacing: TextUnitOptional
letterSpacing: TextUnitOptionalDefault: TextUnit.Unspecified
Extra space between letters.
textDecoration: TextDecoration?Optional
textDecoration: TextDecoration?OptionalDefault: null
textAlign: TextAlign?Optional
textAlign: TextAlign?OptionalDefault: null
How lines are aligned: start, center, end or justify. Only visible when the text is wider than one line or has a set width.

Text(
"Centered text that wraps onto a second line.",
textAlign = TextAlign.Center,
modifier = Modifier.width(220.dp),
)
lineHeight: TextUnitOptional
lineHeight: TextUnitOptionalDefault: TextUnit.Unspecified
The height of each line.
overflow: TextOverflowOptional
overflow: TextOverflowOptionalDefault: TextOverflow.Clip
What to do with text that does not fit. TextOverflow.Ellipsis ends it with "…". Default: cut off.

Text(
"This sentence is too long to fit on one line in this narrow space.",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.width(240.dp),
)
softWrap: BooleanOptional
softWrap: BooleanOptionalDefault: true
Set to false to keep the text on one line, even if it does not fit.
maxLines: IntOptional
maxLines: IntOptionalDefault: Int.MAX_VALUE
The most lines to show. Combine with overflow.
minLines: IntOptional
minLines: IntOptionalDefault: 1
The fewest lines to take up, even if the text is shorter.
onTextLayout: ((TextLayoutResult) -> Unit)?Optional
onTextLayout: ((TextLayoutResult) -> Unit)?OptionalDefault: null
Called with the text layout after it is measured, for example to find out if the text was cut off.
style: TextStyleOptional
style: TextStyleOptionalDefault: LocalTextStyle.current
A whole text style: font, size, weight, line height. Use one from MaterialTheme.typography, like titleMedium.
Single parameters like fontSize override parts of it.
String, changing color
Takes color as a function, for colors that animate often.
@Composable
fun Text(
text: String,
color: ColorProducer,
modifier: Modifier = Modifier,
autoSize: TextAutoSize? = null,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
onTextLayout: ((TextLayoutResult) -> Unit)? = null,
style: TextStyle = LocalTextStyle.current,
)
color: ColorProducerRequired
color: ColorProducerRequiredThe text color. Default: taken from style, or else from the surrounding component.
In the "changing color" forms, pass a function that returns the color. This avoids recomposing while the color animates.
Same as above: text, modifier, autoSize, fontSize, fontStyle, fontWeight, fontFamily, letterSpacing, textDecoration, textAlign, lineHeight, overflow, softWrap, maxLines, minLines, onTextLayout, style.
Styled text
Takes an AnnotatedString, with different styles in one text.
@Composable
fun Text(
text: AnnotatedString,
modifier: Modifier = Modifier,
color: Color = Color.Unspecified,
autoSize: TextAutoSize? = null,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current,
)
text: AnnotatedStringRequired
text: AnnotatedStringRequiredThe text to show. A String, or an AnnotatedString for mixed styles.

Text(
buildAnnotatedString {
append("Delivery ")
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) { append("tomorrow") }
append(", before ")
withStyle(SpanStyle(color = MaterialTheme.colorScheme.primary)) { append("12:00") }
},
)
inlineContent: Map<String, InlineTextContent>Optional
inlineContent: Map<String, InlineTextContent>OptionalDefault: mapOf()
Composables placed inside the text, like small icons. Used with appendInlineContent in an AnnotatedString.
onTextLayout: (TextLayoutResult) -> UnitOptional
onTextLayout: (TextLayoutResult) -> UnitOptionalDefault: {}
Called with the text layout after it is measured, for example to find out if the text was cut off.
Same as above: modifier, color, autoSize, fontSize, fontStyle, fontWeight, fontFamily, letterSpacing, textDecoration, textAlign, lineHeight, overflow, softWrap, maxLines, minLines, style.
Styled text, changing color
AnnotatedString with color as a function.
@Composable
fun Text(
text: AnnotatedString,
color: ColorProducer,
modifier: Modifier = Modifier,
autoSize: TextAutoSize? = null,
fontSize: TextUnit = TextUnit.Unspecified,
fontStyle: FontStyle? = null,
fontWeight: FontWeight? = null,
fontFamily: FontFamily? = null,
letterSpacing: TextUnit = TextUnit.Unspecified,
textDecoration: TextDecoration? = null,
textAlign: TextAlign? = null,
lineHeight: TextUnit = TextUnit.Unspecified,
overflow: TextOverflow = TextOverflow.Clip,
softWrap: Boolean = true,
maxLines: Int = Int.MAX_VALUE,
minLines: Int = 1,
inlineContent: Map<String, InlineTextContent> = mapOf(),
onTextLayout: (TextLayoutResult) -> Unit = {},
style: TextStyle = LocalTextStyle.current,
)
Same as above: text, color, modifier, autoSize, fontSize, fontStyle, fontWeight, fontFamily, letterSpacing, textDecoration, textAlign, lineHeight, overflow, softWrap, maxLines, minLines, inlineContent, onTextLayout, style.