How to Make Button Text Bold with CSS

Introduction

Button text can be made bold to enhance visibility and emphasize the button's action. CSS provides a simple way to achieve this using the font-weight property, which controls the thickness of the font.

In this tutorial, you’ll learn how to make button text bold using CSS.

Problem Statement

Create CSS code that:

  • Displays a button with bold text.
  • Adds a hover effect to further enhance the button's visibility.

Example:

  • Input: A button element with the text "Submit".
  • Output: A button with bold text that changes style on hover.

Solution Steps

  1. Use the <button> Element: Create the button in HTML.
  2. Make Text Bold Using CSS: Use the font-weight property to style the button text.
  3. Add Hover Effect (Optional): Further enhance the button on hover.

HTML Structure

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bold Button Text</title>
    <style>
        /* Step 1: Style the button and make the text bold */
        .bold-button {
            font-size: 1.2rem;
            font-weight: bold; /* Makes the text bold */
            color: white;
            background-color: #3498db;
            padding: 12px 30px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        /* Step 2: Add hover effect */
        .bold-button:hover {
            background-color: #2980b9; /* Darker blue on hover */
        }
    </style>
</head>
<body>

    <div style="text-align: center; margin-top: 100px;">
        <button class="bold-button">Submit</button>
    </div>

</body>
</html>

Output

You can play with the above HTML in Online HTML Editor and Compiler. Here is the output of the above HTML page.:

Explanation

Step 1: Make Button Text Bold

The .bold-button class is used to style the button and make the text bold.

.bold-button {
    font-weight: bold; /* Makes the text bold */
}
  • font-weight: bold: This CSS property makes the button text bold.

Step 2: Add Hover Effect

A hover effect is added to change the button's background color when hovered.

.bold-button:hover {
    background-color: #2980b9; /* Changes background color on hover */
}

Conclusion

You can make button text bold using the font-weight: bold property in CSS. This simple change improves readability and emphasis on the button's action.

Comments