How can I hide cell contents in Google Colaboratory?

  1. You right-click on the area on the left of the cell (below the "Play" button) and choose "Add a form"
  2. You can enter a title for your cell after the #@title keyword (first line in your cell code)
  3. Right-click again in the same place and choose "Form > Hide code"

The black triangle, that makes it possible to fold and unfold sections, appears when you create a section (which is equivalent to creating a title).

You can create a section by creating a text cell that starts with # <your section title>.

This is how you create title in Markdown: # This is a title ## This is a smaller title ### This is even a smaller title...

You can fold and unfold sections by clicking on the triangle next to their title.

This image illustrates how to create a section:

This image illustrates how to create a part

This image is the result of the previous image (note the magic triangle on the left):

This image is the result of the previous image note the triangle on the left


None of the other answers worked for me. You can collapse cells by adding this to the top of the cell "#@title" and then double clicking on the white space that appears to the right of it.


I realise this question was posted some time ago but as a newbie to Google Colab myself I thought it would be helpful to share what I have found useful when 'collapsing' sections of code and generally organising code within my notebooks.

To add a collapsible section: proceed title with '#', all code below will fall within this title and can be collapsed. I.e. '#Import libraries' will produce:

Collapsible Colab title

To add collapsible sub-sections (within the main header) simply add another '#', and so on. So, '##Check tf version' would fall within '#Import libraries'

I hope this is helpful!