Open In App

How to change font size using jQuery ?

Last Updated : 15 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to change the font size of an element using jQuery. To change the font size of an element, we will use css() method

The css() method is used to change the style property of the selected element.

Syntax:

$(selector).css(property)

Return value: It will return the value of the property for the selected element. 

In the below example, we have created a div element that contains some text and also created a button element. When the user clicks on the button, the CSS () method is called and this method sets the font-size property value to 32px.

Example: In this example, we will see the use of the CSS method.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
    <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="
    </script>
</head>
<body>
    <center>
        <h1 style="color: green;">
            GeeksforGeeks
        </h1>
        <h3>
            How to change font size using jQuery?
        </h3>
        <div id="content">Welcome to GeeksforGeeks</div>
        <br>
        <button>Change font size</button>
    </center>
    <script>
        $(document).ready(function() {
            $('button').click(function() {
                $("#content").css("fontSize", "32px");
            });
        });
    </script>
</body>
</html>


Output: 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads