view source

HTML to Image: Social Graphics, Ads and Carousels

skill

Write social media graphics, ad creatives and carousels as HTML, then render PNG or JPEG at every platform size with layout checks. Use for posts and ads.

Apache-2.0 Requires: Node.js 18+ and Playwright's Chromium (the installer adds both) and the html-render command on PATH. Web access for platform size pages. macOS/Linux.

instructions

Overview

This skill delivers finished marketing image files: ad creatives, carousel slides, social cards, quote and stat cards, framed product screenshots and link-preview images. Each one is written as an HTML page, rendered to PNG at every placement size in headless Chromium, and checked by the html-render command for clipped text, overlaps, missing fonts and low contrast. The deliverable is the PNG files plus the HTML source they came from.

It does not cover logos and brand kits, video thumbnails, or slide decks.

Mental model

  • HTML and CSS are the design medium because the browser wraps text, loads fonts and lays out a grid. SVG <text> does not wrap, so a model has to guess line breaks and widths. A renderer that is not a browser, such as resvg, draws a static subset of SVG and none of the HTML and CSS around it. Put SVG inline for logos, icons and charts, and let HTML lay out everything around it.
  • A model writing layout code cannot see the result. The loop is: render, read the check output, open every PNG and look at it. A clean check report is not a finished design: the checks do not judge hierarchy, balance or taste.
  • Text in an image is set as HTML text, never drawn by an image model: generated lettering cannot be edited, checked against the copy, or set in the brand font. Generated images are for pictures without text only.

Rules

Method

  1. List the placements and take each size from the platform's own page. Record the page and the date next to the size.
  2. Write the copy before the layout: headline, one supporting line, call to action. Take character limits and truncation from the platform's ad or social skill when one is loaded, otherwise from the platform's own page.
  3. Build one HTML template. Keep copy and brand colours in CSS custom properties at the top. Size type in vmin (1% of the shorter side of the viewport) so it scales with the canvas. Adjust per aspect ratio with media queries on aspect-ratio or with container queries.
  4. Load fonts from local files through @font-face. Use a font whose licence allows this use, and ship the font file next to the HTML.
  5. Render every size in one html-render shot call. Fix every ERROR. Read every WARN and decide: fix it or keep it on purpose.
  6. Open every PNG and look at it. Check the headline reads at phone size, the call to action is visible, and nothing sits where the platform overlays its own interface.
  7. Export carousels from one HTML file with --each: one element per slide, one file per element.
  8. Deliver the PNGs and the HTML source. Say which findings you kept and why.

Design defaults

These are starting points for a layout, not measured rules. Change one when the brand or the brief gives a reason.

DecisionDefault
MessageOne claim per image. A second idea is a second image or the next slide.
Reading orderHeadline, one supporting line, call to action. The headline is the largest text by a clear step, not by a few pixels.
Feed sizePeople see the image much smaller on a phone. Shrink the PNG to about 400 px wide and read it: what is unreadable there is cut or enlarged.
MarginsThe same margin on every side, at least 6vmin, and nothing but the background inside it.
TypeAt most two font families; weight and size carry the hierarchy.
ColourOne accent colour on neutrals; body text at 4.5:1 contrast or better, large text at 3:1 (WCAG).
CarouselThe first slide makes sense alone and says why to swipe; every slide keeps the same grid, margins and type; the last slide is the one worth saving.
VariantsChange one thing per variant (headline, image or colour), so a test result can be read.

Placement sizes

Sizes below were read from each platform's page on 2026-11-30. Re-check before a paid campaign: platforms change sizes and add limits.

PlacementSize and ratioSource
Facebook feed image ad1440x1800 recommended, minimum 600x750, 4:5facebook.com/business/ads-guide/image/facebook-feed/traffic
Instagram feed carouselat least 1080x1080, images 4:5, 2 to 10 cardsfacebook.com/business/ads-guide/carousel/instagram-feed
LinkedIn single image ad1200x628, 1200x1200, or 720x900 (mobile only); 5 MB limitlinkedin.com/help/lms/answer/a426534
Pinterest image pin1000x1500, 2:3help.pinterest.com/en/business/article/pinterest-product-specs
Link preview (Open Graph)at least 1200x630, about 1.91:1, minimum 200x200developers.facebook.com/docs/sharing/webmasters/images
Instagram Stories9:16 recommendeddevelopers.secure.facebook.com/documentation/ads-commerce/instagram/ads-api/reference/media-requirements
Instagram Reels ad9:16 recommendedfacebook.com/business/ads/facebook-instagram-reels-ads

For Stories and Reels the pages read did not give pixel sizes or safe-zone margins (the areas the app covers with its own interface). Open Meta's placement page and its templates for those numbers. Sizes for X, TikTok and YouTube were not confirmed here: read the platform's page.

Framed product screenshots

  1. A public page: capture it with html-render shot <url> -o <dir> --size WxH --style '<css>'. The CSS hides cookie banners and blurs personal data, for example --style '#cookie{display:none} .email{filter:blur(8px)}'. Scale 2 is the default.
  2. A page behind a login is not captured by this command. Ask the user for a screenshot taken at 2x, and mask personal data in it before framing.
  3. Build a second HTML page with the capture as an <img> inside a CSS frame: a browser bar, rounded corners, a shadow and a background. Render that page at the placement size.

Checks and files

  • ERROR lines block delivery. clipped-text and off-canvas mean text is cut off or outside the canvas. broken-image means a file path is wrong.
  • WARN font-fallback means the browser is not using the font you named. Fix the @font-face path or pick an installed font.
  • WARN low-contrast compares text with the solid colour painted behind it. It does not measure text over an image or gradient, or text with opacity below 1: look at those.
  • WARN clipped-text also reports text cut on purpose with text-overflow: ellipsis; confirm that is intended.
  • Without --each, the check compares text to the viewport. With --each, it compares text to its own slide.
  • Put files under ./graphics-out/<slug>/: HTML and assets in src/, PNGs beside it. Pass -o ./graphics-out/<slug>.

Examples

Bad: a request for an ad in three sizes, answered with one 1080x1080 file and the text drawn by an image generator.

Good: one template, three renders, text as HTML:

html
<!doctype html>
<style>
  @font-face { font-family: Brand; src: url(fonts/Brand-Bold.woff2); font-weight: 700; }
  :root { --bg: #10243e; --fg: #fff; --accent: #ffcf5c; }
  html, body { margin: 0; height: 100%; }
  body { background: var(--bg); color: var(--fg); font-family: Brand, sans-serif;
         display: flex; flex-direction: column; justify-content: center; gap: 4vmin; padding: 8vmin; }
  h1 { margin: 0; font-size: 9vmin; line-height: 1.05; }
  a { align-self: flex-start; background: var(--accent); color: var(--bg);
      font-size: 3.6vmin; font-weight: 700; padding: 1.2vmin 2.4vmin; border-radius: 1vmin; }
</style>
<h1>Ship campaigns in every size</h1>
<a>Start free</a>
bash
html-render shot graphics-out/launch/src/ad.html -o graphics-out/launch \
  --size 1080x1080 --size 1080x1350 --size 1200x628

Carousel from one file, each slide a <section class="slide"> of 1080x1350:

bash
html-render shot graphics-out/tips/src/carousel.html -o graphics-out/tips --size 1080x1350 --each .slide

Checklist

  • Each size was read from the platform's page, with the date noted.
  • Copy was written before layout and fits the platform's character limits.
  • One template, brand colours and copy in custom properties, type in vmin.
  • Fonts are local files with a licence that allows the use.
  • One html-render shot call covered all sizes; every ERROR is fixed and every WARN was judged.
  • Every PNG was opened and looked at.
  • Text is HTML text; no image model drew words.
  • Screenshots have personal data masked.
  • PNGs and the HTML source are in ./graphics-out/<slug>/.

Composition / References