search
HomeWeb Front-endHTML TutorialA 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. <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)

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. 
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
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
Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

See all articles

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

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.