Esta página ha sido traducida del inglés por la comunidad. Aprende más y únete a la comunidad de MDN Web Docs.

View in English Always switch to English

String.prototype.fontsize()

Obsoleto

Evita usar esta característica en proyectos nuevos. HTML wrapper methods exist only for backwards compatibility. Use DOM APIs to create elements instead. Esta característica podría eliminarse de los estándares web o de los navegadores.

Considera usar en su lugar las siguientes características: DOM.

El método fontsize() crea <font> elemento HTML que muestra una cadena con el tamaño especificado.

Nota: El elemento <font> ha sido eliminado HTML5 y no se debe usar. Los desarrolladores web deben usar propiedades CSS.

Sintaxis

str.fontsize(size)

Parámetros

size

Un entero entre 1 y 7.

Descripción

Cuando especificas el tamaño como entero, estableces el tamaño de la fuente. Cuando especificas el tamaño como cadena tal como "-2", se ajusta el tamaño de la fuente al de la etiqueta <basefont>.

When you specify size as an integer, you set the font size of str to one of the 7 defined sizes. When you specify size as a string such as "-2", you adjust the font size of str relative to the size set in the <basefont> tag.

Ejemlpos

Usos fontsize()

The following example uses string methods to change the size of a string:

js
var worldString = "Hello, world";

console.log(worldString.small()); // <small>Hello, world</small>
console.log(worldString.big()); // <big>Hello, world</big>
console.log(worldString.fontsize(7)); // <font size="7">Hello, world</fontsize>

With the element.style object you can get the element's style attribute and manipulate it more generically, for example:

js
document.getElementById("yourElemId").style.fontSize = "0.7em";

Especificaciones

Especificación
ECMAScript® 2027 Language Specification
# sec-string.prototype.fontsize

Compatibilidad con navegadores

See also