Is there a easy way to insert source code with highlight in Google Docs?

  • Well, this question is not really a duplicate. The related question asks explicitly for Syntax Highlighting. This question is more generic. And the answer is: Currently this is not possible. You can use plugins which set colors for you, but inside the document this is just text with color, not "code" (pre). This becomes especially relevant, when handling with the document structure in the docs API.
    – Armin
    Jul 27 at 15:48

Not directly but there is an easy way to do it.

You can use the online Colorer-take5 HTML generator to produce the highlighted code. Afterwards just copy/paste it into your document, but don't forget to change the font to Courier New and probably reducing the size of it and you're done.

Here is an example for Java code and using the Eclipse style: alt text

  • 8
    Great idea, but I would suggest pygments.org to generate colored HTML (with multiple styles) and Consolas as font.
    – schlamar
    Dec 12 '12 at 21:33
  • I used Microsoft word for this. Pasted my code in Microsoft word and then copy/paste in google docs
    – gogagubi
    Jun 15 '19 at 12:19

With the new Add-Ons for Google Drive, you can get code highlighting with the Code Pretty add-on.

After installing it, you can access the add-on by clicking Add-ons → Code Pretty, → Format Selection:
Screenshot of using the add-on

This results in:
Result of using the add-on

  • 4
    This is a much better answer!
    – jackocnr
    Sep 18 '14 at 22:58
  • 3
    It is but in defense of @Lipis he answered back in 2010.
    – Asken
    Mar 5 '15 at 6:29
  • Doesn't support code on dark background Jun 6 '16 at 20:42
  • 1
    @IgorVaschuk, for me it does (for instance, I use PyCharm with the Darkula theme). I just need to cancel the highlighting in the google doc. Oct 17 '16 at 21:21
  • Dead link. Please fix
    – j08691
    May 18 at 20:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.