Open In App

How to make a text italic using JavaScript ?

Last Updated : 25 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Javascript provides various methods to modify the text according to our need. In this article, we are going to see how we can make the text italics in javascript.

string.italics( ) is the method use to make the text italics. Basically, italics text are created by using the <i> </i> tag in the html. So, the string.italics( ) method creates an HTML element consisting of <i> </i> tag.

Syntax:

string.italics()

Here, “string” is the name of the variable.

Parameter:

This method doesn’t take any parameters.

Return Value:

This method returns a String that is embedded in an <i> element.

Example:

HTML
<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Italics Example</title>
</head>
  
<body>
    <h1>How to use italics() in Javascript</h1>
    <p id="original-text">Geeks for geeks</p>
    <p id="italic-text"></p>

    <script>
        // Original string
        let originalString = "Geeks for geeks";

        // Apply italics() method to italicize the string
        let italicString = originalString.italics();

        // Display the italicized string in the HTML
        document.getElementById("italic-text").innerHTML = italicString;
    </script>
</body>
  
</html>

Output:

Screenshot-2024-07-24-190956

Use of italics( )



Next Article

Similar Reads