Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to get font size of an element using jQuery ?

  • Last Updated : 20 Jan, 2022

In this article, we will see how to get the font size of an element using jQuery. To get the font size of an element, we will use css() method. The css() method is used to set or return the style property of the selected element.


var style = $(selector).css(property)

Return value: This method returns the value of the style property for the selected element.

Approach: In the below example, we will create a div element that contains some text and add some CSS styles (font-size) on it. Also, we will create a button element. When the user clicks on the button, the css() method is called and this method returns the font-size property of the div element.



<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <!-- Including jQuery -->
    <script src="
        h1 {
            color: green;
        #content {
            font-size: 24px;
        <h1 style="color: green;">
            How to get font size of 
            an element using jQuery?
        <div id="content">
            Welcome to GeeksforGeeks
        <button>Get the font size</button>
        $(document).ready(function () {
            $('button').click(function () {
                var fs = $("#content").css("fontSize");
                alert("Font Size of div Element: " + fs);


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!