Configure text layout
Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to configure your text layout with parameters like
maxLines
and overflow
.
Limit visible lines
To limit the number of visible lines in a Text
composable, set the maxLines
parameter:
@Composable
fun LongText() {
Text("hello ".repeat(50), maxLines = 2)
}
Indicate text overflow
When limiting a long text, you may want to indicate a TextOverflow
,
which is only shown if the displayed text is truncated. To do so, set the
textOverflow
parameter:
@Composable
fun OverflowedText() {
Text("Hello Compose ".repeat(50), maxLines = 2, overflow = TextOverflow.Ellipsis)
}
Recommended for you
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-26 UTC."],[],[],null,["This page describes how to configure your text layout with parameters like\n`maxLines` and `overflow`.\n\nLimit visible lines\n\nTo limit the number of visible lines in a `Text` composable, set the `maxLines`\nparameter:\n\n\n```kotlin\n@Composable\nfun LongText() {\n Text(\"hello \".repeat(50), maxLines = 2)\n}https://github.com/android/snippets/blob/f95ab59fad80aeaf5d6a90bab8a01a126f20f44e/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L279-L282\n```\n\n\u003cbr /\u003e\n\nIndicate text overflow\n\nWhen limiting a long text, you may want to indicate a [`TextOverflow`](/reference/kotlin/androidx/compose/ui/text/style/TextOverflow),\nwhich is only shown if the displayed text is truncated. To do so, set the\n`textOverflow` parameter:\n\n\n```kotlin\n@Composable\nfun OverflowedText() {\n Text(\"Hello Compose \".repeat(50), maxLines = 2, overflow = TextOverflow.Ellipsis)\n}https://github.com/android/snippets/blob/f95ab59fad80aeaf5d6a90bab8a01a126f20f44e/compose/snippets/src/main/java/com/example/compose/snippets/text/TextSnippets.kt#L288-L291\n```\n\n\u003cbr /\u003e\n\nRecommended for you\n\n- Note: link text is displayed when JavaScript is off\n- [Graphics in Compose](/develop/ui/compose/graphics/draw/overview)\n- [Style paragraph](/develop/ui/compose/text/style-paragraph)\n- [Work with fonts](/develop/ui/compose/text/fonts)"]]