Google Docs Code Block: Insert and Format Code
November 11, 2026 · 10 min read
Google Docs Code Block: How to Insert and Format Code
A Google Docs code block is a native Docs element that formats code, but only on certain paid Google Workspace editions. If your account has it, insert one from Insert > Building blocks > Code blocks. If it doesn't, you can build a clean monospace block by hand or with the Code Blocks add-on.
Below are all three routes, plus the settings that stop Docs from quietly rewriting quotes and symbols in your code. If you're moving code between Docs and Markdown, the Google Docs to Markdown converter handles the clipboard side of that trip.
How to Insert a Google Docs Code Block on Workspace
Google launched native code blocks in December 2022 and added 14 more languages in April 2025. The steps come from the April 2025 Workspace Updates post, the most recent official source we found as of November 2026.
- Open the document and put your cursor on an empty line.
- Click Insert, then Building blocks, then Code blocks.
- Pick your programming language from the list.
- Paste or type your code inside the block.
There's a faster route from the keyboard. Type @ on an empty line, search for Code blocks, then choose the language. Both routes produce the same block. Google moves menu items from time to time, so if Building blocks doesn't list it, try the @ route before you assume your account lacks the feature.
The April 2025 update added C#, Go, Kotlin, PHP, Rust, TypeScript, HTML, CSS, XML, JSON, Protobuf, Textproto, SQL and Bash/Shell to the original set. Google's 2022 post says the block saves you from highlighting syntax by hand, but it doesn't document the exact styling. Check how the block looks in your own Doc before you share it.
Why Can't You Find Code Blocks in Google Docs?
The menu item only appears on eligible accounts. Google's December 2022 announcement says the feature isn't available to users with personal Google Accounts. A free Gmail login won't show it, however long you wait.
On Workspace, the edition decides it. The 2025 post lists Business Standard and Plus, Enterprise Starter, Standard, Plus and Essentials Plus, and Education Standard and Plus. The 2022 post names Business Starter among the editions that don't get it.
Google also says there's no admin control for this feature, so your IT team can't switch it on for you. Rollouts were gradual too: the 2022 notes warned it could take longer than 15 days to appear, and the 2025 notes allowed up to 15 days. If you're on an eligible plan and still don't see it, ask your admin which edition your account is on.
How to Build a Code Block in Google Docs by Hand
On a personal account, a 1x1 table makes a convincing Google Doc code block. It keeps the code visually separate, and the shaded cell tells readers where the snippet starts and stops.
- Click Insert > Table and choose a single cell (1 x 1).
- Copy the code from your IDE, click inside the cell and paste with Ctrl+Shift+V (Cmd+Shift+V on a Mac). Google's keyboard shortcuts page lists it as paste without formatting.
- Select the text and switch it to a monospace font.
- With the cell selected, use the toolbar's Background color to pick a light grey.
- Open Format > Line & paragraph spacing and set it to Single, so the lines sit tight like they do in an editor.
To adjust the inner padding, right-click the table and choose Table options. The Cell section sets padding and vertical alignment.
Here's the limitation: a hand-built block has no syntax colours. Every keyword, string and comment stays the same colour unless you colour them yourself, which isn't worth it for anything longer than a few lines.
What Font Is Code Written in Google Docs?
Code goes in a monospace font, where every character takes the same width. That keeps indentation and aligned comments lined up exactly as they were in your editor. A proportional font like Arial squeezes spaces and breaks that alignment.
Courier New usually appears in the font list already. For more choices, open the font menu, pick More fonts and search by name for Roboto Mono, Source Code Pro or Inconsolata. All three are Google Fonts families, so they render the same for everyone who opens the Doc.
We prefer Roboto Mono at 10 pt inside a light grey 1x1 table. It reads more cleanly than Courier New at small sizes, and the shading separates code from prose without any extra styling.
Stop Docs From Rewriting Quotes, Symbols and Links in Code
Docs' Autocorrect is built for prose, and it can quietly break code. Straight quotes can turn curly, typed character pairs can become symbols, and a URL in a string can become a link. Code that looks fine in the Doc then fails when someone pastes it back into an IDE.
Here's what a Python line looks like before and after curly quotes get applied:
print("Hello, world")
print(“Hello, world”)
The first line runs. The second throws a SyntaxError, because Python only accepts straight quotes as string delimiters.
Google's Autocorrect help page puts the switches under Tools > Preferences > Substitutions. Untick Link detection, and untick Automatic substitution to stop character pairs being swapped for symbols. If your Preferences window has a smart quotes option, untick that too. Google notes you can only change these settings on a computer, not on Android or iPhone.
Docs can also autoformat Markdown, which turns asterisks and other symbols into formatting as you type. Untick Enable Markdown in the same Preferences window while you paste code. Our Google Docs Markdown guide explains what that setting does the rest of the time.
Tabs are the other trap. Tabs can line up differently in a Doc than in your editor, so convert them to spaces in your IDE before you copy.
Code Formatter for Google Docs: The Code Blocks Add-on
If you want colours without a Workspace plan, the best-known option is Code Blocks, a free add-on by Alex Forsythe. You select some code, choose a language and a colour theme, and click Format. It can format inline or as a block, and its listing says block mode uses a 1x1 table, the same trick as the manual method.
To install it, click Extensions > Add-ons > Get add-ons, search for Code Blocks and click Install. Google's help page warns that most add-ons ask for access to data, so read the permissions screen before you click Allow. Code Blocks asks to view and manage the documents it's installed in, run when you're not present, and see your account email and profile info.
Two caveats before you rely on it:
- The listing says it doesn't provide real-time syntax highlighting. Formatting is a one-off action, so edit the code first and format it last.
- Several Marketplace reviews posted since June 2026 say it stopped working for them. Test it on a copy of your Doc before you depend on it.
If it fails, search the Marketplace for other code-formatting add-ons. We haven't vetted them, so apply the same permissions check.
Sometimes a picture of the code is enough, for example in a printed handout. Our code to image tool runs in your browser and exports a highlighted PNG or SVG that you can insert into the Doc like any other image. Readers can't copy code from an image, though, so keep a text version nearby.
Native Block, Add-on or Table: Which Fits Your Account?
Your account type usually makes the choice for you. Here's how the three routes compare:
| Feature | Native code block | Code Blocks add-on | Manual 1x1 table |
|---|---|---|---|
| Account needed | Eligible paid Workspace edition | Any account allowed to install add-ons | Any Google account |
| Syntax colours | Likely, but Google doesn't document the styling | Yes, from a chosen theme | No |
| How it's built | A Docs building block | Coloured text, block mode in a 1x1 table | A table cell you style yourself |
| Third-party access | None | Documents it's installed in, plus account email and profile | None |
| Effort | One menu pick | Install once, then select and format | About five formatting steps |
If you have the native code block in Google Docs, use it. On a personal account, start with the manual table for short snippets that need to stay readable. Try the add-on when colours matter, such as a teaching handout or a code review doc, and keep the table as your fallback. For Microsoft Word, our guide to a code block in Word covers five ways to build one.
Moving Code Between Google Docs and Markdown
Code doesn't always leave Docs the way it went in. If you export a Doc to a .md file, our Google Docs to Markdown guide covers what survives the trip. Check every snippet afterwards and wrap it in triple backticks where it lost its formatting. The Markdown code block guide has the full fence syntax.
Going the other way, you can draft in Markdown first. The Google Docs to Markdown tool runs in your browser. It turns rich text you paste from Docs into Markdown, and renders Markdown as styled text you copy and paste into a Doc. There's no Drive connection, so you work through the clipboard. For documentation that changes with the code, consider a docs as code workflow, where pages are plain-text files in Git.
Google Docs Code Block Questions
A Google Docs code block is easy on an eligible Workspace plan and takes a few minutes of styling everywhere else. Whichever route you pick, paste without formatting and switch off substitutions before the code goes in. Prefer to draft code-heavy notes in Markdown first? Our free Markdown editor has a Code Block toolbar button and a Ctrl+E (Cmd+E) shortcut for fenced blocks.