Composables
Components Unstyled Icons API
Join Radar
Join Radar Components Unstyled Icons API UI Kit UI Blocks SVG to Compose Android Distribution Community Docs Blog Colors
Classes
  • Constraints
  • Dp
  • DpOffset
  • DpRect
  • DpSize
  • ExperimentalUnitApi
  • IntOffset
  • IntRect
  • IntSize
  • LayoutDirection
  • LayoutDirection.Ltr
  • LayoutDirection.Rtl
  • TextUnit
  • TextUnitType
  • Velocity
Objects
  • ComposeUiUnitFlags
Interfaces
  • Density
  • FontScaling
Properties
  • center
  • dp
  • em
  • height
  • isFinite
  • isSpecified
  • isUnspecified
  • size
  • sp
  • width
Functions
  • coerceAtLeast
  • coerceAtMost
  • coerceIn
  • constrain
  • constrainHeight
  • Constraints
  • constrainWidth
  • Density
  • DpOffset
  • DpSize
  • IntOffset
  • IntRect
  • IntSize
  • isSatisfiedBy
  • lerp
  • max
  • min
  • minus
  • offset
  • plus
  • round
  • roundToIntRect
  • roundToIntSize
  • takeOrElse
  • TextUnit
  • times
  • toIntRect
  • toIntSize
  • toOffset
  • toRect
  • toSize
  • Velocity
Jetpack Compose / Compose UI / Compose UI Unit / Classes / Dp
Class

Dp

View Markdown Open in ChatGPT Open in Claude

Dimension value representing device-independent pixels (dp).

Compose Multiplatform

Compose Multiplatform

Ship iOS, desktop, and web apps with Compose

Ad Go Multiplatform
RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
API

Examples

DpSample

@Composable
fun DpSample() {
    Box(
        Modifier.padding(
            10.dp, // Int
            10f.dp, // Float
            20.0.dp, // Double
            10.dp,
        )
    )
}

ToPxSample

@Composable
fun ToPxSample() {
    val lineThickness = 6.dp
    Canvas(Modifier.fillMaxSize()) {
        val lineThicknessPx = lineThickness.toPx()
        inset(lineThicknessPx / 2) { drawRect(Color.Red, style = Stroke(lineThicknessPx)) }
    }
}
Constraints ← Previous DpOffset Next →

Last updated: 2026-04-23

On this page

  • DpSample
  • ToPxSample

Never miss a Jetpack Compose release

Get an alert the moment a new Jetpack Compose release is out: new APIs, new components, new things to experiment with. Straight from Google's servers.

Join 3,000+ Jetpack Compose developers. No spam, ever.