How to do bold and simple text in the same line using the echo in php?

In PHP, you can combine bold and regular text in the same line using HTML tags within your echo statement. The most effective approach is to use the <strong> tag for bold text and regular text outside it.

Using Strong Tags

The simplest way to create bold text alongside regular text is using the <strong> HTML tag −

<?php
echo "<strong>This is bold text</strong> and this is regular text.";
?>
This is bold text and this is regular text.

Using CSS Styling

You can also use CSS font-weight property with <span> tags for more control over styling −

<?php
echo '<span style="font-weight: bold; color: #006400;">Bold colored text</span> followed by normal text.';
?>
Bold colored text followed by normal text.

Mixing with Variables

When combining with dynamic content or variables, concatenate strings properly −

<?php
$username = "John";
$score = 95;
echo "<strong>User: </strong>" . $username . " <strong>Score: </strong>" . $score;
?>
User: John Score: 95

Conclusion

Use <strong> tags for semantic bold text or <span> with CSS for styled text. Always concatenate strings properly when mixing HTML tags with PHP variables.

Updated on: 2026-03-15T09:35:26+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements