Open In App

How to bold text in php?

Last Updated : 18 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Bold Text is used in web applications to highlight important information or headings. In this article, we will learn to bold text in PHP using two possible approaches with implementation.

Below are the approaches to bold text in PHP:

Using the <b> tag from HTML

In this approach, we are using the <b> tag from HTML directly within PHP’s echo statement to render text in bold. The text wrapped within <b> tags is styled as bold, as shown in the example where “Hello GFG! I am Bold Text in PHP” is displayed in bold.

Example: The below example uses <b> tag from HTML to bold text in PHP.

PHP
<?php
echo "<h1>Approach 1: Using the tag from HTML</h1>";
echo "<p>Hello GFG! I am Not Bold Text</p>";
echo "<p><b>Hello GFG! I am Bold Text in PHP</p></b>";
?>

Output:

Screenshot-2024-04-11-at-17-06-22-W3Schools-online-PHP-editor

Using Inline CSS

In this approach, we are using inline CSS within PHP‘s echo statement to apply the font-weight: bold; style to a <span> element, resulting in bold text. The text “Hello GFG! I am Bold Text in PHP” is rendered in bold due to the inline CSS styling applied to the <span> element.

Example: The below example uses Inline CSS to bold text in PHP.

PHP
<?php
echo "<h1>Approach 2: Using Inline CSS</h1>";
echo "<p>Hello GFG! I am not Bold Text in PHP</p>";
echo "<p><span style='font-weight: bold;'>
Hello GFG!I am Bold Text in PHP</span> </p>";
?>

Output:

Screenshot-2024-04-11-at-17-10-32-W3Schools-online-PHP-editor


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads