About space and line breaks in HTML source code

Sometimes the space and line break between two HTML tags is ignored by the browser, sometimes not.

I feel that the space and line break between two lines shows, two block blocks do not show. But what about one row window and one block block?

I want a rule or specification, could you tell me?

+4
source share
2 answers

In general, browsers ignore extra space (more than one extra space).

If you have at least one space between two inline elements, then the browser will display one space (but only one space no matter how much you have). If you want to display more than one place, use the html   symbol code . This will make as many spaces as you need. (although, as Wakey noted, it is much better to use CSS for the spacing)

As for line breaks, some browsers (e.g. firefox) will treat line breaks as well as space (where one space will be added no matter how many lines you have). However, other browsers (such as Internet explorer) completely ignore line breaks. To force browsers to display line breaks, use the <br> tag.

I hope all this cleared up!

+5
source

The specifications say that all spaces, tabs, and line breaks are interpreted as a word delimiter. This way, no matter how many spaces, tabs, and line breaks you have, it will only appear as one space.

The one exception is the pre-tag. Displays spaces, line breaks and tabs in the predtega. You can create each tag as a preliminary tag using the white-space: pre rule.

Specifications: http://www.w3.org/TR/html401/struct/text.html#h-9.1

To display line breaks, the browser checks the type of content (inline or block). If it is embedded (strong, em, a, ...), it does not show line breaks. If it is a block (p, table, div, ...), it shows a line break before and after the element.

Again, with css, you can change the type of block (using the display property) and change its appearance.

+1
source

Source: https://habr.com/ru/post/1335850/


All Articles