A brief discussion on spaces and blank lines in HTML code
All consecutive spaces or empty lines (newlines) in HTML code will be displayed as a single space.
Example 1: (Continuous spaces in the text content)
Code
<p>这段文本中,输入连续的空格 大概输入了十个。</p>
Display effect: There is a space between "square" and "big" and it is displayed as just one Space.
这段文本中,输入连续的空格 大概输入了十个。
Example 2: (Continuous spaces between codes)
Code
<span>span是一个行内标签</span> <span>和前面的span元素之间隔了很多个空格</span>
Display effect: Continuous spaces between two span elements are displayed as "sign There is only one space between " and ".
span是一个行内标签 和前面的span元素之间隔了很多个空格
The above two examples prove that continuous spaces in the HTML code will be displayed as one space when displayed, and the remaining extra spaces will be removed or ignored.
The paragraph text is actually part of the HTML code, but it is inside the p tag, and the space in Example 2 is between the two span tags.
Understood the spaces, now look at the blank lines, the same reason
Example 3: (blank lines in text content)
Code
<p>这段文本中,输入连续的空行 大概输入了五行。</p>
Display effect: As we can see, the five blank lines in the text code are only displayed as a space.
这段文本中,输入连续的空行 大概输入了五行。
Example 4: (blank lines between elements/labels), just replace the spaces in example 2 with blank lines. The display effect is the same as in example 2, with multiple blank lines. will only be displayed as a space.
<span>span是一个行内标签</span> <span>和前面的span元素之间隔了很多空行</span>
span是一个行内标签 和前面的span元素之间隔了很多空行
Proof: All consecutive spaces or empty lines (line breaks) in HTML code will be displayed as one space.
In this case, what should we do if we want to expand the distance between two characters so that the result of continuous spaces or blank lines in the code is also continuous spaces or blank lines? it's actually really easy.
Method 1: We can use the pre-formatted tag
, whether it is a space or a blank line. </p><pre class='brush:php;toolbar:false;'><pre class="brush:php;toolbar:false"> 这是 预格式文本。 它保留了 空格 和换行。
Display effect
这是 预格式文本。 它保留了 空格 和换行。
Method 2: We can use the space entity character instead of spaces and line breaks The tag
replaces empty lines. Although this method can get the display effect we want, it is not the most friendly to search engines because and
have no semantics in HTML. So it is recommended to use it as little as possible. Also note that must be lowercase, and the semicolon at the end cannot be omitted.
Method three: (suitable for spaces) Use full-width spaces
Full-width spaces are interpreted as Chinese characters, so they will not be interpreted as HTML delimiters. You can follow the actual The number of spaces is displayed.
Question: How to use the full-width input method?
Take Sogou input method as an example. We usually use half-width input. If there is a moon symbol in the status bar, it means that half-width input is being used. If it is a sun symbol, it means that it is using half-width input. It is a full-width input. You can switch between full-width and half-width by clicking on the icon, or by pressing the shortcut key Shift+Space.
Half-angle input (Moon) Full-angle input (Sun)
Description | |
---|---|
default. White space is ignored by the browser. | |
Blank spaces will be retained by the browser. It behaves like the tag in HTML. Copy after login |
|
The text will not wrap, the text will continue on the same line until the tag is encountered. |
|
Preserves whitespace sequences, but wraps normally. | |
Combines whitespace sequences, but retains newlines. |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
