Class

BaselineShift

Shifts the text baseline vertically (up or down).

BaselineShiftSample

@Sampled
@Composable
fun BaselineShiftSample() {
    Text(
        fontSize = 20.sp,
        text =
            buildAnnotatedString {
                append(text = "Hello")
                withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
                    append("superscript")
                    withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                        append("subscript")
                    }
                }
            },
    )
}

BaselineShiftAnnotatedStringSample

@Sampled
@Composable
fun BaselineShiftAnnotatedStringSample() {
    val annotatedString = buildAnnotatedString {
        append("Text ")
        withStyle(SpanStyle(baselineShift = BaselineShift.Superscript)) { append("Demo") }
    }
    Text(text = annotatedString)
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: