JavaScript String fontsize() Method
In JavaScript, fontsize() function of string values, one can have a string, where this string is included in the <font> tag with str being defined as (<font size="size">str</font>) so that we can set the font size of the text in the string. However, it is usually advisable to use for formatting text, although HTML5 also supports it.
Note: String fontsize() is deprecated in JavaScript.
Syntax
string.fontsize(size)
Parameters:
size
: A string or number representing the font size, valid values are from "1" to "7" or any CSS-compatible size.
Return Value:
A string embedded within a <font> tag that features a certain size.
Example 1: In the example below, we will see the basic usage of the fontsize()
method.
let str = "Hello, World!";
console.log(str.fontsize(4));
Output
<font size="4">Hello, World!</font>
Example 2: In the example below, we will use the fontsize()
method with a concatenated string.
let str1 = "Hello, ";
let str2 = "World!";
console.log((str1 + str2).fontsize(7));
Output
<font size="7">Hello, World!</font>
Example 3: In the example below, we will use nested HTML tags with the fontsize()
method.
let str = "Hello, <em>World!</em>";
console.log(str.fontsize(3));
Output
<font size="3">Hello, <em>World!</em></font>