Home Web Front-end HTML Tutorial Several ways to insert spaces in HTML

Several ways to insert spaces in HTML

Nov 17, 2017 pm 04:29 PM
html several kinds method

About HTML, basically we all use it as programmers. In this article, we mainly introduce two methods of inserting spaces in HTML for students who are just getting started.

Method 1. Insert a single space and tab character

1. Insert a non-breaking space. Generally speaking, HTML will only display a blank space between words no matter how many times you press the space bar. When you need to insert multiple spaces, please enter the   or   code. They are called "space placeholders". If you enter a few, they will display a few spaces on the page.

The reason why it is called non-breaking spaces is because it does not produce newlines. If you abuse this spacing, the browser may not be able to insert line breaks in a neat and readable way.

2. Insert spaces of different widths. There are various character entities that allow browsers to display spaces. Different browsers may display this a little differently, but unlike  , they do not affect line breaks:

  — "enspace" is named after the typographic unit of measurement, width. It is the width of two ordinary spaces

  — "em space" is about the width of four ordinary spaces

3. Use non-breaking spaces to simulate tab characters. One way to generate a paragraph is to insert a few spaces before the first line:    . This method only works with HTML and is not recommended if you are using CSS (other methods will be covered in other steps).

If the content of the paragraph is rich text, please use the "pre" tag.

4. Use CSS to generate paragraphs. The inner margin or outer margin of CSS indicates the specific display format to the browser, so the display effect is more consistent. Even if you don't know CSS very well and don't have an instruction sheet handy, it can be easily added. Here are the specific instructions on how to move an entire paragraph to the right:

In the section of the HTML document, insert the following command:

"p.indent" defines a paragraph (labeled p) called "indent" (can be named arbitrarily). The remaining commands add padding space to the left of the paragraph.

Return the body of the HTML document. Whenever you want to add a paragraph, insert the following in the tag:

.

To adjust the amount of indentation, just change the number "1.8" in the CSS command. The following "em" should be retained, it is the unit representing width.

Method 2. Format long paragraphs

1. Use pre-formatted text. The "pre" element can define pre-formatted text, which will preserve spaces or newlines in the text. Therefore, spaces or enter keys entered in the

 tag will be displayed as spaces or line feeds. You can use it to display code samples, poetry, or other text content that requires spaces and line breaks. 

One of the drawbacks of preformatted text is its width. It cannot adjust the page width to adapt to the user's window size like ordinary hypertext markup languages.

2. Create a newline character. The
tag is placed at the end of the current line of text and inserts a simple line break. You can enter multiple "br" tags to create multiple blank lines. This is a good way for novice HTML students to write code, but when you learn CSS, you will find that this kind of mandatory HTML style code is not recommended. ,

3. Use the "p" tag to define the paragraph. The p element automatically creates some white space before and after it, so the

tag after the text can end the paragraph. Most browsers separate paragraphs with a blank line, but this does not guarantee precise formatting.

If you see some extra symbols "floating" on the code when you finally review the text and code, you need to carefully check whether there is incomplete code, such as writing "
" "

CSS (Cascading Style Sheets) can provide pixel-level precise control over the layout of element positions in web pages (including spacing in text), allowing for better and more precise editing of web page objects and model styles.

Do not enter spaces after the start tag or before the end tag. For example, when typing "Spaces Tutorial" do not write "Spaces Tutorial ".

The non-spacing character ( ) is an example of a character entity. You cannot type such web characters from the keyboard, but you can use the corresponding code to insert the characters.

In fact, what we know about HTML is not difficult, but we can basically use it. I hope these little knowledge can help you lay a solid foundation.

Related recommendations:

htmlspace code

htmlVarious forms of spaces_html/css_WEB-ITnose

Example analysis of how to retain spaces and line breaks in html pages

The above is the detailed content of Several ways to insert spaces in HTML. For more information, please follow other related articles on the PHP Chinese website!

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

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.

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.

See all articles