Emacs: Change Default Font Size by Command, for Current Session 🚀

By Xah Lee. Date: . Last updated: .

This command set a default font size across all buffers and windows, for the current session only.

put this in your Emacs Init File:

(defun xah-set-default-font-size ()
  "Set default font globally.
Note, this command change font size only for current session, not in init file.
This command useful for making font large when you want to do video livestream.
URL `http://xahlee.info/emacs/emacs/emacs_set_default_font_size.html'
Version: 2021-07-26 2021-08-21 2022-08-05"
  (interactive)
  (let ((xfSize (read-string "size:" "16" nil "16")))
    (if (> (string-to-number xfSize) 51)
        (user-error "Max font size allowed is 51. You gave %s " xfSize)
      (set-frame-font
       (cond
        ((eq system-type 'windows-nt)
         (if (member "Consolas" (font-family-list)) (format "Consolas-%s" xfSize) nil))
        ((eq system-type 'darwin)
         (if (member "Menlo" (font-family-list)) (format "Menlo-%s" xfSize) nil))
        ((eq system-type 'gnu/linux)
         (if (member "DejaVu Sans Mono" (font-family-list)) "DejaVu Sans Mono" nil))
        (t nil))
       t t))))

Emacs Font Setup