54

I am fairly new to python and have no html experience. The question has been asked and either not answered at all or not answered in enough detail for me to set the default font within iPython (not change to browser). Specifically, what has to be put in the css file and which css file should be used? I am on a Windows system.

For reference, these are in answer to the linked SO questions below:

  • in #1: an unnamed file in /usr/lib/python2.6/.../css/
  • in comment to #1: change monospace font in browser - worked but font is italic
  • in #2: custom.css in profile subdirectory /static/custom/custom.css

Related questions:

  1. Change ipython notebook font type
  2. Change font & background color in ipython notebook
  3. Changing (back to default) font in ipython notebook (unanswered) -

Edit: Changing the monospace font in my browser worked, as suggested in an answer comment of #1. However the font is italic, which is not what is intended.

1
  • 1
    There are a lot more questions with similar content, look e.g. here or here. The custom.css approach is the way to go! Commented Mar 14, 2014 at 16:51

9 Answers 9

46

You can hover to .ipython folder (i.e. you can type $ ipython locate in your terminal/bash OR CMD.exe Prompt from your Anaconda Navigator to see where is your ipython is located)

Then, in .ipython, you will see profile_default directory which is the default one. This directory will have static/custom/custom.css file located.

You can now apply change to this custom.css file. There are a lot of styles in the custom.css file that you can use or search for. For example, you can see this link (which is my own customize custom.css file)

Basically, this custom.css file apply changes to your browser. You can use inspect elements in your ipython notebook to see which elements you want to change. Then, you can changes to the custom.css file. For example, you can add these chunk to change font in .CodeMirror pre to type Monaco

.CodeMirror pre {font-family: Monaco; font-size: 9pt;}

Note that now for Jupyter notebook version >= 4.1, the custom css file is moved to ~/.jupyter/custom/custom.css instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that now for IPython version >= 4.1, custom css file is moved to ~/.jupyter/custom/custom.css instead.
I had to create the .jupyter/custom/custom.css file as it was not there by default for my install (pip). I downloaded the above said template via wget and then modified to to us a mono type font so I could discern between 1 and l .
16

In JupyterNotebook cell, Simply you can use:

%%html
<style type='text/css'>
.CodeMirror{
font-size: 17px;
</style>

Comments

10

I would also suggest that you explore the options offered by the jupyter themer. For more modest interface changes you may be satisfied with running the syntax:

jupyter-themer [-c COLOR, --color COLOR]
                      [-l LAYOUT, --layout LAYOUT]
                      [-t TYPOGRAPHY, --typography TYPOGRAPHY]

where the options offered by themer would provide you with a less onerous way of making some changes in to the look of Jupyter Notebook. Naturally, you may still to prefer edit the .css files if the changes you want to apply are elaborate.

1 Comment

But, I think that jt allows only some fonts in their allowed list, and you can only select from them.
6

The new location of the theme file is: ~/.jupyter/custom/custom.css

2 Comments

This is the new file location And edit the file to .CodeMirror pre { font-family: Anonymous Pro; font-size: 9pt; }
how for single cell?
6

In your notebook (simple approach). Add new cell with following code

%%html
<style type='text/css'>
.CodeMirror{
    font-size: 12px;
}

div.output_area pre {
    font-size: 12px;
}
</style>

Comments

4

Using Jupyterthemes, one can easily change look of notebook.

pip install jupyterthemes

jt -fs 15 

By default code font size is set to 11 . Trying above will change font size. It can be reset using.

jt -r 

This will reset all jupyter theme changes to default.

3 Comments

I might be wrong, but if you are working with the default theme, the command jt -fs 15 will not set the font size without specifying the theme jt -t name_of_the_theme -fs 15. Hence I am afraid that jt will not allow you to reset the default theme's font size.
This command will reset jupyter notebook theme to default value and wil not change the font size. The better usage is jt -t chesterish -fs 14 as @RandomWalker suggested.
jt -t chesterish -fs 14 -ofs 12 better command changes main cell font-size and output font-size as well
3

In addition to the suggestion by Konrad here, I'd like to suggest jupyter themes, which seems to have more options, such as line-height, font size, cell width etc.

Command line usage:

jt  [-h] [-l] [-t THEME] [-f MONOFONT] [-fs MONOSIZE] [-nf NBFONT]
[-nfs NBFONTSIZE] [-tf TCFONT] [-tfs TCFONTSIZE] [-dfs DFFONTSIZE]
[-m MARGINS] [-cursw CURSORWIDTH] [-cursc CURSORCOLOR] [-vim]
[-cellw CELLWIDTH] [-lineh LINEHEIGHT] [-altp] [-P] [-T] [-N]
[-r] [-dfonts]

Comments

-2

For chrome users, This is very simple.

Just install the desired font in your OS. Then open the said browser, Go to Settings -> Appearance -> Customize font.

Go to fixed width font and from drop down list select the desired font.

Note: This might also change the fonts at some other places depending on the web pages that you visit.

Comments

-3

There is a much easier way to do without adding the CSS files and all the other methods suggested. But you have to do it every time you start the Jupiter notebook.

Go to inspect in your browser and click on the element selection icon and then click on the box. And at the bottom of the page, you will be seeing the styling option for CSS where you can easily change the font-size.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.