# SpanStyle

Artifact: [androidx.compose.ui:ui-text](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/text/SpanStyle.kt+class:androidx.compose.ui.text.SpanStyle) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  class SpanStyle : AnnotatedString.Annotation
  ```

*** ** * ** ***

Styling configuration that applies at the character level.

Use `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle`.

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

Text(
    fontSize = 16.sp,
    text =
        buildAnnotatedString {
            withStyle(style = SpanStyle(color = Color.Red)) { append("Hello") }
            withStyle(SpanStyle(color = Color.Blue)) { append(" World") }
        },
)
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

val brushColors = listOf(Color.Red, Color.Blue, Color.Green, Color.Yellow)
Text(
    fontSize = 16.sp,
    text =
        buildAnnotatedString {
            withStyle(SpanStyle(brush = Brush.radialGradient(brushColors))) { append("Hello") }
            withStyle(SpanStyle(brush = Brush.radialGradient(brushColors.asReversed()))) {
                append(" World")
            }
        },
)
```

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString

buildAnnotatedString {
    append("Hello")
    // push green text style so that any appended text will be green
    pushStyle(SpanStyle(color = Color.Green))
    // append new text, this text will be rendered as green
    append(" World")
    // pop the green style
    pop()
    // append a string without style
    append("!")
    // then style the last added word as red, exclamation mark will be red
    addStyle(SpanStyle(color = Color.Red), "Hello World".length, this.length)

    toAnnotatedString()
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/AnnotatedString` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#SpanStyle(androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)( color: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight?, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle?, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis?, fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift?, textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform?, localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList?, background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration?, shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow?, platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle?, drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? )` Styling configuration for text spans. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#SpanStyle(androidx.compose.ui.graphics.Brush,kotlin.Float,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)( brush: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush?, alpha: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight?, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle?, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis?, fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift?, textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform?, localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList?, background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration?, shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow?, platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle?, drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? )` Styling configuration for text spans. | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#copy(androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)( color: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight?, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle?, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis?, fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift?, textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform?, localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList?, background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration?, shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow?, platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle?, drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? )` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#copy(androidx.compose.ui.graphics.Brush,kotlin.Float,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)( brush: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush?, alpha: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight?, fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle?, fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis?, fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?, fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit, baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift?, textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform?, localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList?, background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color, textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration?, shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow?, platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle?, drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? )` | Cmn |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#hashCode()()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle?)` Returns a new span style that is a combination of this style and the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)` style. | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#plus(androidx.compose.ui.text.SpanStyle)(other: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle)` Plus operator overload that applies a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#alpha()` Opacity of text. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#background()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#baselineShift()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#brush()` Brush to draw text. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#color()` Color to draw text. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#drawStyle()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontFamily()` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontFeatureSettings()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontSize()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontStyle()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontSynthesis()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#fontWeight()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#letterSpacing()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#localeList()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#platformStyle()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#shadow()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#textDecoration()` | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#textGeometricTransform()` | Cmn |

## Public constructors

### SpanStyle

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
SpanStyle(
    color: Color = Color.Unspecified,
    fontSize: TextUnit = TextUnit.Unspecified,
    fontWeight: FontWeight? = null,
    fontStyle: FontStyle? = null,
    fontSynthesis: FontSynthesis? = null,
    fontFamily: FontFamily? = null,
    fontFeatureSettings: String? = null,
    letterSpacing: TextUnit = TextUnit.Unspecified,
    baselineShift: BaselineShift? = null,
    textGeometricTransform: TextGeometricTransform? = null,
    localeList: LocaleList? = null,
    background: Color = Color.Unspecified,
    textDecoration: TextDecoration? = null,
    shadow: Shadow? = null,
    platformStyle: PlatformSpanStyle? = null,
    drawStyle: DrawStyle? = null
)
```

Styling configuration for text spans.

Configures 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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle`.

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

Text(
    fontSize = 16.sp,
    text =
        buildAnnotatedString {
            withStyle(style = SpanStyle(color = Color.Red)) { append("Hello") }
            withStyle(SpanStyle(color = Color.Blue)) { append(" World") }
        },
)
```

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString

buildAnnotatedString {
    append("Hello")
    // push green text style so that any appended text will be green
    pushStyle(SpanStyle(color = Color.Green))
    // append new text, this text will be rendered as green
    append(" World")
    // pop the green style
    pop()
    // append a string without style
    append("!")
    // then style the last added word as red, exclamation mark will be red
    addStyle(SpanStyle(color = Color.Red), "Hello World".length, this.length)

    toAnnotatedString()
}
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

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")
                }
            }
        },
)
```

| Parameters |
|---|---|
| `color: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color = Color.Unspecified` | color to apply to the text |
| `fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit = TextUnit.Unspecified` | glyph size. If `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`, inherits size from parent or default style. |
| `fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight? = null` | typeface thickness (e.g., bold) |
| `fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle? = null` | typeface variant (e.g., italic) |
| `fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis? = null` | font synthesis rules to fallback to bold/italic if the requested style is missing in `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#(androidx.compose.ui.graphics.Color,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)` |
| `fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily? = null` | font family for rendering |
| `fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | advanced font features in CSS format (e.g., "smcp" for small caps) |
| `letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit = TextUnit.Unspecified` | amount of space (in SP or EM) to add between letters. If `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`, inherits from parent. |
| `baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift? = null` | vertical shift amount from the baseline (e.g., for superscript or subscript) |
| `textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform? = null` | geometric transformation to apply |
| `localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList? = null` | locale list for region-specific glyphs |
| `background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color = Color.Unspecified` | color of background rectangle covering entire line height from start to end |
| `textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration? = null` | decorations (e.g., underline) |
| `shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow? = null` | shadow effect |
| `platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle? = null` | platform-specific parameters |
| `drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? = null` | drawing style (fill or stroke) |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/AnnotatedString` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle` |   |

### SpanStyle

Cmn Added in [1.9.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.9.0)

```
SpanStyle(
    brush: Brush?,
    alpha: Float = Float.NaN,
    fontSize: TextUnit = TextUnit.Unspecified,
    fontWeight: FontWeight? = null,
    fontStyle: FontStyle? = null,
    fontSynthesis: FontSynthesis? = null,
    fontFamily: FontFamily? = null,
    fontFeatureSettings: String? = null,
    letterSpacing: TextUnit = TextUnit.Unspecified,
    baselineShift: BaselineShift? = null,
    textGeometricTransform: TextGeometricTransform? = null,
    localeList: LocaleList? = null,
    background: Color = Color.Unspecified,
    textDecoration: TextDecoration? = null,
    shadow: Shadow? = null,
    platformStyle: PlatformSpanStyle? = null,
    drawStyle: DrawStyle? = null
)
```

Styling configuration for text spans.

Configures character-level styles such as text brush, opacity, font size, font family, background color, and text decorations.

For paragraph-level styling (e.g., alignment, line height), see `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle`.

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

val brushColors = listOf(Color.Red, Color.Blue, Color.Green, Color.Yellow)
Text(
    fontSize = 16.sp,
    text =
        buildAnnotatedString {
            withStyle(SpanStyle(brush = Brush.radialGradient(brushColors))) { append("Hello") }
            withStyle(SpanStyle(brush = Brush.radialGradient(brushColors.asReversed()))) {
                append(" World")
            }
        },
)
```

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString

buildAnnotatedString {
    append("Hello")
    // push green text style so that any appended text will be green
    pushStyle(SpanStyle(color = Color.Green))
    // append new text, this text will be rendered as green
    append(" World")
    // pop the green style
    pop()
    // append a string without style
    append("!")
    // then style the last added word as red, exclamation mark will be red
    addStyle(SpanStyle(color = Color.Red), "Hello World".length, this.length)

    toAnnotatedString()
}
```

```kotlin
import androidx.compose.material3.Text
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.BaselineShift
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.sp

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")
                }
            }
        },
)
```

| Parameters |
|---|---|
| `brush: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Brush` for painting text, null for unspecified |
| `alpha: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = Float.NaN` | opacity applied to `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#(androidx.compose.ui.graphics.Brush,kotlin.Float,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)` (0.0 to 1.0) |
| `fontSize: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit = TextUnit.Unspecified` | glyph size. If `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`, inherits size from parent or default style. |
| `fontWeight: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontWeight? = null` | typeface thickness (e.g., bold) |
| `fontStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontStyle? = null` | typeface variant (e.g., italic) |
| `fontSynthesis: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontSynthesis? = null` | font synthesis rules to fallback to bold/italic if the requested style is missing in `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#(androidx.compose.ui.graphics.Brush,kotlin.Float,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.font.FontWeight,androidx.compose.ui.text.font.FontStyle,androidx.compose.ui.text.font.FontSynthesis,androidx.compose.ui.text.font.FontFamily,kotlin.String,androidx.compose.ui.unit.TextUnit,androidx.compose.ui.text.style.BaselineShift,androidx.compose.ui.text.style.TextGeometricTransform,androidx.compose.ui.text.intl.LocaleList,androidx.compose.ui.graphics.Color,androidx.compose.ui.text.style.TextDecoration,androidx.compose.ui.graphics.Shadow,androidx.compose.ui.text.PlatformSpanStyle,androidx.compose.ui.graphics.drawscope.DrawStyle)` |
| `fontFamily: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/font/FontFamily? = null` | font family for rendering |
| `fontFeatureSettings: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? = null` | advanced font features in CSS format (e.g., "smcp" for small caps) |
| `letterSpacing: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit = TextUnit.Unspecified` | amount of space (in SP or EM) to add between letters. If `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit#Unspecified()`, inherits from parent. |
| `baselineShift: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/BaselineShift? = null` | vertical shift amount from the baseline (e.g., for superscript or subscript) |
| `textGeometricTransform: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextGeometricTransform? = null` | geometric transformation to apply |
| `localeList: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/intl/LocaleList? = null` | locale list for region-specific glyphs |
| `background: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color = Color.Unspecified` | color of background rectangle covering entire line height from start to end |
| `textDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/style/TextDecoration? = null` | decorations (e.g., underline) |
| `shadow: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Shadow? = null` | shadow effect |
| `platformStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/PlatformSpanStyle? = null` | platform-specific parameters |
| `drawStyle: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawStyle? = null` | drawing style (fill or stroke) |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/AnnotatedString` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/TextStyle` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/ParagraphStyle` |   |

## Public functions

### copy

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
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

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
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
```

### equals

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### merge

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
fun merge(other: SpanStyle? = null): SpanStyle
```

Returns a new span style that is a combination of this style and the given `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)` style.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)` 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 `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)` style are *filled* by the properties of this style.

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

| Parameters |
|---|---|
| `other: https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle? = null` | style to merge |

### plus

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
operator fun plus(other: SpanStyle): SpanStyle
```

Plus operator overload that applies a `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#merge(androidx.compose.ui.text.SpanStyle)`.

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### alpha

Cmn Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.3.0)

```
val alpha: Float
```

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

### background

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val background: Color
```

### baselineShift

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val baselineShift: BaselineShift?
```

### brush

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val brush: Brush?
```

Brush to draw text. If not null, overrides `https://developer.android.com/reference/kotlin/androidx/compose/ui/text/SpanStyle#color()`.

### color

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val color: Color
```

Color to draw text.

### drawStyle

Cmn Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.4.0)

```
val drawStyle: DrawStyle?
```

### fontFamily

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontFamily: FontFamily?
```

### fontFeatureSettings

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontFeatureSettings: String?
```

### fontSize

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontSize: TextUnit
```

### fontStyle

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontStyle: FontStyle?
```

### fontSynthesis

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontSynthesis: FontSynthesis?
```

### fontWeight

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val fontWeight: FontWeight?
```

### letterSpacing

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val letterSpacing: TextUnit
```

### localeList

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val localeList: LocaleList?
```

### platformStyle

Cmn Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.2.0)

```
val platformStyle: PlatformSpanStyle?
```

### shadow

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val shadow: Shadow?
```

### textDecoration

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val textDecoration: TextDecoration?
```

### textGeometricTransform

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val textGeometricTransform: TextGeometricTransform?
```