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
? Writing them would be a very tedious job.
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.
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.
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.
<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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With