How to make a text italic in JavaScript?

To make italic text, we have two methods, first one is style.fontStyle, and the italics() method.

The property sets or returns whether the style of the font is normal, italic, or oblique.

Method 1: Using style.fontStyle


<!DOCTYPE html>

<p id="text_id">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever</p>

<button onclick="myfunction()">make italic</button>



function myfunction() {
   	document.getElementById("text_id").style.fontStyle = "italic";

Method 2: Using  italics() method

We can also use the javascript italics() method. The italics() method creates an <i> An HTML element that causes a string to be italic.

      <title>JavaScript String italics() Method</title>

         var str = new String("Demo Text");