Google is committed to advancing racial equity for Black communities. See how.

BaselineShift

@Immutable inline class BaselineShift
kotlin.Any
   ↳ androidx.compose.ui.text.style.BaselineShift

The amount by which the text is shifted up or down from current the baseline.

Summary

Public constructors
<init>(multiplier: Float)

import androidx.compose.foundation.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.withStyle

Text(
    fontSize = 20.sp,
    text = annotatedString {
        append(text = "Hello")
        withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
            append("superscript")
            withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                append("subscript")
            }
        }
    }
)

Properties
Float

shift the baseline by multiplier * (baseline - ascent)

Companion properties
BaselineShift

Constant for no baseline shift.

BaselineShift

Default baseline shift for subscript

BaselineShift

Default baseline shift for superscript.

Public constructors

<init>

BaselineShift(multiplier: Float)
import androidx.compose.foundation.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.withStyle

Text(
    fontSize = 20.sp,
    text = annotatedString {
        append(text = "Hello")
        withStyle(SpanStyle(baselineShift = BaselineShift.Superscript, fontSize = 16.sp)) {
            append("superscript")
            withStyle(SpanStyle(baselineShift = BaselineShift.Subscript)) {
                append("subscript")
            }
        }
    }
)
import androidx.compose.foundation.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.annotatedString
import androidx.compose.ui.text.withStyle

val annotatedString = annotatedString {
    append("Text ")
    withStyle(SpanStyle(baselineShift = BaselineShift.Superscript)) {
        append("Demo")
    }
}
Text(text = annotatedString)
Parameters
multiplier: Float shift the baseline by multiplier * (baseline - ascent)

Properties

multiplier

val multiplier: Float

shift the baseline by multiplier * (baseline - ascent)

Companion properties

None

@Stable val None: BaselineShift

Constant for no baseline shift.

Subscript

@Stable val Subscript: BaselineShift

Default baseline shift for subscript

Superscript

@Stable val Superscript: BaselineShift

Default baseline shift for superscript.