HTML to Image: Social Graphics, Ads and Carousels
skillWrite 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.
agents that use this skill
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
- List the placements and take each size from the platform's own page. Record the page and the date next to the size.
- 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.
- 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 onaspect-ratioor with container queries. - 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. - Render every size in one
html-render shotcall. Fix every ERROR. Read every WARN and decide: fix it or keep it on purpose. - 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.
- Export carousels from one HTML file with
--each: one element per slide, one file per element. - 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.
| Decision | Default |
|---|---|
| Message | One claim per image. A second idea is a second image or the next slide. |
| Reading order | Headline, one supporting line, call to action. The headline is the largest text by a clear step, not by a few pixels. |
| Feed size | People 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. |
| Margins | The same margin on every side, at least 6vmin, and nothing but the background inside it. |
| Type | At most two font families; weight and size carry the hierarchy. |
| Colour | One accent colour on neutrals; body text at 4.5:1 contrast or better, large text at 3:1 (WCAG). |
| Carousel | The 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. |
| Variants | Change 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.
| Placement | Size and ratio | Source |
|---|---|---|
| Facebook feed image ad | 1440x1800 recommended, minimum 600x750, 4:5 | facebook.com/business/ads-guide/image/facebook-feed/traffic |
| Instagram feed carousel | at least 1080x1080, images 4:5, 2 to 10 cards | facebook.com/business/ads-guide/carousel/instagram-feed |
| LinkedIn single image ad | 1200x628, 1200x1200, or 720x900 (mobile only); 5 MB limit | linkedin.com/help/lms/answer/a426534 |
| Pinterest image pin | 1000x1500, 2:3 | help.pinterest.com/en/business/article/pinterest-product-specs |
| Link preview (Open Graph) | at least 1200x630, about 1.91:1, minimum 200x200 | developers.facebook.com/docs/sharing/webmasters/images |
| Instagram Stories | 9:16 recommended | developers.secure.facebook.com/documentation/ads-commerce/instagram/ads-api/reference/media-requirements |
| Instagram Reels ad | 9:16 recommended | facebook.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
- 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. - 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.
- 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-textandoff-canvasmean text is cut off or outside the canvas.broken-imagemeans a file path is wrong. - WARN
font-fallbackmeans the browser is not using the font you named. Fix the@font-facepath or pick an installed font. - WARN
low-contrastcompares 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-textalso reports text cut on purpose withtext-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 insrc/, 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:
<!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>html-render shot graphics-out/launch/src/ad.html -o graphics-out/launch \
--size 1080x1080 --size 1080x1350 --size 1200x628Carousel from one file, each slide a <section class="slide"> of 1080x1350:
html-render shot graphics-out/tips/src/carousel.html -o graphics-out/tips --size 1080x1350 --each .slideChecklist
- 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 shotcall 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
- The platform's ad or social skill, when one is loaded: copy limits, truncation and placement rules.
- WCAG contrast minimum: the 4.5:1 and 3:1 thresholds.
- Playwright screenshots: scale, animations and element capture.
- Open Graph protocol:
og:imagetags for link previews. html-render --helplists every option.