Skip to main content

How to Make Text Bold with font-weight in CSS

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

font-weight sets how heavy the text is. bold makes it bold, normal takes the bold away, and numbers such as 700 give the same weights in numbers.

Syntax​

Syntax
<selector> {
font-weight: <weight>;
}
PartWhat it does
<selector>The text to change.
<weight>bold or normal, a number from 1 to 1000 such as 700, or bolder and lighter, which go one step from the parent's weight.

MDN's font-weight page says normal is the same as 400 and bold the same as 700.

The Example​

The example is a short receipt: two items and a total. One rule makes the total bold.

Step 1: Write the Code​

Create a file named index.html in a text editor, such as Visual Studio Code:

index.html, an HTML page with a style element holding a rule for the class total with font-weight bold, and three paragraphs, Coffee: 3.50, Cake: 4.00 and Total: 7.50, the last with the class total.

index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Font weight</title>
<style>
.total {
font-weight: bold;
}
</style>
</head>
<body>
<p>Coffee: 3.50</p>
<p>Cake: 4.00</p>
<p class="total">Total: 7.50</p>
</body>
</html>

Step 2: Open It in a Browser​

Double-click index.html. It opens in your browser:

The page in Chromium: Coffee: 3.50 and Cake: 4.00 in normal text, and Total: 7.50 in bold.

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.

What Happened​

  • The total is bold. Chromium gave it a font weight of 700.
  • The two items stayed at 400, the normal weight.

Common Mistakes​

MistakeWhat happensDo this instead
A made-up value, such as heavyThe value is invalid and ignored: the text stayed at 400Use bold, or a number such as 700

Troubleshooting​

SymptomLikely causeFix
The text doesn't get bolderThe value is misspelled or made upUse bold or a number
A heading is bold although you didn't ask for itBrowsers make headings bold by defaultSet font-weight: normal on it

FAQ​

Is 700 the same as bold?​

Yes. font-weight: 700 gave the same weight as bold: 700.

How do I remove the bold from a heading?​

Set font-weight: normal. An h1 with it measured 400, the normal weight.

What does bolder do?​

It goes one step heavier than the parent. In a page whose text was 400, bolder gave 700.

Conclusion​

Use font-weight: bold or 700 to make text bold, and normal to remove the bold. Any other word is ignored, so stick to the keywords and the numbers.

Additional Resources​