Edited from a previous answer here:
“Current JupyterLab … has code folding ability built-in by default. To fold a cell:
Click on a code cell to highlight it as active and then click on the blue bar to the left. The code cell will ‘fold’ and be represented by three dots where the code cell was previously. You can ‘unfold’ it by clicking on the dots or on the blue bar again.”
Also under ‘View
’ on the toolbars is a range of options for collapsing all selected or all code or outputs. And below that options for expanding.
The state will be respected upon reopening in JupyterLab, as the state is encoded in ‘metadat
’ tags, see here.