Change Font Size and Color in PHP

Sheeraz Gul Dec 21, 2022 Feb 27, 2022 PHP PHP Text
Change Font Size and Color in PHP

PHP doesn’t have built-in functionality for changing the font size or color. We can use HTML and CSS with PHP to change the font size and color.

This tutorial demonstrates how to change font size and color using PHP.

Change the Font Size and Color Using PHP

We can echo an HTML tag with CSS to change the font size and color of the text.

Example:

<?php
$string= "Welcome! This page doesn't exist!";
echo $string."<br>";

//Change the fontsize using PHP, HTML and css through echo
echo '<span style="font-size: 50px;"> ' . $string.  ', <a href="something.php">New Page</a></span>';

//Change the font color using PHP, HTML and css through echo
echo "<br>";
echo '<span style="color: red; font-size: 50px;"> ' . $string.  ', <a href="something.php">New Page</a></span>';
?>

The code above prints three strings. One with original size and color, second with 50px font-size, and third with red font color.

Output:

Change Font Size and Color in PHP

Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.

LinkedIn Facebook