How can HTML code be properly separated from PHP code for styling purposes?

To properly separate HTML code from PHP code for styling purposes, you can use PHP to echo out the HTML code while keeping the styling separate. This can be achieved by storing the HTML code in a separate variable and then echoing it out where needed in the PHP script.

<?php
$html = '<div style="color: red;">Hello, world!</div>';
echo $html;
?>