Skip to content
Discussion options

You must be logged in to vote

@PrettyCoffee Here is the simple function you can use:

export default function convertPxToRems(px: number): string {
  const basicFontSize = parseFloat(
    getComputedStyle(document.querySelector("html")!).fontSize
  ) || 16;
  return `${px / basicFontSize}rem`;
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@PrettyCoffee
Comment options

@hex2r
Comment options

@hex2r
Comment options

Answer selected by PrettyCoffee
@PrettyCoffee
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants