5 Easy Ways to Insert Spaces in HTML - GeeksforGeeks

5 Easy Ways to Insert Spaces in HTML

Last Updated : 29 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Inserting spaces provides developers with greater control over the spacing between text, elements, and paragraphs, aiding in the efficient management of content layout. Effective spacing enhances text readability, facilitating user comprehension and engagement with the content.

There are five easy ways to insert spaces in HTML which are as follows:

Using Non-Breaking Space

The abbreviation of   is a Non-Breaking Space entity used in HTML to insert a space between characters that prevents line breaks.

Syntax:

&nbps;

Example: To illustrate the implementation of Non-Breaking Space.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, initial-scale=1.0">
    <title>Non-Breaking Space</title>
</head>

<body>
    <p>
        The element have
        five&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;spaces
    </p>
</body>

</html>

Output:

&nbsp-in-html

    ” ” in HTML

Using Multiple Non-Breaking Spaces

We can achieve multiple non-breaking spaces in different ways including &nbsp;, &emsp;, and &ensp;.

Syntax:

&ensp; Or $emsp;

Example: To illustrate the implementation of Multiple Non-Breaking Spaces().

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Non-Breaking Space</title>
</head>

<body>
    <h1>
        Welcome
        to&ensp;GeeksforGeeks
    </h1>
    <p>
        The above text has two space
        between to and GeeksforGeeks
    </p>

    <h3>Hello&emsp;Geeks</h3>
    <p>
        The above text has four space
        between Hello and Geeks
    </p>
</body>

</html>

Output:

Or-$emsp;

&emsp Or $emsp; in HTML

Using Preformatted Text Tag

The Preformatted Text <pre> tag is used to display the text exactly as it is defined in the HTML document, whitespace, and line breaks are rendered the same.

Syntax:

<pre>Content...</pre>

Example: To illustrate the implementation of Preformatted Text (<pre>) Tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>Non-Breaking Space</title>
</head>

<body>
    <h1>Welcome to
        GeeksforGeeks
    </h1>
    <pre>
            ** 
        **** 
        ****** 
        ***********     
    </pre>
</body>

</html>

Output:

<pre>-tag-in-HTML


tag in HTML

Using Break Tag

The <br> tag in HTML is an empty, self-closing tag that represents a line break or newline within text.

Syntax:

<br>

Example: To illustrate the implementation of Break Tag.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
                   initial-scale=1.0">
    <title>Non-Breaking Space</title>
</head>

<body>
    <h1>
        Welcome to <br>
        GeeksforGeeks
    </h1>
</body>

</html>

Output:

Break-tag-in-HTML

Break tag in HTML

Using Paragraph Tag

The <p> tag in HTML is used to separate and structure the text content into paragraphs, providing clear visual separation between different sections of text.

Syntax:

<p>Content...</p>

Example: To illustrate the implementation of Paragraph (<p>).

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, 
                   initial-scale=1.0">
    <title>Non-Breaking Space</title>
</head>

<body>
    <p>
        Web Design is a field related to
        designing websites on the Internet.
        Without a good design, a website
        fails to perform well and cannot
        produce a good impact on the user.
        Design is a creative process that
        affects the ranking of the brand.
    </p>
    <p>
        A good website design helps
        to create an engaging online
        presence that captivates the
        audience.
    </p>
</body>

</html>

Output:

ptag

Similar Reads

How to insert spaces/tabs in text using HTML and CSS
In this article, we will learn how to add spaces/tabs in text using HTML and CSS. As we know HTML doesn't support more than one space by default, that's why we need some extra attributes or CSS to get extra space in between the text. These are the following approaches by using these we can add spaces/tabs in text: Table of Content Using the HTML En
3 min read
Different ways to add Breaks and Spaces in HTML.
In HTML, Breaks and Spaces can be added using various elements and entities. The &lt;br&gt; tag creates a line break, while &amp;nbsp; represents a non-breaking space. Additionally, the &lt;p&gt; tag defines a paragraph, creating space between blocks of text. CSS properties like margin and padding can also be used for more precise control over spac
1 min read
Blockchain as a Service Platform - Easy to use
With the growth of the crypto market, the demand for blockchain has increased and people are seeking various possibilities of growth and taking interest in blockchain as a service platform. There are so many applications of blockchain which are the best things of blockchain as a tool platform for business. Its applications are making the scope of B
6 min read
How to make an accordion using jQuery easy UI ?
EasyUI is a HTML5 framework for using user interface components based on jQuery, React, Angular and Vue technologies. It helps in building features for interactive web and mobile applications saving a lot of time for developers. In this article, we will learn how to design accordion using jQuery EasyUI.accordion is display a collection of panels. I
2 min read
Project Idea | Web app that facilitates easy discovery of crucial medicines in nearby pharmacy
Project Title : Sehath Introduction : Domain: HealthcarePurpose:Sehath is meant to be a web app that provides people with the help of finding crucial life-saving drugs such as Remdesivir in their nearby pharmacies as soon as it becomes available. We came up with the idea during the second wave of covid pandemic in India where the majority of the af
5 min read
How to design a ticker using jQuery easy ticker plugin ?
In this article, we will learn about the jQuery easy ticker plugin which acts like a news ticker having the facility of infinite list scrolls. It is highly customizable and flexible with a lot of features. Download Link: https://github.com/vaakash/jquery-easy-ticker Note: Download the "jquery.easy-ticker.js" pre-compiled file to include in the foll
5 min read
Easy UI jQuery Introduction
Easy UI is an HTML5 framework for using user interface components based on jQuery, React, Angular, and Vue technologies. It helps in building features for interactive web and mobile applications saving a lot of time for developers. Features: We don't need to write much javascript code while using Easy UI; instead, you usually define the user interf
2 min read
How to Edit the Footer in WordPress ? (6 Easy Steps)
WordPress is a tool that helps people make and manage websites easily. It's open-source, which means anyone can use and change it for free. It started as a way to make writing look nicer, but now it's much more than that. Today, WordPress is used all over the world, not just for blogs but for all kinds of websites. WordPress is popular because it's
5 min read
Replacing spaces with underscores in JavaScript
Given a sentence and the task is to replace the spaces(" ") from the sentence with underscores("_") in JavaScript. There are some JavaScript methods are used to replace spaces with underscores which are listed below: JavaScript replace() method: This method searches a string for a defined value, or a regular expression, and returns a new string wit
2 min read
How to access an object having spaces in the object's key using JavaScript ?
Given an object and the task is to access the object in which the key contains spaces. There are a few methods to solve this problem which are discussed below: Approach 1: Create an object having space-separated keys.Use square bracket notation instead of dot notation to access the property. Example: This example implements the above approach. C/C+
2 min read
Article Tags :