The major modes for SGML and HTML provide indentation support and commands for operating on tags.
HTML consists of two modes—one, a basic mode called
html-mode is a slightly customized variant of SGML mode. The
other, which is used by default for HTML files, is called
<script> element and CSS embedded in a
Interactively specify a special character and insert the SGML
‘&’-command for that character (
Interactively specify a tag and its attributes (
This command asks you for a tag name and for the attribute values,
then inserts both the opening tag and the closing tag, leaving point
With a prefix argument n, the command puts the tag around the n words already present in the buffer after point. Whenever a region is active, it puts the tag around the region (when Transient Mark mode is off, it does this when a numeric argument of -1 is supplied.)
Interactively insert attribute values for the current tag
Skip across a balanced tag group (which extends from an opening tag
through its corresponding closing tag) (
A numeric argument acts as a repeat count.
Skip backward across a balanced tag group (which extends from an
opening tag through its corresponding closing tag)
sgml-skip-tag-backward). A numeric argument acts as a repeat
Delete the tag at or after point, and delete the matching tag too
sgml-delete-tag). If the tag at or after point is an opening
tag, delete the closing tag too; if it is a closing tag, delete the
opening tag too.
Display a description of the meaning of tag tag
sgml-tag-help). If the argument tag is empty, describe
the tag at point.
Insert a close tag for the innermost unterminated tag
sgml-close-tag). If called within a tag or a comment,
close it instead of inserting a close tag.
Toggle a minor mode in which Latin-1 characters insert the
corresponding SGML commands that stand for them, instead of the
characters themselves (
Run a shell command (which you must specify) to validate the current
buffer as SGML (
sgml-validate). (In HTML mode this key
sequence runs a different command.)
Toggle the visibility of existing tags in the buffer. This can be
used as a cheap preview (
The major mode for editing XML documents is called nXML mode. This
is a powerful major mode that can recognize many existing XML schemas
and use them to provide completion of XML elements via
M-TAB, as well as on-the-fly XML
validation with error highlighting. To enable nXML mode in an
existing buffer, type M-x nxml-mode, or, equivalently, M-x
xml-mode. Emacs uses nXML mode for files which have the extension
.xml. For XHTML files, which have the extension .xhtml,
Emacs uses HTML mode by default; you can make it use nXML mode by
customizing the variable
auto-mode-alist (see Choosing Modes).
nXML mode is described in an Info manual, which is distributed with
You may choose to use the less powerful SGML mode for editing XML,
since XML is a strict subset of SGML. To enable SGML mode in an
existing buffer, type M-x sgml-mode. On enabling SGML mode,
Emacs examines the buffer to determine whether it is XML; if so, it
sets the variable
sgml-xml-mode to a non-
This causes SGML mode’s tag insertion commands, described above, to
always insert explicit closing tags as well.