Blog / Coding-agent workflows
Claude Code HTML Output: Prompts, Preview and Safety
· AI coding · 8 minute read
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
| Need | Prefer Markdown | Prefer HTML |
|---|---|---|
| Repository documentation | Readable source and clean diffs | Only when the repository publishes an HTML artifact |
| Architecture explanation | Short linear overview | Responsive diagram, legend and expandable components |
| Pull-request review | Comments that belong in the review system | Standalone annotated walkthrough for complex changes |
| Data comparison | Small static table | Filtering, sorting or linked detail |
| Security-sensitive material | Default choice | Only 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
- Read the source first. Search for scripts, inline event handlers, forms, frames, external URLs and URL schemes such as
javascript:. - Preview with scripts disabled. The EasyTool preview uses an origin-isolated iframe and restrictive Content Security Policy.
- Check document quality. Verify title, language, H1, meta description, image alternatives and responsive behavior.
- Review interaction separately. If scripts are necessary, understand the code before explicitly enabling them in the sandbox.
- 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
- The page has one descriptive title, one primary H1 and a declared language.
- Headings form a meaningful outline rather than visual-only styling.
- Colors maintain contrast and information is not conveyed by color alone.
- Keyboard focus remains visible; interactive controls are actual buttons or links.
- SVG diagrams include a text explanation.
- Claims link to primary sources or identifiable repository evidence.
- The artifact still communicates its core answer when JavaScript is disabled.
Sources and further reading
- Simon Willison: The unreasonable effectiveness of HTML
- HTML output examples collected by Thariq Shihipar
- MDN: iframe sandbox permissions
- MDN: Content Security Policy