1# Pixel Units 2 3ArkUI provides four pixel units, with vp as the reference data unit. 4 5>**NOTE** 6> 7>The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10| Name| Description | 11| ---- | ------------------------------------------------------------ | 12| px | Physical pixel unit of the screen. | 13| vp | Pixel unit specific to the screen density. Pixels in this unit are converted into physical pixels of the screen based on the screen pixel density. This unit is used for values whose unit is not specified.<br> **NOTE**<br>The ratio of vp to px is subject to the screen pixel density.| 14| fp | Font pixel, which is similar to vp and varies according to the system font size.| 15| lpx | Logical pixel unit of the window. It is the ratio of the actual screen width to the logical width (configured by [designWidth](../../../quick-start/module-configuration-file.md#pages)). For example, if **designWidth** is set to **720** (default value), then 1 lpx is equal to 2 px for a screen with an actual width of 1440 physical pixels.| 16 17 18## Pixel Unit Conversion 19 20Conversion between px and other pixel units is supported. 21 22**Widget capability**: This API can be used in ArkTS widgets since API version 9. 23 24**Atomic service API**: This API can be used in atomic services since API version 11. 25 26**System capability**: SystemCapability.ArkUI.ArkUI.Full 27 28| API | Description | 29| ---------------------------------------- | ---------------------------------------- | 30| vp2px(value : number) : number | Converts a value in units of vp to a value in units of px.<br>This API can be used in ArkTS widgets since API version 9.<br> **NOTE**<br> By default, the virtual pixel ratio of the screen where the current UI instance is located is used for conversion. If no UI instance is available, the virtual pixel ratio of the default screen is used instead.| 31| px2vp(value : number) : number | Converts a value in units of px to a value in units of vp.<br>This API can be used in ArkTS widgets since API version 9.<br> **NOTE**<br> By default, the virtual pixel ratio of the screen where the current UI instance is located is used for conversion. If no UI instance is available, the virtual pixel ratio of the default screen is used instead.| 32| fp2px(value : number) : number | Converts a value in units of fp to a value in units of px.<br>This API can be used in ArkTS widgets since API version 9.| 33| px2fp(value : number) : number | Converts a value in units of px to a value in units of fp.<br>This API can be used in ArkTS widgets since API version 9.| 34| lpx2px(value : number) : number | Converts a value in units of lpx to a value in units of px.<br>This API can be used in ArkTS widgets since API version 9.| 35| px2lpx(value : number) : number | Converts a value in units of px to a value in units of lpx.<br>This API can be used in ArkTS widgets since API version 9.| 36 37 38## Example 39 40```ts 41// xxx.ets 42@Entry 43@Component 44struct Example { 45 build() { 46 Column() { 47 Flex({ wrap: FlexWrap.Wrap }) { 48 Column() { 49 Text("width(220)") 50 .width(220) 51 .height(40) 52 .backgroundColor(0xF9CF93) 53 .textAlign(TextAlign.Center) 54 .fontColor(Color.White) 55 .fontSize('12vp') 56 }.margin(5) 57 58 Column() { 59 Text("width('220px')") 60 .width('220px') 61 .height(40) 62 .backgroundColor(0xF9CF93) 63 .textAlign(TextAlign.Center) 64 .fontColor(Color.White) 65 }.margin(5) 66 67 Column() { 68 Text("width('220vp')") 69 .width('220vp') 70 .height(40) 71 .backgroundColor(0xF9CF93) 72 .textAlign(TextAlign.Center) 73 .fontColor(Color.White) 74 .fontSize('12vp') 75 }.margin(5) 76 77 Column() { 78 Text("width('220lpx') designWidth:720") 79 .width('220lpx') 80 .height(40) 81 .backgroundColor(0xF9CF93) 82 .textAlign(TextAlign.Center) 83 .fontColor(Color.White) 84 .fontSize('12vp') 85 }.margin(5) 86 87 Column() { 88 Text("width(vp2px(220) + 'px')") 89 .width(vp2px(220) + 'px') 90 .height(40) 91 .backgroundColor(0xF9CF93) 92 .textAlign(TextAlign.Center) 93 .fontColor(Color.White) 94 .fontSize('12vp') 95 }.margin(5) 96 97 Column() { 98 Text("fontSize('12fp')") 99 .width(220) 100 .height(40) 101 .backgroundColor(0xF9CF93) 102 .textAlign(TextAlign.Center) 103 .fontColor(Color.White) 104 .fontSize('12fp') 105 }.margin(5) 106 107 Column() { 108 Text("width(px2vp(220))") 109 .width(px2vp(220)) 110 .height(40) 111 .backgroundColor(0xF9CF93) 112 .textAlign(TextAlign.Center) 113 .fontColor(Color.White) 114 .fontSize('12fp') 115 }.margin(5) 116 }.width('100%') 117 } 118 } 119} 120``` 121 122 123