However, we do think it is important to have consistency in your code. That's what this page is about.
Below are 2 samples of the same header.php file. The first is poorly formatted code. The second shows how we can clean this up to make it more readable.
The example above is taken from the header.php file in the Underscores theme and represents poorly formatted code. There is no consistency with the nesting of HTML tags. No consistency with the indentations and the PHP get's lost among the HTML.
Now let's take a look at the same code block but with better formatting.
Example #2 - BETTER
Notice how all of the opening and closing tags line up and the nesting of elements is clearly visible. When an element or HTML tag resides within another element, be sure to apply some indentation and keep this indentation consistent (spaces or tabs). There's no right or wrong way so long as you are consistent and it's easy to comprehend. Also notice how there are comments next to each closing tag to use as a reference. When mixing in PHP and HTML notice how we used an extra line break. It doesn't have to be done this way but it's consistent. Have we mentioned consistency?
If you need a little more guidance on the recommended coding standards for WordPress please review their documentation. They have a comprehensive list of coding standards for HTML, CSS, PHP and Javascript.