px to rem converter

PHOTO EMBED

Sun Jan 11 2026 15:03:15 GMT+0000 (Coordinated Universal Time)

Saved by @SoulDee #typescript

// px -> rem 转换
const pxToRem = (px: number, base: number) => {
  if (base === 0) return "0";
  return (px / base).toFixed(4).replace(/\.?0+$/, "");
};

// rem -> px 转换
const remToPx = (rem: number, base: number) => {
  return (rem * base).toFixed(2).replace(/\.?0+$/, "");
};
content_copyCOPY

any
https://px2rem.com/