Style fontSizePropiedad
Objeto Style
Definición y uso
La propiedad fontSize establece o devuelve el tamaño de fuente del texto.
Sintaxis
Establecer la propiedad fontSize:
Object.style.fontSize="value|inherit"
Devolver la propiedad fontSize:
Object.style.fontSize
| Valor | Descripción |
|---|---|
| xx-small x-small small medium large x-large xx-large |
Establece el tamaño de fuente a diferentes tamaños fijos, desde xx-small hasta xx-large. |
| smaller | Disminuye el tamaño de fuente en una unidad relativa. |
| larger | Aumenta el tamaño de fuente en una unidad relativa. |
| length | Define el tamaño de fuente usando unidades como px, cm, etc. |
| % | Define el tamaño de fuente como un porcentaje del tamaño de fuente del elemento padre. |
| inherit | El valor de la propiedad fontSize se hereda del elemento padre. |
Compatibilidad del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales admiten la propiedad fontSize.
Nota:IE7 y versiones anteriores no admiten el valor "inherit". IE8 solo admite "inherit" si se especifica !DOCTYPE. IE9 admite "inherit".
Ejemplo
Ejemplo
Cambiar el tamaño de fuente del texto:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSize="xx-large";
}
</script>
</head>
<body>
<p id="p1">Este es un texto.</p>
<br>
<button type="button" onclick="displayResult()">Cambiar tamaño de fuente</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontSize="xx-large";
}
</script>
</head>
<body>
<p id="p1">Este es un texto.</p>
<br>
<button type="button" onclick="displayResult()">Cambiar tamaño de fuente</button>
</body>
</html>
Pruébalo »
Objeto Style Otras extensiones