As an experienced full-stack developer, Jupyter notebook is one of my most used tools for everything from data wrangling and analysis to machine learning model building. I have worked extensively with customizing and theming Jupyter over the years to optimize for long coding sessions.
In this comprehensive 3k+ word guide, I will provide my insider tips to customize the Jupyter notebook‘s look and feel specifically for developers and programmers.
Why Should Developers Care About Themes
Most developers spending hours coding in Jupyter should consider tweaking the default white notebook theme. Here are some key reasons:
1. Prevent Eye Strain and Fatigue
Staring at bright white backgrounds for long durations can strain your eyes leading to headaches and loss of productivity.
Programmers looking to code for extended uninterrupted periods should consider dark color schemes. These emit lower light levels and studies have found that dark modes lead to less eye fatigue.
2. Enhanced Focus and Concentration
Muted darker themes with sufficient contrast orient the eyes better towards the code content without unnecessary distractions. This helps you stay focused for longer periods.
Data scientists working on complex models or algorithms can benefit from themes tailored to enhance concentration.
3. Establish Personal Style
Picking a custom theme over the default white notebook is an opportunity to showcase a bit of your personality and style. Whether you prefer minimal elegance or retro green-on-black terminals, theming allows self-expression.
When sharing your analysis with colleagues and peers, your individuality can make your work more memorable.
4. Promote Brand Identity
If analyzing data related to specific brands or products, matching a custom Jupyter color scheme can help align with existing marketing material for continuity. Corporate notebooks can reuse brand style guides.
Note this is only applicable in certain business scenarios with established branding or style guides. But it allows good customization opportunities for enterprises.
Overall, while theming starts as a way to reduce eye discomfort, the benefits go deeper for developers spending a major chunk of their day using Jupyter notebooks.
Methods for Changing Jupyter Themes
There are two main approaches to modify the visual treatment of Jupyter notebooks:
1. Jupyter Notebook Themes Extension
The Jupyter community has built an excellent 3rd party extension called Jupyter Themes that is the easiest way to customize notebooks.
It contains pre-packaged themes that change the background, text fonts/colors, spacing, sizing and other elements in just a few commands.
We will cover how to install and use the Jupyter Themes extension in detail later. I highly recommend this approach.
Pros:
- Simple installation
- 30+ premade beautiful themes
- Granular control over styles
- Easy preview before applying
- Lightweight extension
Cons:
- Limited to available premade themes
- Relies on custom CSS under the hood
2. Custom Jupyter CSS Files
The internal way to modify Jupyter themes is by writing your own custom CSS rulesets and feeding it through config options.
This gives you unlimited flexibility to craft a unique color scheme and style down to the pixel. But it requires knowledge of applying CSS styles properly.
Pros:
- Pixel-perfect control over all visual elements
- Customize colors, fonts, sizes, spacing exactly
- Not limited to pre-defined themes
Cons:
- Need CSS expertise
- Hard to preview before applying
- No central library of schemes
- Manual process
As an experienced developer well-versed in CSS, SASS and styling systems, I can work with custom Jupyter CSS files comfortably.
But I would still recommend most readers use the Jupyter Themes extension first. The customization options are quite extensive without needing raw CSS skills.
Now let‘s see how to use the extensions to start modifying your notebooks!
Using Jupyter Themes Extension
I‘ll provide specific steps to change the default theme using the popular Jupyter Themes extension.
Step 1: Install Jupyter Themes
First, you need to install the jupyterthemes
Python package using pip or conda.
I prefer conda environments to keep dependencies isolated:
conda create -n jupyter-theming
conda activate jupyter-theming
pip install jupyterthemes
Alternatively, just:
pip install jupyterthemes
Verify it installed correctly by importing it in a Python cell:
import jupyterthemes
print(jupyterthemes.__version__)
You should see the current version printed without errors.
Step 2: List Available Themes
Jupyter Themes packs over 30 different styles you can preview and activate.
See all options with:
jt -l
This prints a list along with screenshots and descriptions:
Review and make a shortlist of 2-3 potential candidates.
I‘ll demo with the grade3
and oceans16
scheme.
Step 3: Live Preview Themes
Before applying any theme permanently, preview how it will look in a live notebook.
Use the -p
flag:
jt -t [theme] -p
For example:
jt -t grade3 -p
This will open a new notebook tab with the grade3
theme loaded. Now test it out by adding some code cells, Markdown text, data frames etc.
See how readable it looks and tweak settings. When ready, exit out and try another preview session with the next shortlisted theme.
Step 4: Set Chosen Theme
Once you decide on a final theme, you can set it persistently by running:
jt -t [theme-name]
After testing a few options, I liked the professional charm of oceans16
:
jt -t oceans16
The dark grey/blue color scheme is soothing and has plenty of contrast.
Now reopen your notebook and the oceans16
theme stays applied.
To reset to default light theme, use:
jt -r
And that‘s the basics of loading a premade theme package! Next, let‘s see how you can customize the active theme further.
Fine-Tuning Jupyter Themes
While the Jupyter Themes library comes packed with beautiful schemes, you may want to tweak certain elements.
Thankfully, the extensions provide additional options to control styles, fonts, sizes and other attributes.
Here are some useful customizations:
Show/Hide Interface Elements
By default, the toolbar, filename and kernel logo are hidden when applying a packaged theme.
Show them with:
- Toolbar:
jt -t [theme] -T
- Filename Path:
jt -t [theme] -F
- Kernel Logo:
jt -t [theme] -N
For example:
jt -t oceans16 -T -F -N
Code Font & Size
Change code font:
jt -t [theme] -cf [font-name]
Change code font size:
jt -t [theme] -fs [size]
I prefer using Jetbrains Mono and a size of 11pt:
jt -t chesterish -cf ‘Jetbrains Mono‘ -fs 11
Cell Font & Size
Modify text/Markdown font:
jt -t [theme] -nf [font-name]
Cell font size:
jt -t [theme] -nfs [size]
Cell Width
Set pixel width of code cells:
jt -t [theme] -cellw [width]
Plot Style
Change Matplotlib plot scheme:
import jtplot
jtplot.style()
Options like ggplot
, bmh
, dark_bg
etc.
And much more – review the Jupyter Themes docs for advanced configurations.
Sample CSS Override Rules
You can also override specific CSS rules inline to add some custom flair.
For example, to set bold red headers, add this to a Markdown cell:
<style>
.rendered_html h1 {
font-size: 2.0em;
font-weight: bold;
color: #E93535;
}
</style>
# My Analysis Report
This will apply custom CSS styling to all h1
headers.
You can craft these rules to target any elements like code cells, tables, links etc. But you need some basic HTML/CSS familiarity.
Comparing Popular Jupyter Themes
To help summarize, here is a comparison table of some of my favorite Jupyter themes from over the years:
Theme | Screenshot | Overview |
---|---|---|
Solarized Light | Clean yellow/blue scheme optimized for long coding hours. Light background is easier on eyes. | |
Ocean Light | Understated gray and blue. Code syntax highlighting remains colorized for legibility. | |
Dracula | Darker theme with glowy purple/green accents. Signature style developed by Zeno Rocha. | |
Monokai | Retro green terminal aesthetic for old-school hackers. | |
Chesterish | Minimalist tinted theme. Good contrast without bright colors. |
The list goes on – play around with jt -l
to preview other choices. The extension makes it so convenient to rapidly try different themes.
Now that you have a custom scheme set, how do you share your improved notebooks with colleagues?
Exporting Jupyter Notebooks with Themes
By default, the selected Jupyter theme you activate is stored locally in config files and won‘t carry over if you export and send your work.
However, with some additional steps, you can package notebooks to retain themes:
Bundling Config Files
When exporting a notebook using jupyter nbconvert
, you can pass the --config
argument to pick up local config files storing custom rules like current theme, CSS overrides etc.
For example:
jupyter nbconvert MyReport.ipynb --to html --config jupyter_notebook_config.py
Anyone loading the exported .html
will see the styled version.
Using Jupyter Book
Jupyter Book is an excellent tool to build documentation and books from notebooks with custom layouts and themes retained.
It has a sphinx
engine allowing you to preserve your configured schemes in published artifacts shared online or offline.
Other Options
I also recommend checking out:
- Voila – Serves live notebook server rendering for sharing
- nbpresent – Exports stylish slides/pages
- RISE – Live slideshow from notebook
Test these tools to find the right publishing format retaining your chosen styling.
The key is to bundle your various config files or use wrappers understanding Jupyter customization when exporting.
Final Words
I hope this guide gives you a very thorough overview of the theming mechanisms in Jupyter notebook and how to customize its visual treatment specifically considering developers.
Here are my key recommendations when theming your notebooks:
- Strongly consider the jupyterthemes extension before raw CSS
- Shortlist 2-3 scheme options to rapidly preview
- Begin with slight touch-ups before drastic changes
- Pair monospace fonts like Jetbrains Mono for code
- Export using nbconvert or Jupyter Book to share styled versions
- Reset to default light theme in case of issues
Customizing your Jupyter environment can greatly boost your productivity and effectiveness for long programming stretches.
Let me know in the comments if you have any other creative theme customization tips for developers!