<h2 id="aspectratio-matchheightconstraintsfirst">aspectRatio</h2>

<div class='sourceset sourceset-android'>Android</div>

```kotlin
public fun SubspaceModifier.aspectRatio(
    @FloatRange(from = 0.0, fromInclusive = false) ratio: Float,
    matchHeightConstraintsFirst: Boolean = false,
): SubspaceModifier
```

Attempts to size the content to match a specified aspect ratio by trying to match one of the
incoming constraints in the following order: [VolumeConstraints.maxWidth](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints),
[VolumeConstraints.maxHeight](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints), [VolumeConstraints.minWidth](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints), [VolumeConstraints.minHeight](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints) if
`matchHeightConstraintsFirst` is `false` (which is the default), or
[VolumeConstraints.maxHeight](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints), [VolumeConstraints.maxWidth](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints), [VolumeConstraints.minHeight](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints),
[VolumeConstraints.minWidth](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints) if `matchHeightConstraintsFirst` is `true`. The size in the other
dimension is determined by the aspect ratio. The combinations will be tried in this order until
one non-empty is found to satisfy the constraints. If no valid size is obtained this way, it
means that there is no non-empty size satisfying both the constraints and the aspect ratio, so
the constraints will not be respected and the content will be sized such that the
[VolumeConstraints.maxWidth](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints) or [VolumeConstraints.maxHeight](/jetpack-compose/androidx.xr.compose/compose/classes/VolumeConstraints) is matched (depending on
`matchHeightConstraintsFirst`). Note that this modifier constrains the ratio between the
content's width and height only. The depth dimension is not affected or constrained by this
aspect ratio modifier.

```kotlin
SpatialPanel(SubspaceModifier.width(100.dp).aspectRatio(16f / 9f)) {   Text(text = "Inner Composable Content")
}
```

#### Parameters

| | |
| --- | --- |
| ratio | the desired width/height positive ratio |
| matchHeightConstraintsFirst | if true, height constraints will be matched before width constraints and used to calculate the resulting size according to `ratio` |