Why you might want to clear output in Colab
Google Colab notebooks accumulate output as you run cells — printed text, graphs, error messages, and results all stack up and make your notebook harder to read. Clearing output is useful when you want to share a clean version of your work, reduce file size before saving, or start fresh while keeping your code intact. Unlike deleting cells, clearing output removes only what the code produced, not the code itself.
Colab gives you three ways to clear output: one cell at a time, all cells at once, or all cells plus the entire execution history. Which one you choose depends on whether you want to keep your code as-is or reset the notebook completely.
Key Takeaways
- Right-click any cell's output area and select "Clear output" to remove just that cell's results while keeping the code.
- Use the Edit menu to clear output from all cells at once without touching your code.
- "Clear all outputs" removes results but leaves code and variables in memory; "Restart and clear all outputs" also erases variables and forces you to run cells again.
- Clearing output shrinks file size and makes notebooks easier to read when sharing, but does not change the code itself.
- If you clear output by mistake, use Ctrl+Z (or Cmd+Z on Mac) to undo when ready.
Clear output from a single cell
The fastest way to clean up one cell's output is to right-click directly on the output area — the text, numbers, or graph that appeared below the code. A small menu will appear with several options. Click "Clear output" and that cell's results disappear when ready. The code stays exactly as it was.
This method works for any type of output: printed text, tables, plots, error messages, or images. If a cell produced no output (for example, a cell that only assigns a variable), there is nothing to right-click, so this option does not appear. You can repeat this for as many cells as you need to clean up.
Clear output from all cells at once
To remove output from every cell in your notebook without restarting, go to the Edit menu at the top and select "Clear all outputs". All results disappear when ready, but your code remains unchanged and any variables you created are still in memory. This is the safest option if you want a clean-looking notebook but plan to keep working.
After you clear all outputs, the notebook looks like it has never been run — no graphs, no printed results, no error messages. However, if you run a cell that depends on a variable from an earlier cell, it will work fine because the variable still exists in the notebook's memory. You only see the output when you run cells again.
Clear output and restart the entire notebook
If you want to erase everything — output, variables, and execution history — use Runtime menu and select "Restart and clear all outputs". This completely resets the notebook as if you had just opened it for the first time. All variables disappear, all output vanishes, and the next time you run a cell, it will start from scratch.
Use this option when you want to test whether your code works on its own without relying on variables from earlier runs, or when you are preparing a notebook to share and want to make sure someone opening it sees a blank slate. After restarting, you will need to run cells from the top down if you want the code to work properly.
When to clear output before saving
Colab notebooks with lots of output — especially notebooks with many graphs or large data tables — take up more storage space. If you are running low on Google Drive space or want to keep file sizes small, clearing output before saving can help. The code itself takes up very little space; the output is what adds bulk.
Before you share a notebook with someone else, clearing output is often a good idea. It makes the notebook cleaner to read, and the person receiving it can run the code themselves to see the results. This also ensures they are seeing the output from their own run, not cached results from your machine.
Undo if you clear output by mistake
If you clear output and when ready realize you needed it, press Ctrl+Z on Windows or Cmd+Z on Mac to undo. This works for clearing a single cell or all cells, as long as you do it right away. Undo only works for recent actions, so if you have run other cells or made other changes since clearing, the undo may not restore the exact output you lost.
If you restarted the notebook and cleared output that way, undo will not bring back the variables or execution history — those are gone. In that case, you will need to run the cells again to recreate the output.
Frequently Asked Questions
Does clearing output delete my code?
No. Clearing output removes only the results that appeared below each cell. Your code stays exactly as you wrote it. Even if you clear all outputs, every line of code is still there and ready to run again.
If I clear output, will my variables still work?
Yes, unless you choose "Restart and clear all outputs". Regular clearing removes only what you see on screen. Variables created by your code remain in the notebook's memory, so cells that depend on them will still work. Restarting erases the variables too.
Can I clear output from just part of my notebook?
You can clear cells one at a time by right-clicking each output, but there is no built-in way to select a range of cells and clear them all at once. If you need to clear many cells, doing them individually is the only option, or you can clear all outputs and then re-run only the cells you want to keep output from.
What is the difference between "Clear all outputs" and "Restart and clear all outputs"?
"Clear all outputs" removes what you see but keeps variables in memory. "Restart and clear all outputs" erases variables too and resets the notebook completely. Use the first if you want to keep working; use the second if you want a completely fresh start.
Does clearing output make my notebook run faster?
No. Clearing output does not change how fast your code runs. It only affects what you see and the file size. The actual computation time stays the same whether output is visible or hidden.