Emacs: Xah HTML Mode Tutorial

By Xah Lee. Date: . Last updated: .

This page is a tutorial on using Xah HTML Mode

once you have installed xah-html-mode, then open any file whose name ends in “.html”. In the mode line, you'll see “∑html”, that means you are in xah-html-mode.

xah html mode modeline 2022-03-10 fcHz
xah html mode modeline 2022-03-10 fcHz

View Manual

Alt+x describe-function, then type xah-html-mode, to see the documentation.

sshot 2024-03-31 091243 3M7v
sshot 2024-03-31 091243 3M7v

The mode is completely self-documented. You can just browse the doc string in emacs.

Find Key of a Command, or Command Name of a Key

we will only mention command name here. To find the key, see: Emacs Principles, Command and Keys.

Insert Tags

To insert a tag, press Tab Space . (xah-html-insert-tag)

xah html mode insert tag 2021-09-18
xah html mode insert tag

xah-html-insert-tag is the general way to insert any html tag.

Here's specialized commands to create some commonly used tags:

Turn blocks into paragraphs.
insert a br tag.

Create List

Turn lines to a unordered list. Press Ctrl+u first for ordered list.
Turn lines to a definition list

Create Table

Turn lines into a table.

Create Link

To create a link, of url, image, pdf, etc, first paste the url or file path, then Alt+x xah-html-any-to-link

The command creates different links for different url/path. For example:

you can also call a specific command:

Embed Image

To turn a image path into a embedded image with figure and caption, Alt+x xah-html-any-to-link

Here's more specific commands:

Turn path into img tag with figure and figcaption
Turn path into img tag
Turn path into a link

Embed Programing Language Source Code

Create a pre code with class name of a programing language.
Move the source code to a temp file. So you can run it.
add or remove span tags that colors the source code.
remove all span markup in buffer that colors the source code.
Redo all pre source code blocks in buffer.

Tag Navigation

press ↓ to repeat.
press ← to repeat.
press → to repeat.

Select Element

Select the current element. Press m to repeat.

Remove Tags

Delete the open and close tag pair. (before cursor) Press m to repeat. Useful info in tag's attribute, such as link url, image source path, are preserved in a markdown format. Not useful innerText such as JavaScript code in script tag, are removed with the tags.
Delete all list tags. (of current block.)
Delete all p tags. (of current block.)
Delete all tags. (of current block.)
Delete tags but preserve info. (of current block.) For example, url in link remain, image path remain. This command basically convert html to plain text in best format as much as possible.
Join two same elements together. Cursor must be in between the closing tag and opening tag. Press m to repeat.

Open in a Browser

Open buffer in default browser.
In Chrome. If cursor is on a url, open the url, else buffer.
In Safari. If cursor is on a url, open the url, else buffer.
In Firefox. If cursor is on a url, open the url, else buffer.
In Brave. If cursor is on a url, open the url, else buffer.
In Brave. If cursor is on a url, open the url, else buffer.


Includes a abbrev system. You can define any tag or template.

Type htmlt to insert a whole html template.

view the image in a image tag

Just move cursor to the file path, press Enter to open it.

History of Xah Html Mode

xah-html-mode began in 2013. And went thru a complete rewrite in 2021-08, 2024-03.