What are the potential pitfalls of mixing PHP and HTML styling attributes, and how can they be avoided?

Mixing PHP and HTML styling attributes can lead to messy and hard-to-maintain code. To avoid this, it is recommended to separate PHP logic from HTML presentation by using CSS classes for styling. This separation of concerns makes the code cleaner and more organized.

<?php
// Instead of mixing PHP and HTML styling attributes, use CSS classes for styling
$color = "red";
?>

<!DOCTYPE html>
<html>
<head>
    <style>
        .red-text {
            color: <?php echo $color; ?>;
        }
    </style>
</head>
<body>
    <p class="red-text">This text is styled with a CSS class</p>
</body>
</html>