To display 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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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 EngineerCommented:
<pre> Pre formatted
<samp> Sample output
<xmp> lets you display html code without requiring escape characters

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;

But it is still centered. What am I doing wrong here?
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.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Julian HansenCommented:
There is always Google Prettify. Javascript library with various options to display your code.
Sample of how it looks here
Dave BaldwinFixer of ProblemsCommented:
<pre> does Not center your code.  Something else is doing that.
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


Open in new window

but i needed to have it like:


Open in new window

edited: <xmp> has been deprecated so I am back using <pre>
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

From novice to tech pro — start learning today.