Time-Savers: Code Beautifier And Formatter

Advertisement

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.

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.

Screenshot

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.

Screenshot

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.

Screenshot

6. CSS Beautifier
This tool offers a variety of options, among them – Alphabetizing Feature and De-Capitalization Feature.

Screenshot

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.

Screenshot

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.

Screenshot
Screenshot

9. Code Beautifier Plus
Beautifies Java, C# and ActionScript.

Screenshot

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.

Screenshot

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

Screenshot

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.

Screenshot

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.

  1. 1

    Binny V A

    July 12th, 2007 8:10 pm

    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.

    +1
  2. 2

    Michael

    July 12th, 2007 8:20 pm

    Better solution: (g)Vim with syntax highlighting.

    +1
  3. 3

    Skys0

    July 12th, 2007 8:38 pm

    Some useful tools ! Thank you ! :)

    0
  4. 4

    Tom

    July 12th, 2007 9:12 pm

    Ok, 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

    0
  5. 5

    marianne mcdougall

    July 12th, 2007 9:22 pm

    Some very useful tools – Thank a lot guys.

    Mari
    G3 Creative (Scotland)

    0
  6. 6

    Rick

    July 12th, 2007 9:25 pm

    I just use dreamweaver. It highlights code as well as anything Ive seen.

    0
  7. 7

    Peter

    July 12th, 2007 9:49 pm

    I 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).

    0
  8. 8

    Jeff Croft

    July 12th, 2007 10:25 pm

    I’m surprised Pygments was left off the list. For syntax highlighting, I don’t think it can be beat.

    0
  9. 9

    lizzardS

    July 12th, 2007 10:37 pm

    Awesome 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.

    0
  10. 10

    Sergej

    July 12th, 2007 11:43 pm
    0
  11. 11

    Jenny

    July 13th, 2007 12:55 am

    Thanks for this very helpful posting.

    I read about online backup on a daily dasis from an aggregator site,

    http://www.BackupReview.info

    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.

    0
  12. 12

    plasebo

    July 13th, 2007 1:01 am

    Is the javascript from google for prettifying code on webpages in this list?

    0
  13. 13

    Karl L. Gechlik

    July 13th, 2007 1:21 am

    I 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

    0
  14. 14

    Flasher

    July 13th, 2007 1:28 am

    In regards to #9. Code Beautifier Plus….you should be shot dead at your keyboard if you use on(press), etc in actionscript.

    0
  15. 15

    DynamicStability

    July 13th, 2007 2:00 am

    I’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 Code

    Is that advertising?

    0
  16. 16

    Brian H.

    July 13th, 2007 2:14 am

    For SQL, wangz.net provides a really nice SQL Instant Formatter

    0
  17. 17

    Jestep

    July 13th, 2007 2:27 am

    Anyone know of a Dreamweaver add-on that does this?

    0
  18. 18

    Benson

    July 13th, 2007 2:54 am
    0
  19. 19

    Andrey

    July 13th, 2007 3:16 am

    There 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.

    0
  20. 20

    Roberto

    July 13th, 2007 3:52 am

    There 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. :)

    0
  21. 21

    John Robo

    July 13th, 2007 4:14 am

    As 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?

    0
    • 22

      Max

      January 28th, 2010 1:27 pm

      COBOL ?
      What’s that ! :-) Sounds hard !

      0
  22. 23

    ken

    July 13th, 2007 5:09 am

    Seriously 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.

    0
  23. 24

    Michael Brennan-White

    July 13th, 2007 6:50 am

    Eclipse 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.

    0
  24. 25

    Bob

    July 13th, 2007 10:34 am

    And none of them work with velocity…

    0
  25. 26

    CFrankB

    July 13th, 2007 3:03 pm

    John Robo, the best COBOL formatter I could find is unlimited shareware; search for Cobol Beautifier.

    0
  26. 27

    Nibbler

    July 13th, 2007 5:03 pm

    Is 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).

    0
  27. 28

    Shery

    July 13th, 2007 5:05 pm

    Thanks 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

    0
  28. 29

    Traian

    July 14th, 2007 4:54 am

    Thanks for the info, i was searching for something like this :)

    Extremely useful website

    0
  29. 30

    Steve

    July 14th, 2007 5:16 am

    I 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.

    -1
  30. 31

    Timothy Long

    July 15th, 2007 12:19 am

    I’m tabified.

    0
  31. 32

    Digital Street

    July 15th, 2007 12:44 am

    Thanks for the tools review.
    I will check some of them when I can.

    0
  32. 33

    Josh

    July 17th, 2007 7:27 am

    Thanks guys. Great tools here. StartupByte.com is almost entirely built from the code/tools you guys have featured. Great work.

    0
  33. 34

    Petr

    July 18th, 2007 12:14 am

    You can also try Jush (http://jush.info/).

    0
  34. 35

    Christopher Rees

    July 18th, 2007 3:06 am

    I happen to like Scintilla, which is free and does great syntax highlighting, etc.

    http://scintilla.sourceforge.net/SciTEDownload.html

    0
  35. 36

    jmur

    July 19th, 2007 7:46 pm

    Sois una panda gays con tanto color y tanta mierda.

    Viva el VI. Y digo el VI y no el VIM.

    0
  36. 37

    LeoB

    July 20th, 2007 2:16 am

    Oh, 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 highlighting

    And you get that for a lot of programming languages, from C to XHTML, on Windows, Linux etc. That can be quite a timesave.

    +1
  37. 38

    Jestep

    July 20th, 2007 10:44 pm

    Here’s one for XHTML. I noticed that all of the examples only validated to HTML 4.0

    http://www.webmastergate.com/html-beautifier/

    0
  38. 39

    Axel

    July 24th, 2007 7:20 pm

    I’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

    +1
  39. 40

    Koesper

    July 30th, 2007 10:35 pm

    Anyone 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)

    0
    • 41

      David Levin

      February 26th, 2011 12:03 pm

      I think Dreamweaver already has a built in function for cleaning up code.
      Commands > Clean up Source Formatting

      0
  40. 42

    Koesper

    August 3rd, 2007 8:16 pm

    in 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

    0
  41. 43

    GuidoMarcel

    August 18th, 2007 2:58 am

    There is also a free online sql formatter for SQL code. http://www.sqlinform.com

    0
  42. 44

    Matt

    February 14th, 2008 12:23 pm

    Please 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/

    0
  43. 45

    Wellington Oliveira

    March 27th, 2008 9:51 am

    Polystyle do the right job!

    Dreamweaver integration with polystyle can be found here:
    polystyle.com

    Regards!
    Wellington.

    sorry, wellington, but this domain is pending renewal or deletion (editor)

    0
  44. 46

    Tester

    April 9th, 2008 1:36 am

    I need a PHP beautifier or formatter for using in cmd or Putty for Linux .

    0
  45. 47

    Jade Ohlhauser

    May 6th, 2008 9:27 pm

    CSSTidy 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).

    0
  46. 48

    Thomas Schweitzer

    June 22nd, 2008 11:43 pm

    On 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.

    0
  47. 49

    BL

    September 19th, 2008 12:27 pm

    I find it interesting to note how many people have confused Syntax Highlighting with Code Beautifying.

    0
  48. 50

    jowant

    October 17th, 2008 11:19 pm

    i think coding, technique is easy, if we unterstand of, basic principle of structure….nice post

    0
  49. 51

    zapata

    October 31st, 2008 9:06 pm

    Please 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.

    0
  50. 52

    Silver Knight

    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.)

    0
  51. 53

    Кострома

    February 25th, 2009 2:57 pm

    John Robo, the best COBOL formatter I could find is unlimited shareware; search for Cobol Beautifier…

    0
  52. 54

    Altyazı

    March 30th, 2009 2:32 am

    very interesting article . Thank you

    0
  53. 55

    Hugo

    April 28th, 2009 1:40 am

    Nice 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

    0
  54. 56

    Marvin B.

    September 6th, 2009 2:38 am

    we 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.

    +1
  55. 57

    dtecmeister

    May 13th, 2010 8:22 pm

    For C# and/or t-sql (sql server) code try: http://www.softfrontiers.com/Downloads/ReIndenter.shtml
    It’s fast and free. It only changes indentation levels for code blocks and will add comments to code block ends where possible and necessary.

    0
  56. 58

    Stephen Ferg

    July 12th, 2010 5:09 am

    I’m surprised you didn’t mention a couple of Java code beautifiers: Jalopy and Jacobe.
    Jalopy is available at
    http://www.triemax.com/

    and Jacobe at
    http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html

    0
  57. 59

    coder

    September 8th, 2010 4:55 pm

    Thanks for posting this, and also for posting all of the source code, very helpful examples. :-)

    0
  58. 60

    tejji

    January 18th, 2011 8:18 am

    Thanks for the list.
    I also found online javascript formatter which is pretty simple to use at http://www.formatjavascript.com/

    0
  59. 61

    Emily Roll

    March 16th, 2011 8:33 am

    With new version of dbForge SQL Complete you can also format a code.

    Formatting SQL Code

    +1
  60. 62

    Vik

    May 10th, 2011 11:39 pm

    http://www.htmlbeautifier.net
    HTML Beautifier .Net is advanced and flexible solution for .Net applications to filter, clean up and modify HTML, XHTML, ASPX, XML documents at server-side. The component can be easily integrated into any type of .Net application, either ASP.Net websites, Console or Windows Forms applications, to replace, remove or change any HTML/ASPX/XML tags, attributes, CSS, scripts, comments, forms, everything what you want to change in HTML document on fly.

    +2
  61. 63

    Antoine Martin

    May 13th, 2011 4:15 am

    Hi,

    Does an extension exist on notepad++ to beautify php,html,js ?

    Thanks

    +1
  62. 64

    Max

    June 26th, 2011 9:36 pm
    +2
  63. 65

    hamed

    September 30th, 2011 8:56 am

    SourceFormatX is fake don’t use it i have purchased version it isn’t complete software i have request money refund but they don’t back my money

    -1
  64. 66

    Kai

    October 6th, 2011 11:59 am

    I am missing Jindent a Source Code Formatter for Java and C/C++.
    Very nice IDE integrations for Eclipse, Netbeans, IntelliJ IDEA, JDevelopers…

    http://www.jindent.com

    0
  1. 1

    Vik

    May 10th, 2011 11:39 pm

    http://www.htmlbeautifier.net
    HTML Beautifier .Net is advanced and flexible solution for .Net applications to filter, clean up and modify HTML, XHTML, ASPX, XML documents at server-side. The component can be easily integrated into any type of .Net application, either ASP.Net websites, Console or Windows Forms applications, to replace, remove or change any HTML/ASPX/XML tags, attributes, CSS, scripts, comments, forms, everything what you want to change in HTML document on fly.

    +2
  2. 2

    Max

    June 26th, 2011 9:36 pm
    +2
  3. 3

    Binny V A

    July 12th, 2007 8:10 pm

    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.

    +1
  4. 4

    Michael

    July 12th, 2007 8:20 pm

    Better solution: (g)Vim with syntax highlighting.

    +1
  5. 5

    LeoB

    July 20th, 2007 2:16 am

    Oh, 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 highlighting

    And you get that for a lot of programming languages, from C to XHTML, on Windows, Linux etc. That can be quite a timesave.

    +1
  6. 6

    Axel

    July 24th, 2007 7:20 pm

    I’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

    +1
  7. 7

    Antoine Martin

    May 13th, 2011 4:15 am

    Hi,

    Does an extension exist on notepad++ to beautify php,html,js ?

    Thanks

    +1
  8. 8

    Marvin B.

    September 6th, 2009 2:38 am

    we 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.

    +1
  9. 9

    Emily Roll

    March 16th, 2011 8:33 am

    With new version of dbForge SQL Complete you can also format a code.

    Formatting SQL Code

    +1

Leave a Comment

Yay! You've decided to leave a comment. That's fantastic! Please keep in mind that comments are moderated and rel="nofollow" is in use. So, please do not use a spammy keyword or a domain as your name, or it will be deleted. Let's have a personal and meaningful conversation instead. Thanks for dropping by!

↑ Back to top