As another user pointed out, it's called Escaping from HTML, it's just an alternative to echo/print'ing out every line of HTML that is inside the PHP if statement.
That being said, the syntax you're using is just fine:
// Option 1
<?php if ($variable) { ?>
<!-- HTML stuff here -->
<?php } ?>
Or, the other way:
// Option 2
<?php
if ($variable) {
echo '<div>';
echo '<span>Totally putting HTML here</span>';
echo '</div>';
}
?>
Or, the third way as user1266222 pointed out:
// Option 3
<?php if ($variable) { include 'path/to/htmlfile/filename.html'; } ?>
Which would just include the HTML file there.
The method depends on what you wanna do, all are viable in all usecases, but for only very small snippets of HTML, I would go with option 2. For a whole HTML file (or even just partial), I would go with option 3. And if lazy and you have a longer piece of HTML, there is option 1.