docs.rodeo

MDN Web Docs mirror

font-weight

{{CSSRef}} 

The font-weight CSS property sets the weight (or boldness) of the font. The weights available depend on the {{cssxref("font-family")}}  that is currently set.

{{EmbedInteractiveExample("pages/css/font-weight.html")}} 

Syntax

/* <font-weight-absolute> keyword values */
font-weight: normal;
font-weight: bold;

/* <font-weight-absolute> numeric values [1,1000] */
font-weight: 100;
font-weight: 200;
font-weight: 300;
font-weight: 400; /* normal */
font-weight: 500;
font-weight: 600;
font-weight: 700; /* bold */
font-weight: 800;
font-weight: 900;

/* Keyword values relative to the parent */
font-weight: lighter;
font-weight: bolder;

/* Global values */
font-weight: inherit;
font-weight: initial;
font-weight: revert;
font-weight: revert-layer;
font-weight: unset;

The font-weight property is specified using either a <font-weight-absolute> value or a relative weight value, as listed below.

Values

Fallback weights

If the exact weight given is unavailable, then the following rule is used to determine the weight actually rendered:

[!NOTE] The fallback weight algorithm is only used for rendering. The computed value of the property is still the specified value.

Meaning of relative weights

When lighter or bolder is specified, the below chart shows how the absolute font weight of the element is determined.

Note that when using relative weights, only four font weights are considered — thin (100), normal (400), bold (700), and heavy (900). If a font family has more weights available, they are ignored for the purposes of relative weight calculation.

Inherited value bolder lighter
100 400 100
200 400 100
300 400 100
400 700 100
500 700 100
600 900 400
700 900 400
800 900 700
900 900 700

Common weight name mapping

The numerical values 100 to 900 roughly correspond to the following common weight names (see the OpenType specification):

Value Common weight name
100 Thin (Hairline)
200 Extra Light (Ultra Light)
300 Light
400 Normal (Regular)
500 Medium
600 Semi Bold (Demi Bold)
700 Bold
800 Extra Bold (Ultra Bold)
900 Black (Heavy)
950 Extra Black (Ultra Black)

Variable fonts

While many fonts have a particular weight corresponding to one of the numbers in Common weight name mapping, most variable fonts support a range of weights providing much finer granularity, giving designers and developers more control over the chosen weight.

For TrueType or OpenType variable fonts, the “wght” variation is used to implement varying widths.

This demo loads with font-weight: 500; set. Change the value of the font-weight property in the .sample selector to see the weight of the text change (e.g., 200, 700). Click “Play” in the code blocks below to edit the example in the MDN Playground:

<p class="sample">
  ...it would not be wonderful to meet a Megalosaurus, forty feet long or so,
  waddling like an elephantine lizard up Holborn Hill.
</p>
@font-face {
  src: url("https://mdn.github.io/shared-assets/fonts/variable-fonts/MutatorSans.ttf");
  font-family: "MutatorSans";
  font-style: normal;
  font-weight: 1 1000;
}

.sample {
  text-transform: uppercase;
  font-weight: 500;
  font:
    1.5rem "MutatorSans",
    sans-serif;
}

{{EmbedLiveSample("font-weight-example", "", "200px")}} 

Accessibility

People experiencing low vision conditions may have difficulty reading text set with a font-weight value of 100 (Thin/Hairline) or 200 (Extra Light), especially if the font has a low contrast color ratio.

Formal definition

{{cssinfo}} 

Formal syntax

{{csssyntax}} 

Examples

Setting font weights

HTML

<p>
  Alice was beginning to get very tired of sitting by her sister on the bank,
  and of having nothing to do: once or twice she had peeped into the book her
  sister was reading, but it had no pictures or conversations in it, "and what
  is the use of a book," thought Alice "without pictures or conversations?"
</p>

<div>
  I'm heavy<br />
  <span>I'm lighter</span>
</div>

CSS

/* Set paragraph text to be bold. */
p {
  font-weight: bold;
}

/* Set div text to two steps heavier than
   normal but less than a standard bold. */
div {
  font-weight: 600;
}

/* Set span text to be one step lighter
   than its parent. */
span {
  font-weight: lighter;
}

Result

{{EmbedLiveSample("Setting_font_weights","400","300")}} 

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN