Smashing Magazine - we smash you with the information that will make your life easier. really.
Time-Savers: Code Beautifier And Formatter
Well-documented and readable source code is essential for every collaborative project. Logically structured, well organized and nicely formatted, the code can speed up the bug hunting and help to keep the code clean, minimal and still functional. These aspects are particularly important if the code is being developed by a group of developers: in this context a common scheme for source code presentation is necessary. You don’t have to do everything by hand; in fact, there are many tools which can save a lot of time – for you and your co-workers.
The tools and services we’ve collected below aren’t validators. They format and beautify the code; some of them can remove redundant elements. Using them, you have to make sure you have a backup, so your data can always be restored.
Let’s take a look at code beautifier and formatter which can save you a lot of time and help to maintain a clean and readable source code.
[By the way, did you know there is a brand new Smashing Wordpress Book? Push WordPress past its limits!]
Code Beautifier And Formatter
1. Quick Highlighter
Quick Highlighter can format source codes written in over 85 languages – among them C++, PHP, Ruby, HTML, JavaScript, Perl, Python, Smarty, XML and more. The tool formats source code and highlights inbuilt keywords, data types etc.
2. PrettyPrinter
Knows PHP, Java, C++, C, Perl, JavaScript, CSS. The service offers many formatting options you can use to present the code just the way you’d like it to look like.
3. PHP Code Beautifier
This tool is designed to beautify PHP code, applying most of the PEAR standard requirements to it. It can even process really scrambled scripts, e.g. all code in one line, and thus may help you to get scripts into a more readable form. It sets missing line breaks without removing any additional line breaks that you may use to group related things and corrects wrong indentation according to the level of nested braces.
4. Ruby Script Beautifier
Ruby Beautifier accepts a command-line list of file names, creates a backup copy of each named file and beautifies the originals. If there is an indentation error (an imbalance of opening and closing keywords), the script will print an error message but will save the result anyway.
5. Tabifier
The tabifier is a tool to properly indent computer code. The style it produces is a mix of my personal preferences for indentation plus what I could manage to make a program produce from dirty source. The tabifier currently supports CSS, HTML, and C Style code; the latter being anything that uses curly braces to start and end blocks, and semicolons to terminate statements.
6. CSS Beautifier
This tool offers a variety of options, among them – Alphabetizing Feature and De-Capitalization Feature.
7. CSS Formatierer und Optimierer
Has different compression layouts; you can sort selectors, properties, regroup selectors, optimize shorthands, compress colors, compress font-weight, discard invalid properties and add timestamps. You can also create a custom template the system will use to format the code. The result can be outputted as a file. A copy / mirror of the tool can be found on cleancss.com.
8. Highlight.js
Highlight.js highlights syntax in code examples on blogs, forums and in fact on any web pages. It’s very easy to use because it works automatically: finds blocks of code, detects a language, highlights it. Also available as Wordpress-Plugin and Firefox-extension. Suported languages: Python, Ruby, Perl, PHP, HTML, CSS, Django, JavaScript, VBScript, Delphi, Java, C++, SQL. Similar tools is offered by Google: Googles Javascript Code Prettifier.
9. Code Beautifier Plus
Beautifies Java, C# and ActionScript.
10. PHP Formatter
PHP formatter adds comments after control structures, colors the output, links to the php-manual by inline-functions, removes comments and removes empty lines. There are 5 pre-defined layouts, but you can also define your own styles.
11. PHP_Beautifier
A tool to beautify PHP 4 and PHP 5 source code – to run on your own server. Requires PHP 5.
12. Online Beautifier for JavaScript
The tool completely reformats the JavaScript source code, so that it becomes a little bit more readable.
13. Lorins simple code beautifier for C++, C#, Java, and Javascript
You can use the source code of this beautifier to creat your own code formatters.
14. Tidy
A classic. Tidy consists of many program libraries and comes and has many variations. E.g. you can use
- TidyGUI to format the code right on your desktop,
- HTML Tidy
- Clean up your Web pages with HTML TIDY
- HTML Code Export (software based upon Tidy)
- CSSTidy
- Perltidy
- HTML Validator Firefox Extension
Commercial Solutions
15. SourceFormatX Source Code Formatter & Beautifier
For developers. The tool supports neither HTML nor CSS; instead Javascript, VB, PHP, ASP, JSP, HTC, C, JAVA and more. Price: $36,99, Windows.
16. Polystyle
Polystyle automatically reformats source code in your personal style. Polystyle learns your formatting style by examining examples of your code. It is another Windows-tool which supports Actionscript, ASP, C/C++, C#, CMAC, CSS, HTML, Java, Javascript, JSP, PHP, Pascal/Delphi, Perl, Python and Visual Basic. Price: 79$, can be used from the shell and Windows Explorer.
Further Solutions
17. phpCodeBeautifier (Win/Linux Shell), HTB 2.0 (Shell).
The Co-Founder of Smashing Magazine. Former writer, web designer, freelancer and webworker. Author of several books. Runs the business.
- 55 Comments
- 1
- 2
July 12th, 2007 8:20 pmBetter solution: (g)Vim with syntax highlighting.
- 3
July 12th, 2007 8:38 pmSome useful tools ! Thank you ! :)
- 4
July 12th, 2007 9:12 pmOk, those are great. Has anyone seen a class library that performs code formatting for display in ASP.NET C#?
I plan to use this on my blog to show code that I find useful.
Thanks
- 5
July 12th, 2007 9:22 pmSome very useful tools – Thank a lot guys.
Mari
G3 Creative (Scotland) - 6
July 12th, 2007 9:25 pmI just use dreamweaver. It highlights code as well as anything Ive seen.
- 7
July 12th, 2007 9:49 pmI use a free piece of software (Windows only) called HTML-Kit. It offers highlighting for just about every web language, a vast repository of plugins, and a built in FTP client (very handy for editing things on the fly).
- 8
July 12th, 2007 10:25 pmI’m surprised Pygments was left off the list. For syntax highlighting, I don’t think it can be beat.
- 9
July 12th, 2007 10:37 pmAwesome tips as usual.
Though I would recommend saving a backup copy prior to using the tools. I know that sometimes TIDY can toss my whole page into a column. But it is still a useful tool, just remember it is a tool. - 10

- 11
July 13th, 2007 12:55 amThanks for this very helpful posting.
I read about online backup on a daily dasis from an aggregator site,
I have been trying to find a source code for making a sofware for online backup service. Do you know of any such codes?
Cheers.
- 12
July 13th, 2007 1:01 amIs the javascript from google for prettifying code on webpages in this list?
- 13
July 13th, 2007 1:21 amI know some programers around here that can learn from this! I have forwarded it along. Thank you for the great article.
Keep up the great work from your friends @ AskTheADmin
- 14
July 13th, 2007 1:28 amIn regards to #9. Code Beautifier Plus….you should be shot dead at your keyboard if you use on(press), etc in actionscript.
- 15
July 13th, 2007 2:00 amI’ve been using AStyle for years.
http://astyle.sourceforge.net/
Artistic Style 1.21
A Free, Fast and Small Automatic Formatter
for C, C++, C#, and Java Source CodeIs that advertising?
- 16

- 17
July 13th, 2007 2:27 amAnyone know of a Dreamweaver add-on that does this?
- 18
July 13th, 2007 2:54 amNotepad++ is a powerful and free editor.
http://sourceforge.net/project/showfiles.php?group_id=95717&package_id=102072
- 19
July 13th, 2007 3:16 amThere is one more good commercial solution: Profactor Style Manager. This tool intergrates into VisualStudio and allows adjust all styles it can apply. Nice thing, I’ve used it once.
- 20
July 13th, 2007 3:52 amThere is a nice csstidy version (same as http://www.cleancss.com) at http://www.codebeautifier.com with a portuguese version and a ’select code’ feature. :)
- 21
July 13th, 2007 4:14 amAs this post shows, c, c++, java, php, etc code formatters are about a dime a dozen.
What I need is a free formatter for COBOL.
That sure would make the task that I have to do SO much easier.
Does anyone know of a good FREE COBOL code formatter?
- 22
January 28th, 2010 1:27 pmCOBOL ?
What’s that ! :-) Sounds hard !
- 22
- 23
July 13th, 2007 5:09 amSeriously people, use Vim.
It can do twice what any of these programs can combined.
It has a steep learning curve, but so does programming; Vim is worth your time.
- 24
July 13th, 2007 6:50 amEclipse is awesome, cross platform and provides almost all of the functionality of Dreamweaver, and it is free.
You can use some of the wonderful plugins like CFEclipse and Aptana to provide syntax highlighting but also much more including the best tool for debugging purposes, code folding.
- 25
July 13th, 2007 10:34 amAnd none of them work with velocity…
- 26
July 13th, 2007 3:03 pmJohn Robo, the best COBOL formatter I could find is unlimited shareware; search for Cobol Beautifier.
- 27
July 13th, 2007 5:03 pmIs it any safe to blindly submit php code in those websites? Who knows it contains sensitive information (like database connections). Pay attention for these.
@John: So you are one of the few people who program COBOL… nice. I think you can create your own style with Notepad++ (or change one of another language). But for auto formatting, I think it’s best to write something small yourself (in VB6 you’re quickly done).
- 28
July 13th, 2007 5:05 pmThanks guys, very good tools although i use Dreamweaver in my work and also use it as an auto complete, i hate the auto generators. :S
- 29
July 14th, 2007 4:54 amThanks for the info, i was searching for something like this :)
Extremely useful website
- 30
July 14th, 2007 5:16 amI have coded in many environments, although the article is about code auto formatting software, I will just say that nothing compares to Visual Studio 2005 in real-time code formatting. It’s perfect.
- 31
July 15th, 2007 12:19 amI’m tabified.
- 32
July 15th, 2007 12:44 amThanks for the tools review.
I will check some of them when I can. - 33
July 17th, 2007 7:27 amThanks guys. Great tools here. StartupByte.com is almost entirely built from the code/tools you guys have featured. Great work.
- 34

- 35
July 18th, 2007 3:06 amI happen to like Scintilla, which is free and does great syntax highlighting, etc.
- 36
July 19th, 2007 7:46 pmSois una panda gays con tanto color y tanta mierda.
Viva el VI. Y digo el VI y no el VIM.
- 37
July 20th, 2007 2:16 amOh, I did not know you needed pretty-printers today. Don’t you know about Emacs?
To be honest, what you can get from Emacs in this area are things like:
- syntax highlighting
- easy indentation (per line or for the whole file)
- quick ways to make a html view of the code with syntax highlightingAnd you get that for a lot of programming languages, from C to XHTML, on Windows, Linux etc. That can be quite a timesave.
- 38
July 20th, 2007 10:44 pmHere’s one for XHTML. I noticed that all of the examples only validated to HTML 4.0
- 39
July 24th, 2007 7:20 pmI’m using http://www.jtidy.de to convert HTML to Wikipedia text and Java, PHP, C#, ABAP, XML, HTML and JavaScript snippets to Syntax highlighted code
- 40
July 30th, 2007 10:35 pmAnyone know of a Dreamweaver add-on that does this?
I’m also looking for a dreamweaver extension that adds CSStidy functionality to dreamweaver… havent found anything yet…
Someone should build this! (if only i knew how) - 41
August 3rd, 2007 8:16 pmin regards to my own comment above… I have started building a csstidy plugin for dreamweaver myself..
when it is finished i’ll post the results to the csstidy sourceforge project - 42
August 18th, 2007 2:58 amThere is also a free online sql formatter for SQL code. http://www.sqlinform.com
- 43
February 14th, 2008 12:23 pmPlease give my HTML Formatter a look…a lot of people have found it very handy…Drag and drop folders or files, back ups, total reformats and beautifies the code.
http://www.logichammer.com/html-formatter/ - 44
March 27th, 2008 9:51 amPolystyle do the right job!
Dreamweaver integration with polystyle can be found here:
polystyle.comRegards!
Wellington.sorry, wellington, but this domain is pending renewal or deletion (editor)
- 45
April 9th, 2008 1:36 amI need a PHP beautifier or formatter for using in cmd or Putty for Linux .
- 46
May 6th, 2008 9:27 pmCSSTidy didn’t work for me so I wrote my own and you’re welcome to it if you like: http://jadeohlhauser.com/strip/
(Windows only, sorry Tester, but you can have the source code if you like).
- 47
June 22nd, 2008 11:43 pmOn my way finding the right settings for the indenters I used, I got really annoyed trying out every setting by calling on command line again and again. Therefore I’ve developed a graphical user interface that can handle nearly any command line indenter if set up by a ini file. The app is called UniversalIndentGUI.
Also if you’re looking for the indenter that suits your programming language best, the web site might give you useful info.
- 48
September 19th, 2008 12:27 pmI find it interesting to note how many people have confused Syntax Highlighting with Code Beautifying.
- 49
October 17th, 2008 11:19 pmi think coding, technique is easy, if we unterstand of, basic principle of structure….nice post
- 50
October 31st, 2008 9:06 pmPlease note the official website of “SourceFormatX Source Code Formatter & Beautifier” has been changed to http://www.sourceformat.com, you had better modify the dead link.
- 51
November 25th, 2008 9:22 am@editor #43: It would appear that domain is again active. (It appears to be a commercial source code formatter for Windows as far as I can tell.)
- 52
February 25th, 2009 2:57 pmJohn Robo, the best COBOL formatter I could find is unlimited shareware; search for Cobol Beautifier…
- 53
March 30th, 2009 2:32 amvery interesting article . Thank you
- 54
April 28th, 2009 1:40 amNice list… I may be wrong, but I think you forgot one for Javascript minimizing:
JS Minifier
Have used it for several months now, very pleasing results.-H
- 55
September 6th, 2009 2:38 amwe just started a blog covering this topic in general. so if you’re interested you may check out . there will be following articles concerning this topic pretty soon.
- 00
There are no trackbacks at this time. If you are interested in leaving a trackback, please use this URL.
Leave a Comment
Make sure you enter the * required information where indicated. Please also rate the article as it will help us decide future content and posts. Comments are moderated – and rel="nofollow" is in use. Please no link dropping, no keywords or domains as names; do not spam, and do not advertise!
Interact
Popular
- 100 Wordpress Themes
- Photoshop Tutorials
- Fantastic Wallpapers
- 40+ Excellent Freefonts
- Dual-Screen Wallpapers
- Wordpress Themes for 2009
- Illustrator Tutorials
- Incredible Free Icon Sets
- High-Quality Free Fonts
- 30 Scripts For Galleries
- Photoshop Text Effects
- Useful Icon Sets
- Web Design Trends
- iPhone Wallpapers
- Before Launching a Website
- CSS Layouts And Templates
- Photoshop Actions
- Stunning Pictures and Photos
- Fantastic HDR Pictures
- Logo Design Tutorials
- Free Design Templates
- 10 Mistakes In Logo Design
- Photoshop Custom Shapes
- 40 Creative Design Layouts
- 8 Layout Solutions
- 53 CSS Techniques
- Photography Techniques
- Black & White Photography
- Styling Design Elements
- CSS-Based Forms
- 50 jQuery Techniques
- 50 Portfolio Websites
- 50 CSS Techniques
- Creative Logo Designs
- Desktop Wallpapers
- 25 Open Source Mac Apps
- 50 Free Icon Sets
- lovely-css: a grid-based CSS framework - http://bit.ly/ayA0wb
- How The CSS Selector nth-child Works - http://bit.ly/cgPMqe
- 33 New High Quality Adobe Illustrator Tutorials - http://bit.ly/bTgFbu
- How to Drastically Improve Your Designs - http://bit.ly/a9L1sb
- A Quick Look at Mobile Web Designs - http://bit.ly/9TCWCG
- How to Test your JavaScript Code with QUnit - http://bit.ly/da853c
- jQuery 1.4 API Cheat Sheet - http://bit.ly/5zYYnE













Make sure that you test your app after applying the modifications. There are cases when code formatters have caused errors in the code.
Also, make sure you have taken a backup before saving the formatted code.