---
title: "PolygonShape"
description: "Creates a [PolygonShape] whose geometry is defined by [builder] at layout resolution time."
type: "function"
lastmod: "2026-09-24"
---
## API Reference

### PolygonShape

> Source set: Common

```kotlin
public fun PolygonShape(builder: PolygonShapeScope.() -> PolygonShapeGeometry): PolygonShape
```

Creates a [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api) whose geometry is defined by `builder` at layout resolution time.

`builder` runs in [PolygonShapeScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/PolygonShapeScope/api) on every resolution, with access to the resolved size,
layout direction, and density; the [PolygonShapeGeometry](/jetpack-compose/androidx.compose.foundation/foundation/classes/PolygonShapeGeometry/api) it returns is the shape's definition.
Values the lambda reads are re-read on each resolution, and the outline rebuilds when the
resulting geometry changes. Two shapes created with the same `builder` instance compare equal.

Use this overload when the geometry depends on the resolved size or density, such as vertices
placed in pixels of the layout's coordinate space or rounding given in `Dp`. For a fixed geometry
that scales uniformly into any container, use the [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api) overload taking a
[PolygonShapeGeometry](/jetpack-compose/androidx.compose.foundation/foundation/classes/PolygonShapeGeometry/api).

#### Parameters

| | |
| --- | --- |
| builder | lambda run in [PolygonShapeScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/PolygonShapeScope) returning the shape's geometry |

### PolygonShape

> Source set: Common

```kotlin
public fun PolygonShape(geometry: PolygonShapeGeometry): PolygonShape
```

Creates a [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api) from `geometry` defined in an author-chosen coordinate space.

The geometry is uniformly scaled and centered to fit within the layout bounds at resolution time,
preserving its aspect ratio.

Use this overload for a fixed shape definition, such as unit-space vertices, that scales into
whatever bounds the shape is used in. To define geometry against the resolved size, layout
direction, or density instead, use the [PolygonShape](/jetpack-compose/androidx.compose.foundation/foundation/functions/PolygonShape/api) overload taking a [PolygonShapeScope](/jetpack-compose/androidx.compose.foundation/foundation/interfaces/PolygonShapeScope/api)
builder.

#### Parameters

| | |
| --- | --- |
| geometry | polygon geometry to scale and center into the layout bounds |

## Code Examples

### CustomPolygonShapeSample

```kotlin
@Sampled
@Composable
fun CustomPolygonShapeSample() {
    // A diamond built from pixel coordinates derived from the resolved layout size, with an
    // exact 8dp corner rounding.
    val diamond = remember {
        PolygonShape {
            polygon(
                vertices =
                    listOf(
                        Offset(size.width / 2f, 0f),
                        Offset(size.width, size.height / 2f),
                        Offset(size.width / 2f, size.height),
                        Offset(0f, size.height / 2f),
                    ),
                rounding = CornerRounding(radius = 8.dp),
            )
        }
    }
    Box(Modifier.size(96.dp).clip(diamond).background(Color(0xFFFF5722)))
}
```

### UnitSpacePolygonShapeSample

```kotlin
@Sampled
@Composable
fun UnitSpacePolygonShapeSample() {
    // A kite authored in the unit square [0..1] with per-vertex rounding in the same coordinate
    // space. The shape scales and centers into any container preserving its aspect ratio.
    val kite = remember {
        PolygonShape(
            PolygonShapeGeometry(
                vertices =
                    listOf(Offset(0.5f, 0f), Offset(1f, 0.4f), Offset(0.5f, 1f), Offset(0f, 0.4f)),
                perVertexRounding =
                    listOf(
                        CornerRounding(0.1f),
                        CornerRounding(0.15f),
                        CornerRounding(0.05f),
                        CornerRounding(0.15f),
                    ),
            )
        )
    }

    Box(Modifier.size(width = 120.dp, height = 84.dp).clip(kite).background(Color(0xFF673AB7)))
}
```
