HtmlText

fun HtmlText(text: String, modifier: Modifier = Modifier, style: TextStyle = MaterialTheme.typography.bodyMedium)(source)

Renders trusted HTML content inside Compose using an Android TextView host.

The HTML is parsed with HtmlCompat.FROM_HTML_MODE_COMPACT, which supports common inline and block formatting while collapsing unnecessary whitespace. Links are interactive because the embedded TextView uses LinkMovementMethod.

Styling behavior:

  • Text color follows MaterialTheme.colorScheme.onSurface.

  • Font size uses style when specified, otherwise falls back to MaterialTheme.typography.bodyMedium.fontSize.

Prefer this component when the content source is already HTML and you need clickable links. Prefer Compose Text for plain strings or rich text produced fully in Compose.

Security note: pass trusted or sanitized HTML input only.

Parameters

text

HTML string to parse and display.

modifier

Modifier applied to the host view.

style

Base text style used to derive visual typography.