How do I change Emacs' default font size and font type?
Asked Answered
L

9

100

I am using Emacs 23.3. How can I change the font size and font type?

Lynd answered 17/5, 2011 at 5:44 Comment(1)
A similar question about changing the default font size and saving it to .emacs: https://mcmap.net/q/86669/-how-to-set-the-font-size-in-emacs/94687Brouwer
C
97

You can use the menu bar. Go to Options->Set Default Font....

After you choose a font, don't forget to press Options->Save Options—otherwise your new font will not be saved after you close Emacs.

Consultative answered 17/5, 2011 at 5:54 Comment(10)
This doesn't work (perhaps it used to?) It only changes the font for the current frame, and it does not get saved for future sessions. See this answer for a method that works.Giliane
@alexis: It still works for me on Emacs-24.2. Here'a screenshot. (Sorry for the hideous font choice :P.) It also saved properly when I restarted Emacs. Perhaps you have a configuration difference on your end or something?Consultative
My version is barely different: I've got GNU Emacs 24.3.1 on OS X, and it doesn't work. Clearly something is different, but see also the question and discussion at the answer I linked to. That approach saved the day for me. I guess the conclusion is "YMMV".Giliane
Didn't work for Emacs 24.4 on OS X 10.10.5 either. But direct change to ~/.emacs works.Outer
If you hid the menu bar but still would like to use a GUI font picker with previews, you can use M-x menu-set-font.Guanidine
Or you can still press F10 and select Options->Set Default Font menu item.Nursemaid
Emacs 26.3, on OS X, seeing the same behavior: "Save for future Sessions" direct from the menus doesn't work, but M-x customize-face RET default RET then making some change (because the shown value is what I picked from the "Set default Font" menu), and telling customize to save it wrote the correct custom-set-faces clause to my init.el file. It's as though customize on Mac doesn't think anything is changed if you change the font via the menu, so it won't write anything out. Touching the value inside the customize buffer makes it think that a change really happened.Pretonic
It worked fine on Emacs 27.1 compiled from source on Ubuntu MATE 20.04 (Focal Fossa).Mendicity
Still doesn't work in emacs 27 on mac os monterey. I was able to get the same behavior by M-x customize-face default and then changing the size there, but I had to make sure to UNcheck the background and foreground options there, otherwise customize-theme doesn't workUllund
Emacs 28.0.91 on Mac OS 11.6.4. Set Default Font worked for me. However to get it to persist, after you set the Font, you have to click Save Options in the menu. I do recall that this didn't seem to work last time I tried with Emacs for OSX 27 last year. I'm using a custom compiled version of v. 28.Stoic
Z
148

You can also do the following in your .emacs file.

Emacs 23.1

(set-frame-font "Inconsolata 12" nil t)

Older versions of Emacs

(set-default-font "Inconsolata 12" nil t)
Zerlina answered 18/5, 2011 at 21:3 Comment(3)
(set-default-font Fontname-Size) is now deprecated use (set-frame-font Fontname-Size)Sonnnie
You should also set the FRAMES argument to t to affect all frames, not just the current frame. (set-frame-font Fontname-Size nil t)Consequence
You can also run describe-font to determine current font (for example if it's set throught customize) or to figure out possible options for "full name"Obola
C
97

You can use the menu bar. Go to Options->Set Default Font....

After you choose a font, don't forget to press Options->Save Options—otherwise your new font will not be saved after you close Emacs.

Consultative answered 17/5, 2011 at 5:54 Comment(10)
This doesn't work (perhaps it used to?) It only changes the font for the current frame, and it does not get saved for future sessions. See this answer for a method that works.Giliane
@alexis: It still works for me on Emacs-24.2. Here'a screenshot. (Sorry for the hideous font choice :P.) It also saved properly when I restarted Emacs. Perhaps you have a configuration difference on your end or something?Consultative
My version is barely different: I've got GNU Emacs 24.3.1 on OS X, and it doesn't work. Clearly something is different, but see also the question and discussion at the answer I linked to. That approach saved the day for me. I guess the conclusion is "YMMV".Giliane
Didn't work for Emacs 24.4 on OS X 10.10.5 either. But direct change to ~/.emacs works.Outer
If you hid the menu bar but still would like to use a GUI font picker with previews, you can use M-x menu-set-font.Guanidine
Or you can still press F10 and select Options->Set Default Font menu item.Nursemaid
Emacs 26.3, on OS X, seeing the same behavior: "Save for future Sessions" direct from the menus doesn't work, but M-x customize-face RET default RET then making some change (because the shown value is what I picked from the "Set default Font" menu), and telling customize to save it wrote the correct custom-set-faces clause to my init.el file. It's as though customize on Mac doesn't think anything is changed if you change the font via the menu, so it won't write anything out. Touching the value inside the customize buffer makes it think that a change really happened.Pretonic
It worked fine on Emacs 27.1 compiled from source on Ubuntu MATE 20.04 (Focal Fossa).Mendicity
Still doesn't work in emacs 27 on mac os monterey. I was able to get the same behavior by M-x customize-face default and then changing the size there, but I had to make sure to UNcheck the background and foreground options there, otherwise customize-theme doesn't workUllund
Emacs 28.0.91 on Mac OS 11.6.4. Set Default Font worked for me. However to get it to persist, after you set the Font, you have to click Save Options in the menu. I do recall that this didn't seem to work last time I tried with Emacs for OSX 27 last year. I'm using a custom compiled version of v. 28.Stoic
C
13

Get current font by: M-x describe-font

(Hit Enter if you see Font name (default current choice for ASCII chars): )

This will show a list of attributes which can be set in init.el. After you've had a look the values, minimize the message buffer by C-x 1.

Now do a M-x customize-face and:

  1. Scroll down to the "Default" section
  2. Change the value of "Font Family"
  3. Change the value of "Height"
  4. Hit Enter on "State" and then 1 = Save for Future Sessions

Alternatively, in init.el you could have something like:

(set-face-attribute 'default nil :font "Monospace" :height 160)

Note: If you have a preset for window size (width and height), the height attribute of the font is going to interfere with that layout.

Chemosphere answered 1/4, 2020 at 23:37 Comment(1)
On Ubuntu 20.04.2 emacs 27.2 example: (set-face-attribute 'default nil :font "Ubuntu Medium" :height 160) . Use M-x menu-set-font to get a pop-up and see the available fonts on your install.Convulsion
G
8

To get an extended list of customization use

M-x customize-face RET

Groome answered 3/6, 2011 at 5:59 Comment(0)
S
4

Emacs 25.1 on macOS has Menlo 12 as default. I wanted to increase the size.

C-x C-f ~/.emacs

Add this to end of the ~/.emacs file:

(set-default-font "Menlo 14")

To see the change take effect immediately while staying in ~/.emacs:

M-x eval-buffer [RET]

Stipitate answered 21/3, 2017 at 2:34 Comment(1)
This works for the FIRST file I open when launching emacs, but then subsequent buffers use the smaller font again.Impious
B
4

In my answer, I'll concentrate on setting the default font size through X resources. The use of X resources has already been mentioned in the answer mentioning ~/.Xdefaults; I'll give more details (the same which I have already described in https://unix.stackexchange.com/a/426914/4319. Apart from the height of the "default" "face" in Emacs, one can similarly set other font parameters.

To set a specific default font height for Emacs, I have put into /etc/X11/Xresources-site (/etc/X11/Xresources is also OK, though can be overwritten by your distro):

Emacs.default.attributeHeight: 94

This would affect also remote X clients which are Emacs (e.g., emacs started on a remote host via ssh).

/etc/X11/Xresources-site and /etc/X11/Xresources (and probably ~/.Xresources and ~/.Xdefaults) are usually read at the start of your X session; to affect your current X resources immediately, run something like xrdb -merge /etc/X11/Xresources-site. The X resources can be viewed by xrdb -query.

Actually, in my case, /etc/X11/Xresources-site is being read thanks to a line in /etc/X11/Xresources (which is read by the start scripts):

#include "/etc/X11/Xresources-site"

so /etc/X11/Xresources is the thing that is read for sure.

There are also some files with the same syntax which are read each time an X program like emacs starts. In my case, they are: ~/.Xdefaults-MY_HOST_NAME, /etc/X11/app-defaults/Emacs (only for emacs-athena, not for emacs-gtk3), /usr/share/X11/app-defaults/Emacs etc. (But I like the idea of loaded X resources more -- shown with xrdb -query; so that remote X clients read the same X resources.)

Other X resources which Emacs understands are described at https://www.gnu.org/software/emacs/manual/html_node/emacs/Table-of-Resources.html#Table-of-Resources.

Emacs 24.3 had a bug which made it not honor the attributes for the default face coming from the X resources, such as in my example above. This was fixed since 24.4.

Brouwer answered 27/2, 2018 at 16:47 Comment(0)
B
3

The Emacs way

  1. M-x customize-group
  2. Enter faces
  3. Click on "Basic Faces"
  4. Open / Expand "Default"
  5. Change the font name (like "Inconsolata") and deselect "foundry"
  6. Click "Apply and save"
Benzene answered 6/1, 2021 at 20:41 Comment(1)
What makes it the Emacs way, in particular?Mendicity
S
2

If you use Linux/X11, you may need to set this in ~/.Xdefaults. I have set the font there since the other answers here have no effect.

I'm able to see available font settings by running in Emacs: helm-select-xfont

Then I start typing Conso and I see entries like:

-Consolas-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1
...

So then I put it into ~/.Xdefaults, setting size 12 as:

Emacs.font: xft:-*-Consolas-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1

and restart Emacs.

Shanley answered 30/1, 2017 at 17:41 Comment(0)
D
2

Simply press M-x, and then type in set-frame-font. All available fonts which exist in your machine will be displayed.

Choose the one you look for. I use this way to change font-type in my Emacs so simply; rather than altering the .spacemacs or .emacs file.

Dasya answered 27/11, 2019 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.