Blogger code prettifier


When posting code in blogger looks awful.


There is a nice open source project that prettifies the posted code.

Download code

  • download (or latest) (I includee the date so I remember when to update)
  • Extract to any folder you like on your disk.
  • open folder "prettify" and leave it open (will be needed soon)
  • Use Notepad++ for opening and copying minimized file content. Most editors mess long lines.

Create a Gadget in Blogger:

  • Layout
  • Add a Gadget (anywhere)
  • Basics
  • HTML/Javascript
  • Title: prettify (choose any title you like)
  • Content:
<style type="text/css">
===>insert contents of  prettify.css <===

<script type="text/javascript">
 ===> insert contents of prettify.js (do not use minified-does NOT work!) <===
I customize adding:
(Seems that blogger encloses post in a div with class="post" so that we can style it safely without changing the rest of the page.)
<style type="text/css">
.post .prettyprint { 
 border:1px dotted #666; 
.post .prettyprint ol.linenums li {
.post .nocode { 
 border-right:1px dotted #666; 

<script type="text/javascript>
 ===> insert contents of lang-css.js <===
 ===> insert contents of lang-sql.js <===
 ===> if needed insert contents of lang-*.js where * is apollo,hs,lisp,lua,ml,proto,vb,vhdl,wiki... <===

Modify Blogger Template:

  • Layout
  • Edit HTML
  • Click in template TextArea
  • find (^F) <body>
  • change to
<body onload="prettyPrint()" >

How to use:

Browsers display Tabs as 8 characters and not 4. So:
If you use Tabs in your source and Visual Studio 2010 then:
  1. ^A (Select All)
  2. Edit > Advanced > Untabify Selected Lines
  3. ^C (Copy)
  4. ^Z (Undo Untabify)
Clipboard now contains untabified source.
Edit the code sample you want to post
In the post enter:
<pre class="prettyprint lang-html">
Paste edited (as above) code here
We can replace html in lang-html with:
"bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", "xhtml", "xml", "xsl".
The above languages are supported by default. You can add more if you include the corresponding js from src folder.

Numbering lines:

<pre class="prettyprint linenums:1">/* This is line 1 of my code
 * and here's line 2 */
print("I'm line number 3");
gives (no, it doen't work- You have to go into prettify.css and delete everything about classes L0-L9:
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style:none} li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee})
/* This is line 1 of my code
 * and here's line 2 */
print("I'm line number 3");


  1. Thanks a lot! Your post was very helpful for me.

  2. There is an error in your code; your missing closing double quotes in the opening tag of the script element. Thx for the tips!

  3. Should be OK now. Thanks!
    I'm happy you found it useful.

  4. Thanks for explaining this.

  5. wat if...
    i directly copy the source code to
    blogger-design-edit html

    1. If it works for you...
      Most of the time we prefer color coding, identation etc.
      Plus escaping of some characters so they don't mess HTML.

      So try pasting your code. If you like what you see in preview, don't use any of these techniques. Otherwise...

  6. Thanks for your valuable posting.I have collect more than information from your website. It is really wonderful blog. please added more than tips. i'm working in Erp Software in india.Here providing very low price and Quality ERP,Cloud ERP, CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail

  7. hi, but it appears it does not work with C. I used:
    class=" prettyprint lang-c">

    in my engineering blog

    the code gets smeared all around for C code but works for others such as matlab and vhdl

  8. Hi this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get guidance from someone with experience. Any help would be greatly appreciated! Thanks in advance.

    What is a Medical Website? And why doctors need it for their practice?

  9. Yes, blogs use WYSIWYG editors or if you prefer you can code your post directly (as I do). But you have not. My experience stems from blogger.