# Density

Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+class:androidx.compose.ui.unit.Density) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface Density : FontScaling
  ```
Known direct subclasses [AwaitPointerEventScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope), [BlurScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/BlurScope), [CacheDrawScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope), [CustomStyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CustomStyleScope), [DrawScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope), [FlexBoxConfigScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexBoxConfigScope), [FlexConfigScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexConfigScope), [GraphicsLayerScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope), [GridConfigurationScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridConfigurationScope), [IndirectPointerInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IndirectPointerInjectionScope), [InjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope), [IntrinsicMeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope), [Placeable.PlacementScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable.PlacementScope), [PointerInputScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope), [PolygonShapeScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeScope), [PolygonShapeTransformScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope), [PressGestureScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/PressGestureScope), [RulerScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/RulerScope), [ShadowScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/ShadowScope), [StyleResolverScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolverScope), [SubspaceMeasureScope](https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceMeasureScope), [TextAutoSizeLayoutScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/modifiers/TextAutoSizeLayoutScope)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/AwaitPointerEventScope` | Receiver scope for awaiting pointer events in a call to `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope#awaitPointerEventScope(kotlin.coroutines.SuspendFunction1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/BlurScope` | Configures progressive `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/blur.modifier#(androidx.compose.ui.Modifier).blur(androidx.compose.ui.unit.Dp,androidx.compose.ui.unit.Dp,androidx.compose.ui.draw.BlurredEdgeTreatment)` layer properties. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope` | Handle to a drawing environment that enables caching of content based on the resolved size. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CustomStyleScope` | An interface that is the base interface for all styles scopes. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` | Creates a scoped drawing environment with the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexBoxConfigScope` | Receiver scope for configuring `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexBox.composable#FlexBox(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.FlexBoxConfig,kotlin.Function1)` container properties. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexConfigScope` | Scope for configuring flex item properties within a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/FlexBox.composable#FlexBox(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.FlexBoxConfig,kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope` | A scope which can be used to define the effects to apply for the content, such as scaling (`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#scaleX()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#scaleY()`), rotation (`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#rotationX()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#rotationY()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#rotationZ()`), opacity (`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#alpha()`), shadow (`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#shadowElevation()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#shape()`), and clipping (`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#clip()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/GraphicsLayerScope#shape()`). |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/GridConfigurationScope` | Scope for configuring the structure of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/layout/Grid.composable#Grid(kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/IndirectPointerInjectionScope` | The receiver scope of the indirect pointer input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performIndirectPointerInput(androidx.compose.ui.input.indirect.IndirectPointerEventPrimaryDirectionalMotionAxis,androidx.compose.ui.unit.IntSize,kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/InjectionScope` | The receiver scope for input injection lambdas that are tied to a specific node, such as `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performTouchInput(kotlin.Function1)` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performMouseInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/IntrinsicMeasureScope` | The receiver scope of a layout's intrinsic measurements lambdas. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable.PlacementScope` | Receiver scope that permits explicit placement of a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Placeable`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope` | Receiver scope for `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/pointerInput.modifier#(androidx.compose.ui.Modifier).pointerInput(kotlin.coroutines.SuspendFunction1)` that permits `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope#awaitPointerEventScope(kotlin.coroutines.SuspendFunction1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeScope` | Builds `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeGeometry` for a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape` at layout resolution. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShapeTransformScope` | Transforms a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape`'s geometry inside `https://developer.android.com/reference/kotlin/androidx/compose/foundation/shape/PolygonShape#transform(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/PressGestureScope` | Receiver scope for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.ui.input.pointer.PointerInputScope).detectTapGestures(kotlin.Function1,kotlin.Function1,kotlin.coroutines.SuspendFunction2,kotlin.Function1)`'s `onPress` lambda. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/RulerScope` | A scope used in `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope#layout(kotlin.Int,kotlin.Int,kotlin.collections.Map,kotlin.Function1)` for the `rulers` parameter to allow a layout to define `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/Ruler` values for children. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/ShadowScope` | Scope that can be used to define properties to render either a drop shadow or inner shadow. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolverScope` | The type of the scope of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleResolver#resolve(kotlin.Function1)` that allows the `block` to read the fully resolved values from a style. |
| `https://developer.android.com/reference/kotlin/androidx/xr/compose/subspace/layout/SubspaceMeasureScope` | The receiver scope of a layout's measure lambda. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/text/modifiers/TextAutoSizeLayoutScope` | An entity that allows performing text layout for auto sizing text. |

Known indirect subclasses [ApproachIntrinsicMeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachIntrinsicMeasureScope), [ApproachMeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachMeasureScope), [CanvasDrawScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope), [CommonStyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope), [ContentDrawScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/ContentDrawScope), [DragAndDropSourceScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope), [DropShadowScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/DropShadowScope), [InnerShadowScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/InnerShadowScope), [KeyInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope), [LazyLayoutMeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutMeasureScope), [MeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope), [MouseInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MouseInjectionScope), [MultiModalInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MultiModalInjectionScope), [RotaryInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/RotaryInjectionScope), [StyleScope](https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope), [SubcomposeMeasureScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeMeasureScope), [TouchInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TouchInjectionScope), [TrackpadInjectionScope](https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TrackpadInjectionScope)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachIntrinsicMeasureScope` | The receiver scope of a layout's intrinsic approach measurements lambdas. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachMeasureScope` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachMeasureScope` provides access to lookahead results to allow `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/ApproachLayoutModifierNode` to leverage lookahead results to define how measurements and placements approach their destination. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope` | Implementation of `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` that issues drawing commands into the specified canvas and bounds via `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/CanvasDrawScope#draw(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.graphics.Canvas,androidx.compose.ui.geometry.Size,kotlin.Function1)` |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope` | A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyleScope` is the scope used by a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/CommonStyle`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/ContentDrawScope` | Receiver scope for drawing content into a layout, where the content can be drawn between other canvas operations. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope` | **This interface is deprecated.** Replaced by a callback for obtain a transfer data,start detection is performed by Compose itself |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/DropShadowScope` | Scope that provides the capability to configure the properties of a drop shadow in order to support efficient transformations without recomposition |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/InnerShadowScope` | Scope that provides the capability to configure the properties of an inner shadow in order to support efficient transformations without recomposition |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/KeyInjectionScope` | The receiver scope of the key input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performKeyInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayoutMeasureScope` | The receiver scope of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/layout/LazyLayout.composable#LazyLayout(kotlin.Function0,androidx.compose.ui.Modifier,androidx.compose.foundation.lazy.layout.LazyLayoutPrefetchState,androidx.compose.foundation.lazy.layout.LazyLayoutMeasurePolicy)`'s measure lambda. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope` | The receiver scope of a layout's measure lambda. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MouseInjectionScope` | The receiver scope of the mouse input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performMouseInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/MultiModalInjectionScope` | The receiver scope of the multi-modal input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performMultiModalInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/RotaryInjectionScope` | The receiver scope of rotary input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performRotaryScrollInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope` | A `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/StyleScope` is the receiver scope of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/style/Style` lambda. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeMeasureScope` | The receiver scope of a `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/SubcomposeLayout.composable#SubcomposeLayout(androidx.compose.ui.Modifier,kotlin.Function2)`'s measure lambda which adds ability to dynamically subcompose a content during the measuring on top of the features provided by `https://developer.android.com/reference/kotlin/androidx/compose/ui/layout/MeasureScope`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TouchInjectionScope` | The receiver scope of the touch input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performTouchInput(kotlin.Function1)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/TrackpadInjectionScope` | The receiver scope of the trackpad input injection lambda from `https://developer.android.com/reference/kotlin/androidx/compose/ui/test/package-summary#(androidx.compose.ui.test.SemanticsNodeInteraction).performTrackpadInput(kotlin.Function1)`. |

*** ** * ** ***

A density of the screen. Used for the conversions between pixels, `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`, `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit`.

```kotlin
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp

val sizeInPx = with(LocalDensity.current) { 16.dp.toPx() }
```

## Summary

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).roundToPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).roundToPx()()` Convert Sp to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toDp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toDp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Dp | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.geometry.Size).toDpSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).toPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to pixels. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).toPx()()` Convert Sp to pixels. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpRect).toRect()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpSize).toSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size`. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toSp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to Sp. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toSp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Sp | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#density()` The logical density of the display. | Cmn |

### Inherited functions

From [androidx.compose.ui.unit.FontScaling](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling) `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.TextUnit).toDp()()`

Convert Sp to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`.
Cmn `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.Dp).toSp()()`

Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to Sp.
Cmn

### Inherited properties

From [androidx.compose.ui.unit.FontScaling](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#fontScale()`

Current user preference for the scaling factor for fonts.
Cmn

## Public functions

### Dp.roundToPx

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:roundToPx) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun Dp.roundToPx(): Int
```

Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding

### TextUnit.roundToPx

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:roundToPx) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun TextUnit.roundToPx(): Int
```

Convert Sp to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding

### Int.toDp

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toDp) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open fun Int.toDp(): Dp
```

Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`.

### Float.toDp

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toDp) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open fun Float.toDp(): Dp
```

Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Dp

### Size.toDpSize

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toDpSize) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun Size.toDpSize(): DpSize
```

Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize`.

### Dp.toPx

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toPx) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun Dp.toPx(): Float
```

Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to pixels. Pixels are used to paint to Canvas.

### TextUnit.toPx

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toPx) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun TextUnit.toPx(): Float
```

Convert Sp to pixels. Pixels are used to paint to Canvas.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if TextUnit other than SP unit is specified. |

### DpRect.toRect

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toRect) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open fun DpRect.toRect(): Rect
```

Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`.

### DpSize.toSize

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toSize) Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
open fun DpSize.toSize(): Size
```

Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size`.

### Int.toSp

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toSp) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open fun Int.toSp(): TextUnit
```

Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to Sp.

### Float.toSp

Cmn Artifact: [androidx.compose.ui:ui-unit](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/unit/Density.kt+function:toSp) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
open fun Float.toSp(): TextUnit
```

Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Sp

## Public properties

### density

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val density: Float
```

The logical density of the display. This is a scaling factor for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` unit.