Introduction
(Author's notes from November 2023)
When you write multi-line code in Google Colaboratory and go over it with other people in a meeting, you often want to refer to specific line numbers.
For work I often hold online meetings on Google Meet. There's no on-screen pen, so when commenting on someone else's code I had to describe positions by line, and without line numbers that was frustrating.
The setting in this post shows line numbers and solves the problem.
In short, there are two ways to show line numbers in Colab:
- Keyboard shortcut: on Windows, press Ctrl + M then L; on Mac, press ⌘ + M (Ctrl + M also works) then L
- Menu: "Tools" → "Settings" (or the gear icon at the top right) → "Editor" → check "Show line numbers" → "Save"
Updated December 2026: rechecked the steps in the current Colab UI, added a screenshot of the current settings dialog (gear icon → Editor), the Mac shortcut notation, and the fact that the setting carries over to other notebooks.
Before: no line numbers
This is how a code cell looks before the change. Line numbers are off by default.

Option 1: keyboard shortcut
Mac: press command + m, then l (lowercase L)
Windows: press Ctrl + m, then l (lowercase L)
The trick is to press Ctrl (⌘) + M, release, and then press L. They are not pressed together. In Colab's keyboard shortcut list ("Tools" → "Keyboard shortcuts"), this action is registered as "Toggle line numbers", shown as "⌘/Ctrl+M L" on a Mac.
- Repeat the shortcut to hide line numbers again (it's a toggle).
- If nothing happens, press Esc to leave cell editing mode and try again.
- You can change the key binding in the same shortcut list.
Option 2: the settings menu
Click Tools in the menu and choose Settings. In the current Colab you can also open the same dialog with the gear icon at the top right.

Then check Show line numbers and click Save.

The two screenshots above are from 2023. As of December 2026, the settings dialog has a menu on the left with "Site", "Editor", "Subscription", "GitHub" and "Miscellaneous". Select "Editor" and scroll down a little to find the "Show line numbers" checkbox.

Here is the code cell after the change.
With line numbers visible, it's much easier to talk about the code.

In the December 2026 UI, the line numbers 1, 2, 3… appear on the left of each code cell like this:

The setting carries over to other notebooks
"Show line numbers" is not a per-notebook setting; it applies to the Colab editor as a whole. When we tested it in December 2026, it behaved like this:
- Toggling with the shortcut (Ctrl + M → L) also toggled the "Show line numbers" checkbox in the settings dialog.
- After turning it on in one notebook, line numbers also appeared when opening a different notebook.
- Line numbers stayed on after reloading the page.
On the other hand, it's a display setting for your own screen, so it doesn't affect the people you share the notebook with. If you want to say "line 5" in a meeting, ask the others to turn it on too, or share your screen while you explain.
Other Colab shortcuts worth knowing
These shortcuts use the same "Ctrl (⌘) + M, then a key" pattern as line numbers (checked against the shortcut list in December 2026).
| Action | Shortcut |
|---|---|
| Toggle line numbers | Ctrl + M → L |
| Insert code cell below | Ctrl + M → B |
| Insert code cell above | Ctrl + M → A |
| Delete cell/selection | Ctrl + M → D |
| Convert to text cell / Convert to code cell | Ctrl + M → M / Ctrl + M → Y |
| Show/hide output | Ctrl + M → O |
| Show keyboard shortcuts | Ctrl + M → H |
Summary
This post showed how to display code line numbers in Google Colab. With the shortcut, press Ctrl (⌘) + M → L; from the menu, go to Settings → Editor → "Show line numbers". Once set, line numbers also appear in your other notebooks.
Colab has many other handy shortcuts, so it's worth looking them up, for example in the article below (Japanese).

For more on using Colab, see how to set up an analysis environment with Google Drive and Colab, how to upload and read files in Google Colab and Google Colab pricing and free tier limits.
I hope this helps.

