Class

SpanStyle

Styling configuration that applies at the character level.

Source set: Common
public class SpanStyle : AnnotatedString.Annotation

Styling configuration that applies at the character level.

Use SpanStyle to configure character-level styles such as text color, font size, font family, background color, and text decorations.

For paragraph-level styling (e.g., alignment, line height), see ParagraphStyle.

Properties

fontSize

Source set: Common
public val fontSize: TextUnit

Glyph size. If TextUnit.Unspecified, inherits size from parent or default style.

letterSpacing

Source set: Common
public val letterSpacing: TextUnit

Amount of space (in SP or EM) to add between letters. If TextUnit.Unspecified, inherits from parent.

fontWeight

Source set: Common
public val fontWeight: FontWeight?

Typeface thickness (e.g., bold).

fontFamily

Source set: Common
public val fontFamily: FontFamily?

Font family for rendering.

color

Source set: Common
public val color: Color

Color to draw text.

brush

Source set: Common
public val brush: Brush?

Brush to draw text. If not null, overrides color.

alpha

Source set: Common
public val alpha: Float

Opacity of text. This value is either provided along side Brush, or via alpha channel in color.

fontStyle

Source set: Common
public val fontStyle: FontStyle?

Typeface variant (e.g., italic).

fontSynthesis

Source set: Common
public val fontSynthesis: FontSynthesis?

Font synthesis rules to fallback to bold/italic if the requested style is missing in fontFamily.

fontFeatureSettings

Source set: Common
public val fontFeatureSettings: String?

Advanced font features in CSS format (e.g., "smcp" for small caps).

baselineShift

Source set: Common
public val baselineShift: BaselineShift?

Vertical shift amount from the baseline (e.g., for superscript or subscript).

textGeometricTransform

Source set: Common
public val textGeometricTransform: TextGeometricTransform?

Geometric transformation to apply.

localeList

Source set: Common
public val localeList: LocaleList?

Locale list for region-specific glyphs.

background

Source set: Common
public val background: Color

Color of background rectangle covering entire line height from start to end.

textDecoration

Source set: Common
public val textDecoration: TextDecoration?

Decorations (e.g., underline).

shadow

Source set: Common
public val shadow: Shadow?

Shadow effect.

platformStyle

Source set: Common
public val platformStyle: PlatformSpanStyle?

Platform-specific parameters.

drawStyle

Source set: Common
public val drawStyle: DrawStyle?

Drawing style (fill or stroke).

Functions

merge

Source set: Common
public fun merge(other: SpanStyle? = null): SpanStyle

Returns a new span style that is a combination of this style and the given other style.

other span style's null or inherit properties are replaced with the non-null properties of this span style. Another way to think of it is that the "missing" properties of the other style are filled by the properties of this style.

If the given span style is null, returns this span style.

Parameters

other style to merge

plus

Source set: Common
@Stable public operator fun plus(other: SpanStyle): SpanStyle

Plus operator overload that applies a merge.

copy

Source set: Common
@Deprecated(
        "SpanStyle copy constructors that do not take new stable parameters " +
            "like PlatformStyle, DrawStyle are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
    ): SpanStyle

copy

Source set: Common
@Deprecated(
        "SpanStyle copy constructors that do not take new stable parameters " +
            "like PlatformStyle, DrawStyle are deprecated. Please use the new stable " +
            "copy constructor.",
        level = DeprecationLevel.HIDDEN,
    )
    public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
    ): SpanStyle

copy

Source set: Common
public fun copy(
        color: Color = this.color,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
        drawStyle: DrawStyle? = this.drawStyle,
    ): SpanStyle

copy

Source set: Common
public fun copy(
        brush: Brush?,
        alpha: Float = this.alpha,
        fontSize: TextUnit = this.fontSize,
        fontWeight: FontWeight? = this.fontWeight,
        fontStyle: FontStyle? = this.fontStyle,
        fontSynthesis: FontSynthesis? = this.fontSynthesis,
        fontFamily: FontFamily? = this.fontFamily,
        fontFeatureSettings: String? = this.fontFeatureSettings,
        letterSpacing: TextUnit = this.letterSpacing,
        baselineShift: BaselineShift? = this.baselineShift,
        textGeometricTransform: TextGeometricTransform? = this.textGeometricTransform,
        localeList: LocaleList? = this.localeList,
        background: Color = this.background,
        textDecoration: TextDecoration? = this.textDecoration,
        shadow: Shadow? = this.shadow,
        platformStyle: PlatformSpanStyle? = this.platformStyle,
        drawStyle: DrawStyle? = this.drawStyle,
    ): SpanStyle
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: