To display code...

Using:

<code>
a=a+1
</code>

in a html5, displays "a=a+1" almost correctly like code would look like.

Question: What other tag types are able to display code parts on a website like code (different than the text description)?

I want test them and choose a good one for my use.
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA Engineer IIICommented:
<pre> Pre formatted
<samp> Sample output
<xmp> lets you display html code without requiring escape characters
<textarea>
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
<pre> looks good. But it centers the code. I added the following to mt css:

pre {
    display: block;
    font-family: monospace;
    white-space: pre;
    margin: 1em 0;
      text-align:left;
}

But it is still centered. What am I doing wrong here?
0
jmcgOwnerCommented:
Remember that the <code> tag is both a semantic marker and a kind of formatting directive. If you want your code display to break lines to fit into the browser's rendering window, you can leave it at that. If breaking the lines would mess up the code, you may want to include a <pre> tag (for pre-formatted text, text formatted by white space and other typographical conventions).

You can get fancier with CSS.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Julian HansenCommented:
There is always Google Prettify. Javascript library with various options to display your code.
https://github.com/google/code-prettify
Sample of how it looks here
1
Dave BaldwinFixer of ProblemsCommented:
<pre> does Not center your code.  Something else is doing that.
1
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
I find <xmp> the best. Regarding text justification: Considering number of the tabs prior to the start of the following line, it really was not centering. I had like

<pre>
                                   a=1+1 			
</pre>

Open in new window


but i needed to have it like:

<pre>
a=1+1 			
</pre>

Open in new window


edited: <xmp> has been deprecated so I am back using <pre>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.