Regular HTML mode doesn't close tags. Or, if it does, I haven't found out how.

Transitioning out of Sublime Text, I am searching for an HTML markup mode that will close tags intelligently.

The HTML mode that came with my Emacs (on Ubuntu) can open tags automatically, but does not have a shortcut to close them (like Sublime does when you start typing greater than followed by a forward slash).

  • 3
    Emacs tells me that C-c C-e runs the command sgml-close-tag
    – npostavs
    Jun 2, 2017 at 15:20
  • 2
    web-mode should do
    – caisah
    Jun 2, 2017 at 15:48

2 Answers 2


With the default HTML mode as of Emacs 24.4, you can get the same behavior as Sublime Text (automatic insertion of the closing tag if you type </) by putting the following line in your init file:

(setq sgml-quick-keys 'close)

Out of the box, pressing C-c / or C-c C-e or C-c / inserts a closing tag (the whole </foo>).

You can find out about these keys by typing C-h m while editing an HTML file. This displays the list of mode-specific key bindings. Look for something relevant there — the keys are bound to a command called sgml-close-tag. The binding C-c / is also mentioned in the manual.

Finding out about the </ behavior is harder: it's missing both from the manual and from the self-documentation. Pressing C-h k / tells you that / is bound to sgml-slash, and that it “behaves electrically” (that's Emacs-speak for “it inserts some stuff automatically”) when sgml-quick-keys is non-nil, but to find out about close you need to look at the source code.

Note that there are other HTML modes for Emacs and they may do things completely differently.


Install web-mode, http://web-mode.org/. It is the most complete mode for web pages and does contain what it calls HTML tag auto closing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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