---
title: "fillMaxWidth"
description: "Have the content fill (possibly only partially) the [Constraints.maxWidth] of the incoming
measurement constraints, by setting the [minimum width][Constraints.minWidth] and the
[maximum width][Constraints.maxWidth] to be equal to the [maximum width][Constraints.maxWidth]
multiplied by [fraction]. Note that, by default, the [fraction] is 1, so the modifier will make
the content fill the whole available width. If the incoming maximum width is
[Constraints.Infinity] this modifier will have no effect."
type: "modifier"
---

<div class='type'>Compose Modifier</div>

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


```kotlin
fun Modifier.fillMaxWidth(@FloatRange(from = 0.0, to = 1.0) fraction: Float = 1f) =
    this.then(if (fraction == 1f) FillWholeMaxWidth else FillElement.width(fraction))
```


Have the content fill (possibly only partially) the `Constraints.maxWidth` of the incoming
measurement constraints, by setting the `minimum width` and the
`maximum width` to be equal to the `maximum width`
multiplied by `fraction`. Note that, by default, the `fraction` is 1, so the modifier will make
the content fill the whole available width. If the incoming maximum width is
`Constraints.Infinity` this modifier will have no effect.

#### Parameters

| | |
| --- | --- |
| fraction | The fraction of the maximum width to use, between `0` and `1`, inclusive. |




## Code Examples
### FillHalfWidthModifier
```kotlin
@Composable
fun FillHalfWidthModifier() {
    Box(Modifier.requiredSize(100.dp).background(Color.Red), contentAlignment = Alignment.Center) {
        // The inner Box will be (50.dp x 30.dp).
        Box(
            Modifier.fillMaxWidth(fraction = 0.5f)
                .requiredHeight(30.dp)
                .background(color = Color.Magenta)
        )
    }
}
```
### SimpleFillWidthModifier
```kotlin
@Composable
fun SimpleFillWidthModifier() {
    Box(Modifier.fillMaxWidth().background(Color.Red), contentAlignment = Alignment.Center) {
        Box(Modifier.size(100.dp).background(color = Color.Magenta))
    }
}
```

