Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use indentation in a <code> tag?

Tags:

html

I have a code tag with some computer code:

<code>
    int main(){  <br/ >
        printf("Hello World!");<br/ >
    }
</code>

But when I display it in the browser, there will be no indentation. How can I do this, besides using &nbsp;? Writing them would be a very tedious job.

like image 411
Edward Karak Avatar asked Feb 08 '14 13:02

Edward Karak


People also ask

How do you indent in code?

Should You Use Tab or Space to Indent? Technically, it is fine to either indent using the tab key or with the space bar. Indenting once with the tab key means just pressing the tab key once. Indenting once with the space bar means pressing the space bar 4 times.

Should you indent HTML code?

No. HTML code does not need to be indented, and all browsers and search engines ignore indentation and extra spacing. However, for any human reader, it's a good idea to indent your text because it makes the code easier to scan and read.

How do I indent a paragraph in HTML?

Indent the first line of a paragraph with text-indentPixels (px), em, rem, even percentage (%) units will work. Using a relative unit like percentage will change the amount of indentation based on the width of the webpage.


1 Answers

<code>
    <pre>
        int main(){  
            printf("Hello World!");
        }
    </pre>
</code>

You can use the "pre" tag, which defines preformatted text. Text in a "pre" element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks. It is used when displaying text with unusual formatting, or some sort of computer code. And you will not need additional "br" tags.

Your code should look like the above one.

You can find more about the tag here.

like image 118
Lilit.Petrosyan Avatar answered Oct 08 '22 06:10

Lilit.Petrosyan