Style fontWeightPropiedad
Objeto Style
Definición y uso
La propiedad fontWeight establece o devuelve el grosor de la fuente.
Sintaxis
Establecer la propiedad fontWeight:
Object.style.fontWeight="value"
Devolver la propiedad fontWeight:
Object.style.fontWeight
| Valor | Descripción |
|---|---|
| normal | Predeterminado. La fuente es normal. |
| lighter | Define una fuente más fina. |
| bold | Define negrita. |
| bolder | Define una fuente más gruesa. |
| 100 200 300 400 500 600 700 800 900 |
Define caracteres de fino a grueso. 400 equivale a normal, 700 equivale a negrita. |
| inherit | El valor de la propiedad fontWeight se hereda del elemento padre. |
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales soportan la propiedad fontWeight.
Nota:IE7 y versiones anteriores no soportan el valor "inherit". IE8 solo soporta "inherit" si se especifica !DOCTYPE. IE9 soporta "inherit".
Ejemplo
Ejemplo
Cambiar el grosor de la fuente:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de Ejemplo (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">Este es un texto.</p>
<br>
<button type="button" onclick="displayResult()">Modificar el grosor de la fuente</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de Ejemplo (example.com)</title>
<script>
function displayResult(){
document.getElementById("p1").style.fontWeight="900";
}
</script>
</head>
<body>
<p id="p1">Este es un texto.</p>
<br>
<button type="button" onclick="displayResult()">Modificar el grosor de la fuente</button>
</body>
</html>
Pruébalo »
Objeto Style Otras extensiones