HTML vs markdown for LLM input

Both are read without difficulty. Markdown is shorter for the same content, so it wins by default, and HTML wins where the tags carry meaning that markdown has no way to express.

HTML vs markdown for LLM input comes down to length against structure. Markdown is shorter for the same content, so it is the default, and HTML earns its extra length when the tags carry meaning markdown cannot express.

The same section pasted twice, once as markdown and once as HTML. The content matches; the length does not.
The same section pasted twice, once as markdown and once as HTML. The content matches; the length does not.

Comprehension is not the question. Models read HTML, including attributes and inline styles, without stumbling. The question is what you pay and what you keep.

HTML vs markdown for LLM input: what you pay

Markup is characters. Every opening tag, closing tag, class name and style attribute is part of the input.

The growth is uneven across document types, which is why a single rule for everything is wrong.

Content Markdown to HTML growth Worth paying
Prose with headings Small Rarely
Bullet lists Small Rarely
Rectangular table Large No
Table with merged cells Large Yes, markdown cannot express it
Form or interactive page Large Yes, identity is the point
Page of layout containers Very large No, the growth is all wrapper

The last row is the common case for anything copied from a live website, and it is the case where cleaning up first pays most.

What you keep

Markdown carries headings, lists, links, emphasis, code and rectangular tables. That covers most documents.

It cannot carry four things:

  • Element identity. There is no equivalent of an id or a class, so nothing in the document can be referred to precisely.
  • Attributes. Data values, timestamps and codes attached to elements have nowhere to go.
  • Irregular tables. Row spans, column spans and nested tables flatten, and a flattened version of a merged cell table often reads as wrong rather than as simplified.
  • Layout meaning. A side by side comparison becomes two stacked lists, and the pairing between them is gone.

If none of those appear in your document, converting to markdown loses nothing at all.

Cleaning HTML before pasting

Most of the length in a real page is not content. Removing it is more effective than switching formats.

  1. Drop script and style blocks. On many pages this alone removes over half the file.
  2. Drop navigation, footer and cookie banners. They repeat on every page and answer nothing.
  3. Drop class and style attributes unless you are asking about appearance.
  4. Keep headings, tables, lists, links and image alt text.
A page before and after removing scripts, styles and navigation. The content is unchanged.
A page before and after removing scripts, styles and navigation. The content is unchanged.

After that pass, HTML is often only modestly longer than the markdown version, and it still carries the structure. That is usually a better position than either extreme.

The cases where HTML clearly wins

Irregular tables. Financial statements, timetables and specification sheets frequently use merged cells. Keep the HTML for those.

Anything the model must act on. If the next step is clicking or filling a field, the identifiers must survive. Converting removes them.

Pages where design is part of the question. Asking why a layout breaks on a phone requires the markup and the CSS. A description of the layout is not a substitute.

Round tripping. If you want an edited version of a page back, paste the page. Otherwise you get a new page with similar content, which is a redesign rather than an edit.

Output format is decided separately

A common error is letting the input format choose the output format.

Result goes to Ask for
A repository file or ticket Markdown
Another prompt Markdown
A person opening a page A complete single file HTML document
A plain text field Plain text, written for that field

Getting HTML instead of markdown covers the prompt shape when the answer keeps reverting. Going the other way, ChatGPT HTML to text covers extracting the words from a page you already have.

Semantic tags are where HTML pays off

If you are going to spend characters on tags, spend them on tags that mean something.

One section built from headings, lists and a table, and the same section built from generic containers.
One section built from headings, lists and a table, and the same section built from generic containers.

Headings, lists, tables, sections and articles tell a reader where content begins and ends. Generic containers with styling class names tell it very little, at similar cost.

That is the same property described in semantic HTML, and it is worth applying to pages you generate, because those pages get read back into models later.

When the page is the deliverable

If the output is a page rather than an input, the format question ends and a delivery question starts. An HTML file is awkward to send, since attachments get filtered and phones will not render them.

Pasting it into a NOS document renders it exactly as written, including dark theme, charts and scripts, and gives the page its own address through Share, then Share link, then Create link.

The generated page as a document with a share link. Editing the page does not change the address.
The generated page as a document with a share link. Editing the page does not change the address.

The link is unlisted by default, so only people who have it can open it. Because the address survives editing, corrections happen in the page rather than in a second message.

Turning HTML into a link is that step alone, and the HTML viewer is the quick check before you commit to it.

Short version. Default to markdown. Pay for HTML when the document has irregular tables, elements to act on, attributes with data, or a design that is part of the question.

Clean the HTML before pasting either way, because most of a real page is not content.

Questions people ask

Do models understand HTML as well as markdown?

Yes. Tags, attributes and inline styles are read without difficulty. The reason to prefer markdown is length, not comprehension, and the reason to prefer HTML is structure that markdown cannot represent.

How much longer is HTML?

It depends on the content. Prose with headings and lists grows modestly. Tables grow a lot, because every cell gains an opening and closing tag. Pages built from nested layout containers grow the most, and that growth adds nothing.

Should I strip HTML before pasting it?

Strip scripts, styles, navigation and tracking attributes. Keep headings, tables, lists and links. That removes most of the length while keeping everything the model would have used.

Which format should the model output?

Decide by destination rather than by input. Markdown when the result goes into a file, a ticket or another prompt. HTML when a person will open the result as a page with layout, tables or charts in it.

Does HTML improve table accuracy?

It helps when the table is not rectangular. Merged cells and nested tables have no markdown form, so converting them loses the relationship between a heading and the cells it covers. For plain rectangular tables, markdown pipe tables are enough.

Keep reading