I love emacs,

and I want to do my web-programming work in it,
but I can't find a way to get it to edit HTML properly.

I mean it's seriously awful.

It will do HTML fine, but not PHP, javascript, etc.

I tried getting html-helper-mode... I downloaded it, put it in /usr/local/share/emacs/site-lisp, and added it to my .emacs file:

(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
  (setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))

copied and pasted from some site (I don't know elisp).
it just, doesn't highlight anything at all.

I tried downloading a whole bunch of modes and using some other mode to string them together, to no avail.

Emacs is so great in every other way--why can't it do the simple task of editing web pages? I mean, it's a pretty standard thing to do for editors these days.

So, does anyone know how to do this?

6 Answers 6


Have you checked out Emacs Wiki html page? nxhtml in particular looks useful.

  • 4
    it looks useful but it's very painful to use... it loads slowly, doesn't indent properly, is ugly, runs slow, highlights everything red and then makes it all italic and just, is painful... Aug 9, 2009 at 3:15
  • 1
    I've used nxhtml with success. Font colors and italics are all controllable by customizing the faces Aug 27, 2009 at 20:11

I had the same problem as you so I decided to write web-mode.

enter image description here

Web-mode.el is a major mode for Emacs that is intended for editing mixed web templaces (HTML with Java/JSP, PHP, CSS, JavaScript).

It doesn't rely on any other mode. It does syntax highlight et indenting according to the code block type. I've written a little HOWTO page on


  • web-mode.el is a major-mode for editing web templates (HTML with PHP, Java/JSP, JavaScripts, CSS styles).
  • web-mode.el is will never be a full featured PHP or JS mode. (We don’t encourage multi-lines blocs of code in templates !).

Native Features

  • smart indentation (according to the context : HTML, PHP, Java/JSP, JavaScript or CSS)
  • code navigation : C-c C-n between opening and closing HTML tag or between PHP controls > - if ... else ... endif, for ... endfor
  • HTML tag autoclosing (after
  • syntax highlighting (according to the type of bloc)
  • snippet insertion C-c C-i (auto indented, aware of text selection)
  • auto-inserts (ex. ?> after <?php)
  • Go to say, it saves my day... Thanks @fxbois! I love it. Finally I can get the indentation of mix between html,css,java, etc. Can it be done with Python ?
    – swdev
    Sep 11, 2013 at 1:04
  • @swdev could you open an issue on github about this request of python compatibility. Could send d a link to the template syntax documentation and an example of such a template.
    – fxbois
    Sep 12, 2013 at 6:23
  • Looks neat, but seems to use regexp for parsing HTML, rather than having a real parser like psgml... Sep 27, 2013 at 13:20
  • 3
    What do you mean by real parser ? I traverse the document to find tags that begin with < and end with > etc etc .. Have you find any limitation ? If you find any, do not hesitate to report issues on the github repo
    – fxbois
    Sep 28, 2013 at 14:44
  • Doesn't seem to play well with tidy, though :( Apr 30, 2020 at 15:34

I've been dissatisified with the available modes, but I have found happiness recently using plain old html-mode augmented with yasnippet and tidy.el. As the other answers have mentioned nxhtml mode is useful if you are writing xhtml.

If you are wanting to get highlighted php and javascript, you might want to look at mmm-mode, which will allow you to run multiple major modes at once. I've never used it, so I don't know who it handles conflicting key bindings, etc... so you'll have to feel your way around there.


Give multi-web mode a try, it's a minor mode designed with web editing in mind, it selects the appropriate major when the point moves around.


I too use nXhtml mode for mixed mode editing having failed to get Multiple Modes working correctly. It has been a bit of a rocky ride but recent builds have proved to be useful. I'm running with Emacs 23 FWIW.


I'm running Ubuntu 18.04 with emacs 25 and recently need a multimode capability for javascript and css in HTML. Researching this last night, I settled on polymode. Not many examples out there so here's a simple config for javascript and css in HTML:

;; https://polymode.github.io/installation/#activation-of-polymodes
(require 'polymode)

(define-hostmode poly-html-hostmode
    :mode 'html-mode)

(define-innermode poly-html-js-metadata-innermode
    :mode 'js-mode
    :head-matcher "^[ \t]*<script.*>"
    :tail-matcher "^[ \t]*</script.*>"
    :head-mode 'host
    :tail-mode 'host
    :body-indent-offset '2

(define-innermode poly-html-css-metadata-innermode
    :mode 'css-mode
    :head-matcher "^[ \t]*<style.*>"
    :tail-matcher "^[ \t]*</style.*>"
    :head-mode 'host
    :tail-mode 'host
    :body-indent-offset '2

 ;; html host with js and css innermodes
 (define-polymode poly-html-mode
     :hostmode 'poly-html-hostmode
     :innermodes '(poly-html-js-metadata-innermode

 ;; set mode for html files
 (add-to-list 'auto-mode-alist '("\\.html\\'" . poly-html-mode))

I put this type of stuff in a local elisp file and load it my .emacs for testing and factoring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.