Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent html code examples

Tags:

html

I have a website or a html page and I want to indent my code for my visitors to see. For example:

<html>
<head>
</head>
<body>
<pre>
&lt;html>
&lt;body>
&lt;p>
hi
&lt;/p>
&lt;/body>
</pre>
</body>
</html>

In html, is there a way to indent a block code without using a lot of &nbsp ; , like the <blockquote> tag. this way, I can use something like this:

<html>
<head> &lt/head> <body>
<p> Hi
</p>
</body>
</html> Using:
<blockquote>
&lt;html>
<blockquote>
&lt;head>
&lt/head>
&lt;body>
<blockquote>
&lt;p>
<blockquote>
Hi
</blockquote>
&lt;/p>
</blockquote>
&lt;/body>
</blockquote>
&lt;/html>

I was wondering if there was a better way to indent blocks of code. If not, I was wondering if there was a way to use css to change it so there is no line on the side and it looks just link a normal indent to the user.

like image 550
jeffkmeng Avatar asked Nov 02 '25 07:11

jeffkmeng


1 Answers

You can use the pre tags to make preformatted text which can be indented via normal spaces/tabs.

<pre>
    &lt;html>
        &lt;head>&lt;/head>&lt;body>
            &lt;p>
                Hi
            &lt;/p>
        &lt;/body>
    &lt;/html>
</pre>

JSFiddle

like image 149
p1xel Avatar answered Nov 03 '25 22:11

p1xel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!