In this tutorial we will learn how to Get Font Size of any Tag with JavaScript. JavaScript and HTML codes are give below.
Table of Contents
HTML Code
HTML Code is given below.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Get Font Size using JavaScript</title>
</head>
<body>
<p id="text">Get My Font Size</p>
<button onclick="getFontSize()">Get Font Size</button>
<script src="script.js"></script>
</body>
</html>
JavaScript Code
Take a look at the JavaScript code given below.
<script>
function getFontSize(){
var fontSize = window.getComputedStyle(document.getElementById("text")).fontSize;
alert(fontSize);
}
</script>
Video Tutorial
Watch video tutorial on How To Get Font Size of any Tag using JavaScript.