Emacs: Font Configuration

By Xah Lee. Date: . Last updated: .

This page shows you how to set font for emacs.

How to change font size?

Alt+x text-scale-adjust, then press 【+】 to increase, 【-】 to decrease. You can press them repeatedly. Press【0】 to set it back to default size. Press any key to exit.

Or, Alt+x text-scale-increase.

(text-scale-increase 2)  ; 2 steps larger
(text-scale-normal-size) ; default size
(text-scale-decrease 2)  ; 2 steps smaller

You can make mouse wheel with Ctrl key to increase/descrease font size. See: Emacs: How to Set Mouse Buttons.

To set font size globally in init file, just put the point size in the font name:

(add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10"))

〔►see Elisp: Determine OS, Emacs Version, Machine Host Name

How to find the current font used?

Alt+x describe-char, then look at the line in “display:”. It shows the font used for the character under cursor.

emacs describe-char
emacs M-x describe-char

How to set default font in emacs init file?

;; set a default font
(when (member "DejaVu Sans Mono" (font-family-list))
  (set-face-attribute 'default nil :font "DejaVu Sans Mono"))


;; set default font in initial window and for any new window
 ((string-equal system-type "windows-nt") ; Microsoft Windows
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10"))))
 ((string-equal system-type "darwin") ; Mac OS X
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10"))))
 ((string-equal system-type "gnu/linux") ; linux
  (when (member "DejaVu Sans Mono" (font-family-list))
    (add-to-list 'initial-frame-alist '(font . "DejaVu Sans Mono-10"))
    (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-10")))))

The above code sets a font as default for both initial and default window.

How to change font?

Chose the menu 〖Options ▸ Set Default Font…〗, then 〖Options ▸ Save Options〗.

Or, Alt+x set-frame-font then give a string of the font name.

Here's the elisp code:

(set-frame-font "DejaVu Sans Mono-10")  ; set font for current window
;; set font for all windows. keep window size fixed
(set-frame-font "DejaVu Sans Mono-10" t t)

;; set font for all windows. don't keep window size fixed
(set-frame-font "DejaVu Sans Mono-10" nil t)

How to list fonts?

(print (font-family-list))

Select the elisp code, then Alt+x eval-region. 〔►see How to Evaluate Emacs Lisp Code

You can see the result in “*Messages*” buffer. view-echo-area-messagesCtrl+h e】.

(info "(elisp) Face Attributes")

To list fonts in Linux, in terminal, type fc-list.

For a sample output of fc-list, see: linux_ubuntu_default_fonts.txt.

How to check if a font exist?

;; returns true if Symbola exists
(member "Symbola" (font-family-list))

How to install font?

Just install to the OS normally. Restart emacs. Emacs should see it.

〔►see Linux: How to Install Font

How to set font for a range of Unicode characters?

;; specify font for all unicode characters
(when (member "Symbola" (font-family-list))
  (set-fontset-font t 'unicode "Symbola" nil 'prepend))

Alt+x describe-function on set-fontset-font for detail. (info "(elisp) Fontsets")

〔►see Unicode Emoji 😄 😱 😸 👸 👽 🙋

〔►see Download Free Unicode Fonts

(info "(emacs) Fonts")

How to Display Emoji on MacOS?

emacs on macOS unicode 2017 09 22 44951
Emacs on macOS does not do unicode by default, 2017-09-22

FSF GNU emacs disabled displaying color emoji on Mac, so that Mac won't work better than linux



download font “symbola” at Download Free Unicode Fonts

Put this in your emacs init file:

;; specify font for all unicode characters
(when (member "Symbola" (font-family-list))
  (set-fontset-font t 'unicode "Symbola" nil 'prepend))
emacs on macOS unicode fixed 2017 09 22 25437
Emacs on MacOS, displaying unicode using font Symbola, 2017-09-22

Font/Unicode Topic

  1. Emacs: Unicode Tutorial
  2. Emacs File Encoding FAQ
  3. Unicode Basics: What's Character Set, Character Encoding, UTF-8?
  4. Emacs: Xah Math Input Mode
  5. Emacs: Xah Unicode Browser Mode

  1. Best Unicode Fonts for Programer
  2. Emacs: Font Configuration
  3. Emacs: Proportional Font
  4. Emacs: Cycle Fonts by Command
  5. Emacs: Set Line Spacing
  6. Emacs: toggle-word-wrap
  7. Elisp: Unicode Representation in String

Emacs Customization

  1. How to Set Emacs's User Interface
  2. Emacs: How to Install Packages Using ELPA, MELPA
  3. How to Install Emacs Package Manually
  4. Emacs: How to Define Keys
  5. Emacs: M-x customize Tutorial
  6. Emacs: Set File to Open in a Major Mode
  7. Emacs: Organize Init File
  8. Emacs: Byte Compile Elisp Files
  9. Emacs: What's Hook?
  10. Emacs: Set Environment Variables within Emacs
  11. Elisp: Determine OS, Emacs Version, Machine Host Name
  12. Elisp: Check If a {function, variable, feature} is Defined/Loaded
  13. Emacs: Set Default Window (frame) Size
  14. Emacs: Font Configuration
  15. Emacs: Set Color Theme
  16. Emacs: Save Cursor Position
  17. Emacs: Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
  18. Emacs: Stop Cursor Going into Minibuffer Prompt
Liket it? Put $5 at patreon. Or Buy Xah Emacs Tutorial. Thanks.