Skip to content

Instantly share code, notes, and snippets.

@miladd3
miladd3 / remCalc.ts
Last active June 27, 2024 11:36
Javascript px to Rem function
/**
* Converts pixel size to rem and accepts the base as second argument. default base is 16px
*
* @param {number|string} px
* @param {number} base
* @return {string}
*/
const remCalc = (px: number | string, base: number = 16) => {
const tempPx = `${px}`.replace('px', '')