Xah HTML Mode Tutorial

By Xah Lee. Date: . Last updated: .

This page is a tutorial on using Xah HTML Mode

XahTV 2021-09-14 Emacs Xah Html Mode, the Most Powerful Html Editor

View Manual

Alt+x describe-mode to see the documentation.

Insert Tags

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

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

It'll wrap the tag around the current word, line, or block, depending on the tag. Also, if there is selection, it'll wrap around the selection.

To add a class attribute or id attribute, press Ctrl+u Tab. It'll prompt for class name and id. Leave blank if you do not want the attribute.

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. Press Space to repeat.
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

xah-html-any-to-link is a smart command, it creates different links for different url/path. For example:

xah-html-any-to-link looks at the input and calls one of the following:

you can call any of these yourself.

Emacs: Insert HTML Tag

Embed Image

To turn a image path into a embedded image with figure and caption, just press Tab (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

Goto previous begin tag. Press to repeat.
Goto next begin tag. Press to repeat.
Goto element's begin/end tag. Press Space to repeat.

Select Element

Select the current element. Press Space to repeat.

Remove Tags

Delete the open and close tag pair. (before cursor) Press Space 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 end tag and begin tag. Press Space to repeat.

preview 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.


Type hr will become <hr />

Alt+x list-abbrevs to see all abbrevs.

Insert HTML 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.

open the current directory in OS desktop

Emacs: Open File in External App

History of Xah Html Mode

Xah Html Mode began in 2013. And went thru a complete rewrite in 2021-08. There are a lot to code. If you like it, please pay me.


Spent a few hours here?