It's important to understand the distinction between the HTML pre
element and the CSS property white-space: pre
. These two are separate concepts, so don't confuse them. However, if you're talking about how line breaks are rendered, that's a different story.
According to the official specifications, a line break right after an opening tag should be disregarded. Therefore,
<pre>
aaa
bbb
</pre>
should be the same as
<pre>aaa
bbb
</pre>
This rule shouldn't change even if you swap p
for pre
or apply some styling. But web browsers sometimes don't follow the rules, which is the case here.
Browsers handle elements differently. The key takeaway is to minimize the use of the pre
element and white-space: pre
. If you do use them, be aware of this behavior. If necessary, avoid starting a tag immediately with a line break, and instead insert a space before the line break (if you want an empty line at the beginning).