Current Location: Home> Latest Articles> PHP Font Properties Explained: Font Styles, Colors, and Text Layout

PHP Font Properties Explained: Font Styles, Colors, and Text Layout

M66 2025-10-24

Overview of PHP Font Properties

PHP offers a variety of font properties for text output, allowing developers to control the appearance of text. The main properties include:

Font Family and Style

  • font-family: Specifies the font family to use.
  • font-weight: Sets the font weight, such as normal, bold, or light.
  • font-size: Sets the font size in pixels.

Text Styles

  • color: Sets the text color.
  • text-decoration: Changes text decoration, such as none, underline, or line-through.
  • text-align: Sets text alignment, such as left, center, right, or justify.

Line Height and Letter Spacing

  • line-height: Sets the height of text lines in pixels.
  • letter-spacing: Adjusts the spacing between letters in pixels.

How to Use Font Properties

Developers can control text appearance either through CSS styles or by directly setting font properties in the output.

CSS Style Example

p {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  font-size: 16px;
}

Direct Output Example

echo "<p style='font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 16px;'>Hello World</p>";

The above content provides a comprehensive guide to PHP font properties, helping developers manage text display effectively.