# convert-css-length

> Convert between css lengths e.g. em->px or px->rem

Latest version **2.0.1** (published 2019-07-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install convert-css-length
pnpm add convert-css-length
yarn add convert-css-length
bun add convert-css-length
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2019-07-09 |
| First published | 2015-02-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Kyle Mathews |
| Maintainers | kylemathews |
| Keywords | css, css, length, convert, units, sass, compass |

## Links

- npm: https://www.npmjs.com/package/convert-css-length
- Repository: https://github.com/KyleAMathews/convert-css-length
- Issues: https://github.com/KyleAMathews/convert-css-length/issues
- npm.io page: https://npm.io/package/convert-css-length

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2019-07-09
- 2.0.0 — 2019-06-01
- 1.0.2 — 2018-04-24
- 1.0.1 — 2015-02-11
- 1.0.0 — 2015-02-11

## README

# convert-css-length
Convert between css lengths e.g. em->px or px->rem

Conversions between em, ex, rem, px are supported. PRs welcome if
you need support for more esoteric length units.

*[Note: algorithm was originally ported from Compass] (https://github.com/Compass/compass/blob/master/core/stylesheets/compass/typography/_units.scss)*

## Install
`npm install convert-css-length`

## Usage
```javascript
import convertLength from 'convert-css-length';

// Set the baseFontSize for your project. Defaults to 16px (also the
// browser default).
var convert = convertLength('21px');

// Convert rem to px.
convert('1rem', 'px');
// ---> 21px

// Convert px to em.
convert('30px', 'em');
// ---> 1.42857em

// Convert em to pixels using fromContext.
// em(s) are relative to the font-size at the same element. If you're setting an em on a element whose font-size
// is different than the base font size, you'll need to pass that font-size as the third parameter.
// Or just use rem instead which sizes everything relative to the base node.
convert('1em', 'px', '14px')
// ---> 14px
```

---
_Source: https://npm.io/package/convert-css-length · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
