Introduction
Making text bold in CSS helps emphasize important content. You can easily achieve this using the font-weight
property to control the text's thickness.
Problem Statement
Create a CSS code that:
- Makes text bold using the
font-weight
property. - Demonstrates different ways to apply bold styles in CSS.
Example:
- Input: A paragraph element with the text "Bold Text Example".
- Output: The text appears bold based on the applied CSS styles.
Solution Steps
- Use
font-weight
Property: Set thefont-weight
tobold
to make the text bold. - Use Numeric Values for
font-weight
: Apply specific numeric values (e.g.,700
) for more control over the text thickness.
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 Text Example</title>
<style>
/* Step 1: Make text bold using font-weight: bold */
.bold-text {
font-weight: bold;
}
/* Step 2: Make text bold using numeric values */
.bold-numeric {
font-weight: 700;
}
</style>
</head>
<body>
<p class="bold-text">This text is bold using font-weight: bold.</p>
<p class="bold-numeric">This text is bold using font-weight: 700.</p>
</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: Use font-weight: bold
- To make the text bold, use this CSS code:
.bold-text { font-weight: bold; }
Step 2: Use font-weight: 700
- To make the text bold using a numeric value, use this CSS code:
.bold-numeric { font-weight: 700; }
Conclusion
You can easily make text bold using the font-weight
property. Whether you use bold
or a numeric value like 700
, both methods allow you to control how bold the text appears.
Comments
Post a Comment
Leave Comment