Hey all! I love the new canvas model/UI for GPT-4o, and the cool features it comes with, but was shocked to see that it doesn’t (yet) let you view a preview of HTML/CSS code.
I have experience with developing Chromium extensions, so I decided to dig into seeing if an extension could be built that let’s you preview HTML in canvas. With the help of ChatGPT itself, I was able to successfully build a stable working version 1.0 that does just this.
I’m sure OpenAI will have their own official version of this at some point, but in the meantime feel free to try out this extension!
Description:
Use this extension to easily preview your HTML and CSS code directly within OpenAI’s new “ChatGPT-4o with canvas” model/UI.
This tool adds an eyeball icon to the canvas interface for HTML/CSS code canvases, allowing you to instantly visualize the code displayed in the canvas without the need to save or test locally.
With a single click, the extension renders your code in a pop-up iFrame, saving you time and effort while making the editing process smoother and more efficient. No more tedious back-and-forth between saving files and checking your work—just quick, in-browser previews.
Installation:
Note: The extension is still under review for the Microsoft Edge Add-ons site, but you can still install and use the extension on Edge by installing it on Edge from the Chrome Web Store.
Instructions:
-
Generate new HTML/CSS code, or view already generated canvas code, in “ChatGPT-4o with canvas” at chatgpt.com or chat.openai.com.
-
When the canvas opens automatically, or you open it manually on existing canvas code, the preview eyeball icon button should appear at the top-right of the canvas within a second or two.
-
Press the preview button to visually view your HTML/CSS code.
-
Press the X or the Esc key to close the preview pop-up.
Caveats and limitations:
-
HTML/CSS code canvases must start with
<!DOCTYPE html>
or the preview button won’t appear, as there’s no point to visually preview any other programming languages. -
Some CSS styling may not look quite right or exactly perfect in preview, possibly due to iFrame limitations or differences. If something looks a little off, it’s recommended to always download the HTML and open in your browser before asking ChatGPT for changes on minor appearances based only on what you see in preview.
-
References to external CSS and scripts, as well as inline scripts, will not work due to content security policies.
-
You need to Ctrl + click a link, or link button, in your HTML preview to navigate to it in a new tab. Normal clicking links in your HTML doesn’t work, as it is blocked by CSP.
Feedback and suggestions are welcome!
Thanks and enjoy!