Font-weight - Property CSS

font-weight

Summary of characteristics of the font-weight property

Quick description
Selects a weight for the characters.
Status
Standard
Usable for
HTML, SVG
Predefined values
normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
Percentages
Not applicable.
Initial value
normal
Inherited by default
Yes.
Animation type
Computed value : during an animation, the font-weight property gradually changes from one value to another.
W3C Module
CSS Fonts Module
References (W3C)
 đꎇ  
 đꎅ  
Document status: WD (Working Draft)

Document status: WD (Working Draft)

Document status: REC (Recommendation)

Document status: REC (Recommendation)

Document status: DEPR (Old specification, declared obsolete or superseded)

Syntax diagram of font-weight.

Font-weight property - Syntax diagramSyntax diagram of the font-weight CSS property. See stylescss.free.fr for details. normal normal bold bold number number bolder bolder lighter lighterfont-weight:;font-weight:;
Syntax diagram of the font-weight property.
The links in the diagram provide access to more details.

On the diagram, the terms in bold are the predefined words of CSS, the other terms are described below:

  • number is a numerical value from 1 to 1000, without units.

Description of the font-weight property.

font-weight Sets the weight of the characters (display in bold).

The rendering depends a lot on the font used. Some fonts only support two possibilities: bold or normal, others offer 3 or 4 shades, few are the ones that distinguish the 9 shades provided by font-weight.

When a weight is not available in the font used, the browser can use the weight closest to the requested weight or synthesize the weight by calculation. For more on this, see the font-synthesis property.

The Montserrat font (Google Font) is particularly rich: it has the nine levels of weight provided by CSS.

Aa
100
Aa
200
Aa
300
Aa
400
Aa
500
Aa
600
Aa
700
Aa
800
Aa
900

Note: font-weight can also be a descriptor, used with the @font-face directive.

The different use of font-weight.

The word font-weight matches the property described on this page, but can also be a descriptor usable with the following guidelines:

  • @font-face : Defines all settings for a downloadable font.

Values for font-weight.

  • font-weight: normal;

    Default. Characters are displayed with the median weight.

  • font-weight: bold;

    Characters are displayed in bold.

  • font-weight: bolder;

    Relative value: characters are displayed in a higher weight than the parent.

    1. Parent weight = 100, 200 or 300, bolder takes the value 400.
    2. Parent weight = 400 or 500, bolder take the value 700.
    3. Parent weight = 600 or more, bolder take the value 900.
  • font-weight: lighter;

    Relative value: Characters are displayed in less weight than the parent.

    1. Parent weight = from 100 to 500, lighter take the value 100.
    2. Parent weight = 600 or 700, lighter take the value 400.
    3. Parent weight = 800 or more, lighter take the value 700.
  • font-weight: 300;

    The characters are displayed with a thickness that is all the greater the number. The specified value can be 100, 200, 300, up to 1000.

    These nuances are not necessarily all present in the font used. When this is the case, they are commonly referred to:

    100: Thin,
    200: Extra Light,
    300: Light,
    400: normal ou Regular,
    500: Medium,
    600: Semi Bold,
    700: bold,
    800: Extra Bold,
    900: Black ou heavy.

Values ​​common to all properties:

font-weight: initial (normal) font-weight: inherit font-weight: revert font-weight: revertLayer font-weight: unset

Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, unset.

Animation of the font-weight property.

Here's an example of animation on the font-weight property. The animation is more or less jerky depending on the font chosen. Indeed, some fonts only have two or three thicknesses of weight, while others offer more. The ideal is the so-called "variable" fonts, such as Montserrat, which allow the weight to evolve continuously.

Police 'Arial'
Police 'Montserrat'

Manipulating the font-weight property programmatically.

Change the value of font-weight in Javascript.

The code below is an example that shows how to change the value of font-weight for an el element. Two syntaxes are possible: with the name of the property written in kebab-case (a hyphen to separate words), or with the name of the property written in camel-case (a capital letter to separate words).

Javascript
let el = document.getElementById('id'); el.style['font-weight'] = 'bolder'; // or let el = document.getElementById('id'); el.style.fontWeight = 'bolder';

Read in Javascript the value of font-weight.

The following code only works if the property has been assigned directly to the element with the HTML code style attribute, and not by going through a CSS selector. The value is returned as defined (predefined value or number from 100 to 900).

Javascript
let el = document.getElementById('id'); let value = el.style['font-weight']; // or let el = document.getElementById('id'); let value = el.style.fontWeight;

Read the computed value of font-weight in Javascript.

The computed value is the value that results from the value assigned to font-weight via a selector, or the value determined via the inheritance mechanism. Otherwise, it will be the initial value of the property (normal} in the case of font-weight). But the computed value is always equal to something.

In the case of font-weight, the value is always returned in its numeric form: a number from 100 to 1000.

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('font-weight');

Change the value of font-weight with JQuery.

JQuery

$('#id').css('font-weight', 'bolder');
// or
$('#id').css('fontWeight', 'bolder');

Read the computed value of font-weight with JQuery.

JQuery
let value = $('#id').css('font-weight');

Code démo.

By clicking on the buttons below, you will see the value for the first button as it has been assigned, and for the second button, the computed value. In the case of font-weight we see that the computed value is always returned as 100...1000.

Simulator.

Police :
font-weight :
Pack my box with five dozen liquor jugs (1)

(1) Anonymous pangram.

Browsers compatibility.

The font-weight property itself is well handled by all browsers, But the correct reproduction of the weight (from 100 to 1000) depends on the font chosen.

Column 1
Support for the font-weight property to change the weight of characters.
Column 2
Support for numeric values (from 100 to 900) in the font-weight syntax.
1
font-weight
property
2
Numeric
values
Estimated overall support.
97%
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Opéra

Safari

Safari sur IOS

Firefox pour AndroĂŻd

Samsung Internet

Chrome

Edge

Firefox

AndroĂŻd Brower

Chrome pour AndroĂŻd

Baidu Browser

QQ Browser

UC Browser pour AndroĂŻd

Opéra mini

font-weight history.

The font-weight property has been around since the first CSS specification, and has changed little since then.

  • Cascading Style Sheets specification - Version 1

    Initial definition of property, with values ​​still in use today.
    WD
    November 17, 1995
    Working Draft.
    PR
    November 12, 1996
    Proposed for recommendation.
    REC
    December 17, 1996
    Recommendation .
    DEPR
    September 13, 2018
    Old specification, declared obsolete.
  • Cascading Style Sheets Level 2 - Revision 1 Specification

    No change.
    WD
    November 04, 1997
    Working Draft.
    PR
    March 24, 1998
    Proposed for recommendation.
    REC
    May 11, 1998
    Recommendation .
  • CSS Fonts Module Level 3

    The property specification is not changed. But font-weight is also a descriptor for the @font-face at-rule.
    WD
    July 21, 1997
    Working Draft.
    CR
    October 03, 2013
    Candidate Recommendation.
    PR
    August 14, 2018
    Proposed for recommendation.
    REC
    September 20, 2018
    Recommendation .
  • CSS Fonts Module Level 4

    No change.
    WD
    July 11, 2017
    Working Draft.
    CR
    PR
    REC
  • CSS Fonts Module Level 5

    Possibility of expressing the value in percentages.
    WD
    June 29, 2021
    Working Draft.
    CR
    PR
    REC

See also, about typefaces.

font-weight and the properties concerning fonts are numerous. They are grouped in the CSS Fonts Module. ou will find the following definitions in this module:

Properties:

font
Langue française
Shorthand to set most properties for fonts.
âś—
font-effect
Langue française
Allows you to apply some effects to the text: relief, border...
font-family
Selects a font from those that are available or downloaded.
âš 
font-feature-settings
Langue française
Permet d’exploiter les fonctionnalités spécifiques des polices de caractères OTF, WOFF, etc.
font-kerning
Langue française
Adjusting the kerning between characters.
âš 
font-language-override
Langue française
Defines the language to be considered when choosing characters.
âš 
font-optical-sizing
Langue française
Optimizes the shape of characters based on their size.
font-palette
Langue française
Defines the color palette that can be used for colored fonts.
font-size
Adjusts the font size, which also impacts units like em, ex, etc.
font-size-adjust
Langue française
Definition of the aspect factor of the font.
âś—
font-smooth
Langue française
Defines whether and which smoothing algorithm should be used.
font-stretch
Langue française
Changes the stretching or compression of characters.
font-style
Langue française
Selects the italic or oblique font styles.
font-synthesis
Langue française
Allows or disallows calculation of missing styles in the typeface.
âš 
font-synthesis-position
Langue française
Whether or not allows the browser to synthesize characters in superscript or subscript.
âš 
font-synthesis-small-caps
Langue française
Whether or not allows the browser to calculate the glyphs of characters in small caps.
âš 
font-synthesis-style
Langue française
Defines whether the browser is allowed to synthesize italic forms of characters.
âš 
font-synthesis-weight
Langue française
Defines whether or not the browser can calculate the bold glyph.
font-variant
Langue française
Shorthand to define advanced typographic attributes: ligatures, character substitution, etc.
font-variant-alternates
Langue française
Defines character substitution (OTF, WOFF fonts).
font-variant-caps
Langue française
Applies character capitalization.
font-variant-east-asian
Langue française
Typography specific to Chinese or Japanese characters.
âš 
font-variant-emoji
Langue française
Choose between an emoji or text presentation.
font-variant-ligatures
Langue française
Enables or disables character ligation.
font-variant-numeric
Langue française
Defines how evolved numbers are displayed: fractions, numbers, etc.
font-variant-position
Langue française
Superscript or subscript of characters.
âš 
font-variation-settings
Langue française
Provides access to the stylistic possibilities of OTF fonts.
font-width
Langue française
Synonymous with font-stretch (character width/enlargement).

Functions:

âš 
palette-mix()
Langue française
Establish the mixture of two color palettes from two different typefaces.

At-rules:

@font-face
Langue française
Defines all settings for a downloadable font.
âš 
@font-feature-values
Langue française
Defines the typographic variations to use.
@font-palette-values
Langue française
Defines a color palette that can then be applied to a font.

Descriptors :

ascent-override
Langue française
Descriptor for @font-face. Sets the height of the characters above the baseline.
descent-override
Langue française
Descriptor for @font-face. Sets the height of the characters below the baseline.
âš 
font-display
Langue française
Descriptor for @font-face. Determines how the browser behaves when faced with fonts that take a long time to load.
line-gap-override
Langue française
Descriptor for @font-face. Sets the line spacing of the font.
src
Langue française
Defines the source of a font file to download, or an image to display.
unicode-range
Langue française
Descriptor for @font-face. Defines the range of character codes to be downloaded into a font.