LineBreak


Configures line breaking behavior when text wraps automatically to fit its container.

Offers presets for common use cases:

Preset Use Case
Simple Text fields and inputs
Heading Titles and short text
Paragraph Body text and long passages
import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.unit.sp

Text(
    text = "Title of an article",
    style = TextStyle(fontSize = 20.sp, lineBreak = LineBreak.Heading),
)

Text(
    text = "A long paragraph in an article",
    style = TextStyle(lineBreak = LineBreak.Paragraph),
)

Customize Android behavior using:

  • Strategy: Balances layout speed against formatting quality (e.g., greedy vs. paragraph-optimized breaking).

  • Strictness: Adjusts line-breaking rules for East Asian languages (Chinese, Japanese, and Korean), determining which characters can start or end a line.

  • WordBreak: Specifies word boundary rules, such as default spacing-based breaking or phrase-based breaking (ideal for titles).

import androidx.compose.material3.Text
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.unit.sp

val customTitleLineBreak =
    LineBreak(
        strategy = LineBreak.Strategy.Simple,
        strictness = LineBreak.Strictness.Loose,
        wordBreak = LineBreak.WordBreak.Default,
    )

Text(
    text = "Title of an article",
    style = TextStyle(fontSize = 20.sp, lineBreak = customTitleLineBreak),
)

val defaultStrictnessParagraphLineBreak =
    LineBreak.Paragraph.copy(strictness = LineBreak.Strictness.Default)

Text(
    text = "A long paragraph in an article",
    style = TextStyle(lineBreak = defaultStrictnessParagraphLineBreak),
)

Summary

Nested types

value class LineBreak.Strategy

The strategy used for line breaking.

Describes the strictness of line breaking, determining before which characters line breaks can be inserted.

Describes how line breaks should be inserted within words.

Public companion properties

LineBreak

Looser breaking rules, suitable for short text such as titles or narrow newspaper columns.

Cmn
android
LineBreak

Slower, higher quality line breaking for improved readability.

Cmn
android
LineBreak

Basic, fast line breaking.

Cmn
android
LineBreak

Represents an unset LineBreak value.

Cmn
android

Public constructors

LineBreak(
    strategy: LineBreak.Strategy,
    strictness: LineBreak.Strictness,
    wordBreak: LineBreak.WordBreak
)

This represents a configuration for line breaking on Android, describing Strategy, Strictness, and WordBreak.

android

Public functions

LineBreak
copy(
    strategy: LineBreak.Strategy,
    strictness: LineBreak.Strictness,
    wordBreak: LineBreak.WordBreak
)
android
open String
android

Extension properties

Boolean

Returns true if it is not LineBreak.Unspecified.

Cmn

Public companion properties

Heading

val HeadingLineBreak

Looser breaking rules, suitable for short text such as titles or narrow newspaper columns. For longer lines of text, use Paragraph for improved readability.

Paragraph

val ParagraphLineBreak

Slower, higher quality line breaking for improved readability. Suitable for larger amounts of text.

Simple

val SimpleLineBreak

Basic, fast line breaking. Ideal for text input fields, as it will cause minimal text reflow when editing.

Unspecified

val UnspecifiedLineBreak

Represents an unset LineBreak value.

Public constructors

LineBreak

LineBreak(
    strategy: LineBreak.Strategy,
    strictness: LineBreak.Strictness,
    wordBreak: LineBreak.WordBreak
)

This represents a configuration for line breaking on Android, describing Strategy, Strictness, and WordBreak.

Parameters
strategy: LineBreak.Strategy

defines the algorithm that inserts line breaks

strictness: LineBreak.Strictness

defines the line breaking rules

wordBreak: LineBreak.WordBreak

defines how words are broken

Public functions

copy

fun copy(
    strategy: LineBreak.Strategy = this.strategy,
    strictness: LineBreak.Strictness = this.strictness,
    wordBreak: LineBreak.WordBreak = this.wordBreak
): LineBreak

toString

open fun toString(): String

Public properties

strategy

val strategyLineBreak.Strategy

strictness

val strictnessLineBreak.Strictness

wordBreak

val wordBreakLineBreak.WordBreak

Extension properties

LineBreak.isSpecified

val LineBreak.isSpecifiedBoolean

Returns true if it is not LineBreak.Unspecified.

See also
Unspecified