Eddymens (List page)

Last updated 2023-11-03 06:02:08

What Are Whitespaces?


Whitespace is the space left between visible characters in any text or on-screen element. This space can be horizontal or a next-line space like a paragraph.

Examples of Whitespaces

There are different types of whitespaces including:

  • Horizontal Spacing: This is spacing between characters in a sentence or horizontally arranged on-screen elements. When it comes to text this type of space can be created using the space or tab key on the keyboard.

  • Vertical Spacing: The commonest type of vertical space is the one between paragraphs. This can usually be created using the enter key when it comes to text. This pushes the second half of the text to the next line.

In programming when a developer needs to visually represent whitespaces a special character and or symbols are used to represent this.

Here is an example in Javascript:

01: var text = 'line 1 \n line 2' 02: console.log(text) 03: // output: 04: //line 1 05: // line 2

In the above code the string 'line 1 \n line 2' is broken down into two separate paragraphs, this is caused by the introduction of \n which is known as a line-break symbol in Javascript and many other programming languages. This is an example of vertical spacing.

You can create horizontal spacing by simply using the tab character \t between the string i.e.:'line 1 \t line 2'.

Other programming languages or data exchange formats have their own syntax of character for creating spacing. For example, &nbsp; can be used to create horizontal spacing in HTML, and the <p> tag for creating vertical spacing.

01: <p>1. &nbsp;&nbsp;&nbsp; Line one </p> 02: <p>Line two </p>

Here is another article you might like 😊 "What Is A Method In Programming?"