I love using Google Docs to draft blog posts, create simple ebooks, collaborate with team members, or document my ideas, however, I faced one annoying limitation while working with codes - there’s no built-in way to insert code blocks.
That’s right. Unlike tools like Notion or Markdown editors, Google Docs doesn’t give you a dedicated “Insert Code Blocks” option.
But don’t worry - I have found some ways to do that, and in this guide, you'll learn how to add code blocks in Google Docs using a simple method. Using this method, your technical content will look neat, readable, and professional.
Whether you're a blogger, developer, student, or just someone who documents code snippets, these tips will come in handy.
Note: This article may contain affiliate links. When you click an affiliate link and make a purchase, we get a small compensation at no cost to you. See our Privacy Policy and Disclaimer for more info.
Why Use Code Blocks in Google Docs?
Before we jump in, here’s why formatting your code as a block is important:
- It enhances readability with proper spacing and alignment.
- It keeps the format consistent across platforms.
- It helps highlight syntax, especially with tools that support syntax coloring.
Adding Code Blocks in Google Docs
Google Docs offers an easy option to add code blocks to your document. To add it, go to the Insert menu and click on Building blocks >> Code block >> Programming language.
However, this feature is only available to people who have subscribed to Google Workspace Business Standard, Business Plus, Enterprise Standard, Enterprise Plus, Education Standard, Education Plus customers as well as Nonprofits[1].
So, if you have a subscription, you can insert code blocks from the Insert menu, but if you don't, then there isn't a direct method to add code blocks to your document.
In this tutorial, I will show you a method to add code blocks in Google Docs using a free Google Docs add-on.
Let's get started.
How to Add Code Block in Google Docs?
Step 1: Open your Google Doc
Step 2: Go to the top menu and click Extensions > Add-ons > Get add-ons.
Step 3: As you click on Get add-ons in the last step, Google Workspace Marketplace window will open. Here, type - Code Blocks in the search area as shown below and press the Enter button.
Now, click on Code Blocks by Alex Forsythe from the search results as shown in the below screenshot.
Step 4: Click on the Install button as shown below.
Code Block will ask for permission before the installation. Click on Continue to start the installation process. Choose your Google account to complete the installation process. After successful installation, you can find Code Block from the Extension menu.
Step 5: Now, to use the Code Block, go to the Extension menu and click on Code Blocks >> Start. See the below screenshot.
After clicking on the Start option, Code Blocks interface will appear on the right side of the Google Docs as shown below. It contain options to choose Language (e.g., JavaScript, Python, HTML) and Theme (e.g., Midnight, Classic, Eclipse).
Step 6: Now, enter some codes of any popular programming languages such as Java, C++, etc. inside your document. In the below screenshot, you can see that I have entered some codes to give you an example of adding code blocks in Google Docs.
After you click on the Preview button, you'll see the preview of the code block as shown below.
Step 7: Finally, to add the code block to your document, click on the Format button. In the below screenshot, you can see that the code block has been added to my document.
This is how, you can add code blocks to your Google documents.
Also Read: Best Minecraft Fonts on Google Docs
Tips and Tricks for Cleaner Code Blocks
Check out some important tips and tricks that will help you write cleaner code blocks for your project.
- Use consistent indentation: Stick with 2 or 4 spaces. Avoid tabs.
- Break long lines: Keep your code block within the page width.
- Avoid rich text formatting inside the code block (bold, italic, etc.).
- Use comment markers (// or #) to explain parts of your code.
- Save reusable code snippets in Google Keep for quick access.
Frequently Asked Questions (FAQs)
Below I have added some important questions and answers that will help you learn more about adding code blocks in Google Docs.
1. Can I add a code block directly in Google Docs without any add-ons?
Answer. Yes, you can manually format a code block by using a monospace font like Courier New or Roboto Mono, adjusting the font size, and adding borders or background shading. This doesn’t offer syntax highlighting, but it works well for simple snippets.
2. What is the best add-on to insert code blocks in Google Docs?
Answer. The most recommended add-on is “Code Blocks” by Alex Forsythe. It provides syntax highlighting for many programming languages and allows you to choose different themes for a polished look.
3. Does the Code Blocks add-on support syntax highlighting for all programming languages?
Answer. It supports most commonly used languages like Python, JavaScript, HTML, CSS, Java, C++, and more. While it may not support every language, it covers enough for most users’ needs.
4. Is the Code Blocks add-on free to use?
Answer. Yes, the add-on mentioned in this tutorial is completely free to install and use from the Google Workspace Marketplace. Just make sure you're signed in to your Google account to access it.
5. Can I edit code blocks later once they are inserted using the add-on?
Answer. Once you insert the code using the Code Blocks add-on, it becomes standard text with formatting applied. You can still edit it like any other text block in Google Docs.
Wrapping Up
If you're someone who regularly shares code tutorials or tech documentation in Google Docs, try out the Code Blocks add-on. It’s free, reliable, and makes your documents look polished and professional.
And using just 7 simple steps you can easily add code blocks to your document in Google Docs.
If you like this tutorial, please share it with your friends on social media networks such as Facebook, Pinterest, Reddit and others.