Open In App

How to bold the text using CSS ?

Last Updated : 08 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In HTML, we use the <b> and <strong> tags to make content bold. However, when it comes to styling text, CSS provides a more versatile way to achieve boldness through the font-weight property. This property allows you to set various boldness levels for your text to mark something important.

Font-Weight Property Values

Value

Description

normal

Normal font-weight, equivalent to 400 (default numeric value).

bold

Bold font-weight, equivalent to 700.

bolder

Sets the font-weight bolder than the parent element.

lighter

Sets the font-weight lighter than the parent element.

<number>

A numeric value between 1 and 1000, inclusive (increasing boldness).

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

Font-Weight Inheritance Chart

Parent Valuelighterbolder
100100400
200100400
300100400
400100700
500100700
600400900
700400900
800700900
900700900

Example 1: Using font-weight for Bold Text

The following example demonstrates how to use the font-weight property in CSS to represent simple text in bold.

HTML
<!DOCTYPE html>
<html>

<head>
    <style type="text/css">
        h2 {
            font-weight: 700;
            color: green;
        }

        .text {
            font-weight: bold;
        }
    </style>
</head>

<body>
    <h2>
        Welcome To Geeks for Geeks
    </h2>
    <p class="text">
        A Computer Science portal for geeks
    </p>

</body>

</html>

Output:


Example 2: Using Various Font-Weight Values

The following example demonstrates different font-weight properties applied to simple texts.

HTML
<!DOCTYPE html>
<html>

<body>
    <h2 style="font-weight: bold;
               text-decoration: underline;">
        Thought of the day
    </h2>
    <p style="font-weight: lighter;">
        A good programmer is someone who
        always look both ways
        <span style="font-weight: 900;">
            before crossing the one way road.
        </span>
    </p>

</body>

</html>

Output:

font-weight property

Next Article

Similar Reads