# Code-Driven AI Illustrations: SVG, HTML, and Programmatic Art

> Published 2026-12-02 · https://www.promptzone.com/ayaka_reddy/code-driven-ai-illustrations-svg-html-and-programmatic-art-36fk

A discussion on [Hacker News](https://simonwillison.net/2026/Nov/28/code-driven-ai-illustrations/) with **276 points and 143 comments** argues that AI-generated **code-driven illustrations** are more useful than traditional pixel-based images. The core idea: instead of generating a PNG, you prompt an LLM to produce editable **SVG, HTML, or CSS** code that renders an illustration.

> **Output:** SVG, HTML/CSS, ASCII Art | **Tools:** Claude 3.5 Sonnet, GPT-4o, Gemini 2.0 Flash | **Cost:** ~$0.01 per generation | **Key Trait:** Infinitely editable, reproducible

## What Code-Driven Illustrations Are
These are visual assets defined by code, not pixels. A large language model writes the source code—like an SVG path or a div structure with CSS styles—which a browser or renderer then displays. The final "image" is a text file you can version control, modify directly, or animate with scripts.

The [original post by Simon Willison](https://simonwillison.net/2026/Nov/28/code-driven-ai-illustrations/) demonstrates this by generating **flowchart diagrams, technical icons, and decorative banners** entirely in SVG. The code is the direct output of a prompt like "Create an SVG icon of a database."


![Code-Driven AI Illustrations: SVG, HTML, and Programmatic Art](https://promptzone-community.s3.amazonaws.com/uploads/articles/7yzfgo7ck8fnirm954j5.jpeg)

## How to Generate Them
You need an LLM with strong coding capabilities and a playground to render the output. The process is a three-step loop.

First, **craft a precise prompt** specifying the format, style, and constraints. Example: "Generate a complete, standalone SVG file for a simple rocket ship icon. Use only basic shapes (circle, rect, path). Make it 100x100 pixels with a blue color scheme."

Second, **run the prompt** through a capable model. Claude 3.5 Sonnet is frequently cited for its superior SVG and CSS reasoning. GPT-4o and Gemini 2.0 Flash are also viable, often at a lower cost per generation.

Third, **render and iterate**. Paste the code into an online SVG viewer, a local HTML file, or an **Observable notebook**. If the result is wrong, debug the code with the LLM or adjust your prompt.

{% details "Example prompt and workflow" %}
**Initial Prompt:** "Write an SVG for a green checkmark icon, 64x64px."
**LLM Output:** Returns SVG code with `<path>` elements.
**Validation:** Paste code into a tool like **SVG Viewer**.
**Iteration:** "Make the checkmark bolder and the circle background a lighter green."
The entire workflow can be scripted using the [OpenAI API](https://platform.openai.com/docs/api-reference) or [Anthropic's API](https://docs.anthropic.com/en/api/getting-started) for batch generation.
{% enddetails %}

## Pros and Cons Versus Image Models
Code-driven art solves specific problems inherent to tools like DALL-E 3, Midjourney, or Stable Diffusion, but introduces new trade-offs.

**Advantages:**
- **Infinite resolution and editability:** SVG vectors scale perfectly; CSS properties can be tweaked with one character change.
- **Reproducibility and consistency:** The same prompt and model version yield identical code, enabling reliable asset pipelines.
- **Tiny file sizes:** A complex SVG is often under 10KB, compared to multi-megabyte high-res PNGs.
- **Native interactivity:** Code can include click handlers, animations, or dynamic data binding.

**Disadvantages:**
- **Limited visual fidelity:** Cannot achieve the photorealistic detail or complex artistic styles of diffusion models.
- **Cognitive load:** Requires basic understanding of the output code (SVG/HTML) to debug or modify effectively.
- **Unpredictable failures:** LLMs still hallucinate invalid syntax or geometrically nonsensical paths.

## Alternatives and Comparisons
The choice hinges on your project's needs: editable assets or finished artistic renders.

| Feature | Code-Driven (LLM) | Diffusion Model (e.g., Stable Diffusion) | Vector Graphic Tool (e.g., Figma) |
|---------|-------------------|------------------------------------------|-----------------------------------|
| **Output Format** | SVG, HTML, CSS code | PNG, JPG (raster) | `.fig`, `.svg` (proprietary/vector) |
| **Edit Method** | Edit code directly | Inpainting, regional prompts | Manual GUI manipulation |
| **Style Range** | Simple, geometric, flat | Photorealistic, highly artistic | Limited to user's manual skill |
| **Cost per Asset** | **~$0.01** (API call) | ~$0.02-$0.10 (API/credits) | High (designer time) |
| **Automation Potential** | **High** (scriptable API) | Medium (batch APIs) | Low |

For diagrammatic and UI-centric tasks, code-driven methods compete directly with libraries like **Mermaid.js** or **Graphviz**. The LLM approach is more flexible but less deterministic than these dedicated syntaxes.

## Who Should Use This
This technique is a targeted tool, not a general image generation replacement.

**Use code-driven illustrations if you:**
- Build **developer documentation, technical blogs, or educational content** needing clear, consistent diagrams.
- Develop **web applications** and need customizable, lightweight icons or UI illustrations.
- Maintain a **design system** where assets must be themable and adapt to brand color changes via CSS variables.
- Operate an **automated content pipeline** where assets must be generated at scale with perfect reproducibility.

**Avoid this approach if you:**
- Need **photorealistic imagery, character art, or complex textures** for marketing or narrative visuals.
- Have **no capacity to validate or lightly adjust code** outputs.
- Require **pixel-perfect control** over every visual element; manual design tools are still superior for final polish.

> **Bottom line:** Code-driven AI illustration is a pragmatic solution for generating editable, scalable, and reproducible assets for technical and web contexts.

## The Bottom Line: A New Primitive for Developers
Code-driven AI illustration isn't about replacing artists or diffusion models. It creates a new primitive for developers and technical content creators: the **programmatically generatable, natively editable vector asset**. It shifts the value from the visual output itself to the **source code that defines it**, unlocking workflows where adaptability and automation trump artistic flourish. The vigorous Hacker News discussion signals a clear demand for this—not for all imagery, but for the specific slice where code is the final, useful deliverable.

The next evolution will be models fine-tuned specifically for SVG, D3.js, or CSS output, reducing hallucination and increasing complexity. For now, it’s a remarkably practical technique hiding in plain sight, using general-purpose LLMs.