Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>px2unitNew to Visual Studio Code? Get it now.
px2unit

px2unit

kkopite

|
236 installs
| (0) | Free
transform px to other unit
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

px2unit

中文版本

convert px to other unit,like vw、rem...

preview

Support Languages

  • html
  • vue
  • css
  • less
  • scss
  • sass
  • stylus
  • tpl(php smarty3)
  • tsx
  • jsx

Configurations

💡 All fields must be prefixed with px2unit. in settings

field Default Description
fixedDigits 2 decimal point maximum length
autoRemovePrefixZero true Automatically remove prefix 0
addMark false Whether to enabled mark
ingores [] Ignore file list
languages ['html', 'vue', 'css', 'postcss', 'less', 'scss', 'sass', 'stylus', 'javascriptreact', 'typescriptreact' ] Support language list

px2unit.transformRules

this field is an array with the follow object

interface TransformRules {
  title?: string;
  sourceWidth: number;
  destinationWidth: number;
  unit: string;
}

the transform rule is simple, if you print 1px, it will auto show the convert value(${1 * destinationWidth/sourceWidth}${unit})

for example, if you use Viewport Width(vw) and your design width is 375px,you can use the follow Configurations

{
  "px2unit": {
    "transformRules": [
      {
        "sourceWidth": 375,
        "destinationWidth": 100,
        "unit": "vw"
      }
    ]
  }
}

and it will auto convert what you want

demo1

default transformRules

[
  {
    sourceWidth: 375,
    destinationWidth: 10,
    unit: 'rem'
  },
  {
    sourceWidth: 375,
    destinationWidth: 100,
    unit: 'vw'
  },
  {
    sourceWidth: 375,
    destinationWidth: 750,
    unit: 'rpx'
  }
]

Thanks

  • vscode-cssrem
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft