Skip to content

Instantly share code, notes, and snippets.

@jasongrout
Created June 20, 2018 19:35
Show Gist options
  • Save jasongrout/753216b2d3320b0abec6143d36f5d640 to your computer and use it in GitHub Desktop.
Save jasongrout/753216b2d3320b0abec6143d36f5d640 to your computer and use it in GitHub Desktop.
JupyterLab Theme Customization
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Modifying a JupyterLab theme\n",
"\n",
"Suppose you want to modify the colors and other styles for a particular JupyterLab theme (which we'll call the \"base theme\").\n",
"\n",
"Download the `variables.css` file from the base theme into the same directory as this notebook. For example, for the stock dark theme, download https://github.com/jupyterlab/jupyterlab/blob/master/packages/theme-dark-extension/style/variables.css by clicking on the \"Raw\" button and saving the resulting page.\n",
"\n",
"To change some parameters in the theme:\n",
"1. Change the JupyterLab theme to the base theme using the Settings menu.\n",
"2. Open the `variables.css` you downloaded above and modify whatever parameters you want. You can do this editing in JupyterLab or in a separate editor.\n",
"3. Run the following code cell to read in the `variables.css` file and apply the changes.\n",
"\n",
"Your changes are applied every time you run or rerun the cell below (saving the `variables.css` file alone will not apply your changes).\n",
"\n",
"Your customizations are contained in a cell output of this notebook. Clearing outputs in this notebook will remove your customizations and revert back to the base theme."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import display, HTML\n",
"with open('variables.css') as f:\n",
" css = f.read().replace(';', ' !important;')\n",
"display(HTML('<style type=\"text/css\">%s</style>Customized changes loaded.'%css))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
@GallowayJ
Copy link

@jasongrout Do you know how these changes can be made permanent? I've looked through the Jupyter Lab folder in site-packages but I only find index.css and editing that file doesn't seem to have any effect.

@ian-r-rose
Copy link

A more permanent solution is probably best left to a theme extension.

@jasongrout
Copy link
Author

I agree with @ian-r-rose. Make a new theme extension using your new variables.css file and install it wherever you like!

@sntgluca
Copy link

sntgluca commented Mar 5, 2019

Hi @jasongrout, may you specify if it's possible to install a theme extension without having to rebuild the whole extensions stack?

Referring to jupyterlab/jupyterlab#4064, I am afraid this route only works for single users in control of their environment, but not for users of a central system, in need of a custom theme.

Thanks

@AndrewLaganaro
Copy link

AndrewLaganaro commented Jul 14, 2019

Hello, i've tested and apparently it did not work

I've made the test with the file given here:

jupyterlab/jupyterlab#3844 (comment)

I run the cell with the code, the file IS on the folder of the notebook and IS in .CSS, but when i execute it, nothing happens. Just the message "Customized changes loaded" but nothing happens. Did the code broke or something? pls help. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment