Tab Space in HTMLIn HTML, white spaces are the characters that are not observable on a web page. A tab space is a character that takes the white space of 4 spaces in HTML, which means a single tab character denotes four white spaces. The web page will show only one white space when you give many white spaces or tabs in HTML code. Let us see an example to comprehend it properly. ExampleWe have added extra white spaces and tab spaces between the words in <title> element, <h1> element and <p> element. We have also added line spaces between the tags. We will see how the web browser responds to the following code. Code: Output: We can see that extra spaces in the HTML code do not affect the web page because the number of white spaces between the words and tags is only one space. If you want to add tab space in your HTML, then you do not need to worry because there are many ways to add tab spaces in the HTML: 1. <pre> tagWe can add tab space in the HTML code with the help of <pre> tag. It displays the white spaces or tab spaces as they are added to the HTML code. Syntax of the <pre> tag: <pre> is the starting tag, and </pre> is the ending tag, as shown in the above syntax. A text with tab spaces can be written inside the starting and ending tags. Example: We will add tab spaces between the words in this example. Code: Output: We can see in the output that there is a tab space between the words in the paragraph. 2. CSS ClassWe can use CSS classes to display the tab spaces on the web browser. .class is the CSS selector used to select the HTML element. A period character, which is (.), and a class is written after the period character to specify the CSS class. The class name should be relevant to the style we want. Since we will display tab spaces, we will use the class name as ".tab-space". We can use the margin or padding property and provide them values to display the tab space & set the display property to inline-block, which ensures there is no line break after the HTML element. The display with an inline-block value mainly provides space just after the text. Syntax of the CSS class: The class name in the above syntax is .tab-space. The CSS properties are display and margin-left. The padding property of CSS can also be utilized rather than only the margin-left property. Example: We will exemplify tab spaces using the CSS class selector in the example. Code: Output: We can witness one tab space between each paragraph word in the output. 3. white-space CSS propertyThe white space is the CSS property we can utilize to demonstrate tab space on the web page. This CSS property demonstrates tab space as they have been written in the HTML code. Syntax of the white-space CSS property: white-space is the CSS property with the value assigned to pre-wrap in the provided syntax. Example: We will exemplify the white-space property to view the tab spaces between the words. Code: Output: We can see a single tab space between each word in the paragraph. 4. HTML entity - is the entity of HTML that we can utilize to demonstrate normal white space or 1 white space gap to display tab space on the web browser using the HTML entity. Syntax: is the abbreviation for non-breaking space that prevents line breaks and can display tab space using the above syntax. Example: In this example, we will use the 4   to demonstrate one tab space on the web browser. Code: Output: We can see one tab space after the word "entity" in the paragraph present in the output. 5. HTML entity -    is the HTML entity used to demonstrate two white spaces gap to show tab space on the web browser   HTML entity. Syntax:   is for wide space that can show tab space using the above syntax. Example: In this example, we will use the 2   to demonstrate two tab spaces on the web browser. Code: Output: 6. HTML entity -    is the entity of HTML that we use to denote four white spaces' gap so we can use   HTML entity and show tab space on the web browser. Syntax:   is used for wider space and can display tab space on the web page using the above syntax. Example: We will demonstrate tab spaces on the web browser in this example. We can use one   to show one tab space and two   to show two tab spaces. Code: Output: We can see one tab space after the word "tab" and two after the word "space" in the paragraph. ConclusionWe have understood the tab space in HTML in the above article. There are many methods to demonstrate tab space on the web page:
Next TopicHTML HyperLinks |