CSS - How to simulate the HTML code element with CSS

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

.code {
    font-family: monospace;
}

A live example:

Using the HTML element <code>

HTML:

<code>
Console.WriteLine("Hello");
</code>

HTML output:

Console.WriteLine("Hello");

Using the above CSS class .code

HTML:

<div class="code">
Console.WriteLine("Hello");
</div>

HTML output:

Console.WriteLine("Hello");

Ads by Google


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

© Richard McGrath