Runtime
Bundler
Package Manager
Test Runner
Guides
Reference
Blog
Install Bun
Guides Module System

Import a HTML file as text

To import a .html file in Bun as a text file, use the type: "text" attribute in the import statement.

file.ts
import html from "./file.html" with { type: "text" };

console.log(html); // <!DOCTYPE html><html><head>...

With hot module reloading or watch mode, Bun reloads whenever ./file.html changes.

On this page

No Headings