Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will line breaks/whitespace in HTML affect how the page is displayed?

Tags:

html

Will inserting line breaks in HTML like this affect the output?

<header>

    <div id="someid">

        something here

    </div>

</header>

I've been trying to study web development, and different tutorials use different formats. Will the extra lines between tags affect the output? I personally would prefer it that way since as a newbie, it looks more readable to me.

like image 971
Hero Stradivari Avatar asked Mar 23 '23 00:03

Hero Stradivari


1 Answers

No - whitespace is collapsed in the output.

Primarily that means two things:

1 - Leading/trailing whitespace in an HTML element is not displayed, so these two divs will display the same:

<div>Some stuff</div>

<div>     Some stuff

</div>

2 - Multiple whitespace characters in a row will be collapsed into one space. That means these two divs will display the same:

<div>Some stuff</div>

<div>Some              stuff</div>

Here's a nice article for further reading.

like image 153
uptownnickbrown Avatar answered Apr 25 '23 14:04

uptownnickbrown