Blog / Coding-agent workflows

Claude Code HTML Output: Prompts, Preview and Safety

· AI coding · 8 minute read

When should you ask Claude Code for HTML? Use a self-contained HTML file when the answer benefits from spatial layout, an SVG diagram, collapsible detail, side-by-side comparison or a small interactive control. Use Markdown when the result must remain easy to diff, quote, edit in a terminal or publish in a repository.

HTML is not automatically “better” output. It is a richer execution format with more review surface. A useful workflow asks the coding agent for one bounded artifact, previews it with scripts and network access blocked, checks the document structure, then reviews any JavaScript before enabling interaction.

Open HTML Preview & Safety Inspector

HTML versus Markdown

NeedPrefer MarkdownPrefer HTML
Repository documentationReadable source and clean diffsOnly when the repository publishes an HTML artifact
Architecture explanationShort linear overviewResponsive diagram, legend and expandable components
Pull-request reviewComments that belong in the review systemStandalone annotated walkthrough for complex changes
Data comparisonSmall static tableFiltering, sorting or linked detail
Security-sensitive materialDefault choiceOnly after scripts, links and external resources are reviewed

A prompt that produces a reviewable artifact

Create one self-contained HTML file that explains [TOPIC].

Requirements:
- use semantic HTML and responsive CSS;
- include one H1, a concise title and meta description;
- use inline SVG only where a diagram improves understanding;
- do not load external scripts, fonts, images or stylesheets;
- do not use forms, iframes, object/embed elements or javascript: URLs;
- keep JavaScript out unless interaction is essential;
- if JavaScript is needed, explain every behavior after the code;
- cite the source file, issue or primary documentation behind each claim;
- finish with a verification checklist.

Save the result as [NAME].html. Do not open or execute it automatically.

The constraints matter more than simply saying “output HTML.” They make the file portable, reduce hidden network dependencies and give the reviewer a clear boundary.

Prompt variants

Architecture walkthrough

Build a self-contained HTML architecture walkthrough for this repository.
Show request flow, trust boundaries and failure paths in an inline SVG.
Link each component to the relevant local file path. No external resources.

Pull-request explainer

Create a static HTML explainer for this diff.
Group findings by correctness, security, performance and maintainability.
Quote only the minimum code needed and include file paths and line numbers.
Do not invent test results. Distinguish observed behavior from inference.

Incident timeline

Turn these timestamped logs into a self-contained HTML incident timeline.
Keep original timestamps, add a UTC/local toggle only if it can be implemented
without dependencies, and mark gaps or assumptions explicitly.

Safe preview workflow

  1. Read the source first. Search for scripts, inline event handlers, forms, frames, external URLs and URL schemes such as javascript:.
  2. Preview with scripts disabled. The EasyTool preview uses an origin-isolated iframe and restrictive Content Security Policy.
  3. Check document quality. Verify title, language, H1, meta description, image alternatives and responsive behavior.
  4. Review interaction separately. If scripts are necessary, understand the code before explicitly enabling them in the sandbox.
  5. Save and diff. Put the reviewed artifact under version control so later changes are visible.

Why sandboxing matters

Generated HTML can contain executable JavaScript, network requests, tracking pixels, credential-collection forms or embedded third-party pages. Even when the model did not intend harm, it can reproduce insecure patterns from examples. A preview should therefore start with the minimum capability required to render structure and CSS.

The sandbox attribute and Content Security Policy reduce risk, but they do not turn unknown code into trusted code. Do not combine allow-scripts and allow-same-origin for untrusted same-origin content, and do not treat a static scanner as proof of safety.

Document-quality checklist

Sources and further reading

Related EasyTool tools