Get the default font size

📰 Medium · JavaScript

Learn how to get the default font size in the browser using JavaScript, which is useful for rendering text inside canvas elements

intermediate Published 17 Apr 2026
Action Steps
  1. Create a temporary div element using document.createElement('div')
  2. Set the font size of the div element to 'medium' using el.style.fontSize = 'medium'
  3. Append the div element to the body of the HTML document using document.body.appendChild(el)
  4. Get the computed font size of the div element using getComputedStyle(el).fontSize
  5. Remove the div element from the body of the HTML document using document.body.removeChild(el)
Who Needs to Know This

Frontend developers and designers can benefit from this knowledge to ensure consistent typography across their applications

Key Insight

💡 The 'medium' keyword in CSS directly references the browser's default font size, skipping any stylesheet overrides

Share This
💡 Get the default font size in the browser using JavaScript! Useful for rendering text inside canvas elements
Read full article → ← Back to Reads