MixedHTML Mode for Emacs

jefftk
Sun, 19 Apr 2026 11:40:21 GMT

I made a new major mode for emacs: mixed-html-mode. Or, really, Claude Code made one at my direction. It does syntax highlighting in HTML files with inline CSS and JS. I had two goals, which weren't met by any mode I could find:

1. Does not freeze, flash, or stutter, even on huge files on slow machines.

2. Does not get confused about whether a portion of a file is HTML vs CSS vs JS.

The initial insight was that how browsers decide what text is HTML vs CSS vs JS is super simple: scanning for literal and tags. I pulled some tricky examples, described what I wanted, and then iterated for about an hour until I had something that worked well. Then I tried to use it to write something for real, ran into a few other irritations, had Claude fix those, and now I have something I'm enjoying a lot.

It's mildly faster than web-mode (and much simpler, and easier to install), and far faster than html-ts-mode. And unlike mhtml-mode it doesn't get confused by quotes.

The biggest drawback is that it doesn't do indentation; I may add that, but right now I'm happy with it the way it is.

I've skimmed the code, but haven't read it in detail, and definitely wouldn't say I understand it. The validation has been a mixture of asking Claude to review it and fix the bugs and warts it finds, making sure Claude has written tests, and using it enough to feel good about it. I do expect it has some bugs left: if you decide to use it and find a situation it handles poorly please let me know.

It's funny: I picked emacs two decades ago because I liked the idea of an editor that was so extensible that it was mostly written in its own extension language, and then never took advantage of this because it was too much work. But now it's not much work! Perhaps emacs will finally catch up to (and overtake) vim?

Discuss