Reputation: 41
I've written some python code that I want to show on my website, but obviously just copying and pasting the text will render it almost unreadable due to the HTML not recognising the carriage return and removing the excess spacing.
Is there an easy way to show it in the HTML as if it were in a text editor or IDE short of CSSing the crap out of it?
Upvotes: 0
Views: 2647
Reputation: 38253
You will probably want to use the CSS white-space
property, e.g:
CSS:
div#python { white-space: pre; }
HTML:
<div id="python">
Python code
</div>
There's also different options for how the white space is treated.
The advantage to this method is the abstraction of the style information into CSS which makes the page a lot more maintainable if it needs to be edited in the future.
Upvotes: 2
Reputation: 59819
Use the <pre> </pre>
element - it does exactly what you want
Info: http://www.w3.org/wiki/HTML/Elements/pre
Upvotes: 1
Reputation: 4774
You can wrap it in a 'code' tag.
<code>this is my computer code</code>
Upvotes: 1
Reputation: 13596
<pre>
or <code>
...
Good discussion on <pre>
vs <code>
vs <samp>
Upvotes: 5