How to set the font size in Emacs?

223,442

Solution 1

(set-face-attribute 'default nil :height 100)

The value is in 1/10pt, so 100 will give you 10pt, etc.

Solution 2

From Emacswiki, GNU Emacs 23 has a built-in key combination:

C-xC-+ and C-xC-- to increase or decrease the buffer text size

Solution 3

Press Shift and the first mouse button. You can change the font size in the following way: This website has more detail.

Solution 4

M-x customize-face RET default will allow you to set the face default face, on which all other faces base on. There you can set the font-size.

Here is what is in my .emacs. actually, color-theme will set the basics, then my custom face setting will override some stuff. the custom-set-faces is written by emacs's customize-face mechanism:

;; my colour theme is whateveryouwant :)
(require 'color-theme)
(color-theme-initialize)
(color-theme-whateveryouwant)

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))
 '(font-lock-comment-face ((t (:foreground "darkorange4"))))
 '(font-lock-function-name-face ((t (:foreground "navy"))))
 '(font-lock-keyword-face ((t (:foreground "red4"))))
 '(font-lock-type-face ((t (:foreground "black"))))
 '(linum ((t (:inherit shadow :background "gray95"))))
 '(mode-line ((t (nil nil nil nil :background "grey90" (:line-width -1 :color nil :style released-button) "black" :box nil :width condensed :foundry "unknown" :family "DejaVu Sans Mono")))))

Solution 5

This is another simple solution. Works in 24 as well

(set-default-font "Monaco 14")

Short cuts:

`C-+` increases font size
`C--` Decreases font size
Share:
223,442
Juba
Author by

Juba

Updated on June 07, 2020

Comments

  • Juba
    Juba almost 4 years

    I also want to save the font size in my .emacs file.

  • HongboZhu
    HongboZhu about 12 years
    or `C-x C-=’ and ‘C-x C--’
  • sidgeon smythe
    sidgeon smythe almost 12 years
    This is local to that particular buffer. So when you switch to other files you're editing, they will not see the effect of this change. Also when you close and reopen the buffer (or even restart Emacs), they'll be at the old default size. This may be what you want; I'm just stating this for completeness.
  • Ram Narasimhan
    Ram Narasimhan almost 12 years
    @AndrewLarned To make the change permanent, you'd make the change in your .emacs file. (See Chris Conway's answer for an example of what he has in his .emacs file.)
  • The Student
    The Student over 11 years
    I'm trying to do this, but in Emacs 23.1.1 the auto-complete will only show the options set-face-background set-face-font set-face-inverse-video-p set-face-underline set-face-background-pixmap set-face-foreground set-face-stipple set-face-underline-p.
  • Rory O'Kane
    Rory O'Kane almost 11 years
    @TomBrito Which autocomplete? In my Emacs, set-face-attribute is indeed missing from M-x (execute-extended-command), but it is present in M-: (eval-expression) and C-h f (describe-function). M-: is probably what you want, if you don't want to put this in your .emacs file.
  • EdwardG
    EdwardG almost 11 years
    Many advanced emacs users prefer to not use the customize system, as it's error prone and intermingles all customizations. It's better to break your customization up into individual .el files and load them from init.el, and add your mode customizations as elisp code within each one. See huaiyuan's answer above to see how to set font via elisp.
  • Mauricio A. Cinelli
    Mauricio A. Cinelli over 10 years
    Is there any way to control how much it increases or decreases the font when doing this?
  • xwl
    xwl about 9 years
    The OP wants to save config in .emacs, and this doesn't.
  • DavidS
    DavidS about 9 years
    @RoryO'Kane Why are some commands not available via M-x? Noob question, I'm sure, but I'm not familiar with how emacs "works" at a low-level
  • Rory O'Kane
    Rory O'Kane about 9 years
    @DavidS Good question. I wrote up an answer at “Why are some Emacs functions not available via M-x?”. Researching the answer turned out to be educational.
  • Zelphir Kaltstahl
    Zelphir Kaltstahl over 8 years
    The key bindings for the mouse wheel don't work, I have version GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7)
  • Fomentia
    Fomentia about 8 years
    This is perfect! Thank you so much.
  • stefano
    stefano about 7 years
    Those would be (global-set-key (kbd "<C-mouse-4>") 'text-scale-increase) (global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease) In my version of emacs (25)
  • Ben
    Ben about 6 years
    FWIW, the emacs maintainer (presumably an "advanced" user of emacs) uses the customize system: github.com/jwiegley/dot-emacs/blob/…
  • prayagupa
    prayagupa over 5 years
    works in spacemacs UI (in macos), to set in init.el - stackoverflow.com/a/296316/432903
  • Hi-Angel
    Hi-Angel over 5 years
    This solution doesn't work though when you have customized some faces, e.g. to have a distinct font, slant, etc. They would be left with the old size, and you gotta set them individually.
  • dips
    dips about 5 years
    The changes do not persist if I restart emacs.
  • Dave X
    Dave X almost 3 years
    In elisp, these keys run the text-scale-adjust, text-scale-increase, and text-scale-mode functions in face-remap.el
  • Michel de Ruiter
    Michel de Ruiter over 2 years
    C-0 is already in good use unfortunately. And the links broke. But great idea!
  • kotchwane
    kotchwane about 2 years
    set-default-font is now deprecated. Use either (set-frame-font "Monaco 14") or (set-face-attribute 'default nil :height 130)
  • kotchwane
    kotchwane about 2 years
    If you want C-x C-+ to increase font size in all buffers, check this post
  • Matthaeus Gaius Caesar
    Matthaeus Gaius Caesar about 2 years
    Confirmed does not work in GNU Emacs 25.2.2 for my init.el file at least. I love having a beautiful night of coding on emacs, then spending 1+ hr trying to figure out how to decrease the font size.
  • G Eitan
    G Eitan about 2 years
    To keep the setting for the next time, make sure you select save options after setting the font