Get the default font size

📰 Medium · Programming

Learn how to get the default font size in a browser using the 'medium' CSS keyword, which bypasses stylesheet overrides and reads the browser setting directly.

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 temporary div element from 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 different user settings and devices.

Key Insight

💡 The 'medium' CSS keyword is the only reliable way to read the true default font size in a browser, as it bypasses stylesheet overrides and reads the browser setting directly.

Share This
🔍 Get the default font size in a browser using the 'medium' CSS keyword! 💡 Bypass stylesheet overrides and read the browser setting directly.
Read full article → ← Back to Reads