CSS - How to simulate the HTML pre element with CSS

The following CSS rule simulates the look and behaviour of the HTML pre element.

.pre {
    font-family: monospace;
    white-space: pre;
    margin: 1em 0;
}

A live example:

Using the HTML element <pre> (with example XML)

HTML:

<pre>...</pre>

HTML output:

<mods xmlns="http://www.loc.gov/mods/v3">
  <titleInfo>
    <nonSort>The</nonSort>
    <title>hitchhiker's guide to the galaxy</title>
  </titleInfo>
</mods>

Using the above CSS class .pre (with example XML)

HTML:

<div class="pre">...</div>

HTML output:

<mods xmlns="http://www.loc.gov/mods/v3">
  <titleInfo>
    <nonSort>The</nonSort>
    <title>hitchhiker's guide to the galaxy</title>
  </titleInfo>
</mods>

Ads by Google


Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath