---
title: "contentColorFor"
description: "The Material color system contains pairs of colors that are typically used for the background and
content color inside a component. For example, a [Button] typically uses `primary` for its
background, and `onPrimary` for the color of its content (usually text or iconography).

This function tries to match the provided [backgroundColor] to a 'background' color in this
[ColorScheme], and then will return the corresponding color used for content. For example, when
[backgroundColor] is [ColorScheme.primary], this will return [ColorScheme.onPrimary].

If [backgroundColor] does not match a background color in the theme, this will return
[Color.Unspecified]."
type: "function"
---

<div class='type'>Function</div>


<a id='references'></a>
<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun ColorScheme.contentColorFor(backgroundColor: Color): Color
```


The Material color system contains pairs of colors that are typically used for the background and
content color inside a component. For example, a `Button` typically uses `primary` for its
background, and `onPrimary` for the color of its content (usually text or iconography).

This function tries to match the provided `backgroundColor` to a 'background' color in this
`ColorScheme`, and then will return the corresponding color used for content. For example, when
`backgroundColor` is `ColorScheme.primary`, this will return `ColorScheme.onPrimary`.

If `backgroundColor` does not match a background color in the theme, this will return
`Color.Unspecified`.

#### Returns

| | |
| --- | --- |
|  | the matching content color for `backgroundColor`. If `backgroundColor` is not present in the theme's `ColorScheme`, then returns `Color.Unspecified`. |




