Home Web Front-end HTML Tutorial A brief discussion on spaces and blank lines in HTML code

A brief discussion on spaces and blank lines in HTML code

Feb 18, 2017 pm 03:37 PM
html space blank line

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>
Copy after login

Display effect: There is a space between "square" and "big" and it is displayed as just one Space.

这段文本中,输入连续的空格 大概输入了十个。
Copy after login

Example 2: (Continuous spaces between codes)

Code

<span>span是一个行内标签</span>               <span>和前面的span元素之间隔了很多个空格</span>
Copy after login

Display effect: Continuous spaces between two span elements are displayed as "sign There is only one space between " and ".

span是一个行内标签 和前面的span元素之间隔了很多个空格
Copy after login

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>
Copy after login

Display effect: As we can see, the five blank lines in the text code are only displayed as a space.

这段文本中,输入连续的空行 大概输入了五行。
Copy after login

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>
Copy after login
span是一个行内标签 和前面的span元素之间隔了很多空行
Copy after login

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">  
这是  
预格式文本。  
它保留了      空格  
和换行。  
Copy after login


Display effect

这是  
预格式文本。  
它保留了      空格  
和换行。
Copy after login


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)

A brief discussion on spaces and blank lines in HTML code

# Method Four: Use CSS style intervals attribute control. Change the standard spacing between characters (words). We know that two words in English are separated by a space, so we can visually think that word-spacing changes (lengthens or shortens) the width of the space between words.

Method 5: Use the white-space attribute in the CSS style. This attribute declares how to handle whitespace characters within the element.


##Valuenormalprenowrappre-wrappre-line


white-space:normal; is normal. Just like if it is not set, only one space will be displayed for consecutive spaces and blank lines.

white-space:nowrap;What does not wrap mean? Under normal circumstances, when our text exceeds the text field, the text will automatically wrap. This setting means that it will not automatically wrap, but will wrap when it encounters the line break tag

white-space:pre; Same as method 1, output and display the text as it is. When the text exceeds the text area, no line breaks will occur and scroll bars will be generated.

white-space:pre-wrap;Retain spaces and blank lines, but when the text exceeds the text field, it will automatically wrap.

white-space:pre-line;Continuous spaces will be displayed as one space, but consecutive blank lines will be retained.

The above is the brief discussion of spaces and blank lines in HTML code brought to you by the editor. I hope everyone will support the PHP Chinese website~

More brief discussion of spaces and blank lines in HTML code For articles related to spaces and blank lines, please pay attention to the PHP Chinese website!


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.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

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

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

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.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

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

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

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

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

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

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

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

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

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

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

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

See all articles