Thursday, March 08, 2007

Using code Tag to Display Code in Your Blog or Website

If you post code to your blog or website, you might want to consider using the <code> element to help separate your content from the code. This can be achieved nicely by setting the style for the <code> element in your CSS. I use the following style in my blog to help format code snips that I post.

code
{
background-color: #f6ffff;
border: solid 2px #bbbbbb;
display: block;
font: courier;
margin-left: -10px;
overflow: auto;
white-space: pre;
width: 410px;
}


Sample:

<code>
#include &lt;stdio.h&gt;

int main(void)
{
printf("Hello world!\n");
return 0;
}
</code>

No comments: