Match the canvas to the longest line
A code card is useful when indentation and syntax colors clarify an idea that plain post text would flatten. First decide which line carries the lesson. A reader should be able to identify that line without reading imports, setup, or unrelated helpers. Measure the longest line in the preview. A 60-character command may need more horizontal room than ten short lines, while a narrow checklist about the command can use a portrait card.
| Placement | Export canvas | What to put on the image |
|---|---|---|
| X landscape snippet | 1200 × 675 | One short function or a command with its result |
| LinkedIn directly uploaded image | 1080 × 1080 | A short heading, sample input, and one important expression |
| Instagram portrait lesson | 1080 × 1350 | A narrow example with a one-line explanation |
| Documentation figure | 1200 × 630 | A focused result that sits beside a copyable code block |
Use these as canvas choices, with the suggested line lengths and margins determined by the template and font. The safest layout is one where neither a long line nor the final brace touches the edge, even after the destination scales it. Check a rendered download at the same width as the post rather than relying on your desktop preview. Keep the text and its accents distinct against the background and do not put the only explanation in a syntax color.
Prepare a shareable snippet
- Paste a fenced block with a language name. Preserve indentation. Add a heading that states the outcome such as “Build an export filename,” then add a single sentence to explain why the highlighted line is useful. Use a language identifier that matches the snippet. For mixed shell commands and output, label the lines or place the output in its own small block.
- Reduce the source to the smallest complete idea. Keep a function signature if the types explain something. Drop boilerplate that only makes sense in a full project. Break long arguments across lines when the language permits it. Use placeholder credentials and remove personal paths, internal hostnames, or private data before you export.
- Choose Dark Code or Developer and check the preview. Try a wider canvas when line length is the main problem. If the number of lines is the issue, split the example into distinct phases with a heading on each card. Adjust font and padding so a viewer can read quotes, dots, and underscores at phone width.
- Export PNG and verify against the source. Compare the downloaded image with the original snippet for missing text or cropped lines. Put the actual command or repository link in the accompanying post. For tutorials, include copyable text and use the card to orient readers to the relevant function or outcome.
Three examples to edit
- Reusable function. Load Code snippet and use its filename helper to test punctuation on dark and light templates. Rename the function and reduce the arguments if the central idea is just a naming rule. Compare an export that shows a concrete resulting filename with one that includes an extra explanatory paragraph.
- Change notice with a migration step. Start from Launch announcement, then replace the list with a two-line example of the old and new invocation. Label each line plainly so the difference survives without the colors. Place the full migration instructions in the release notes, where the command can be copied.
- Step-by-step terminal lesson. Adapt Tutorial checklist into three short actions. Put one command and its expected output on the same card, then use a second card for another action only if the result needs more space. Check sequential exports so a reader who sees card two still knows what project or command it refers to.
When to choose a screenshot-style card
Use a code image as a visual preview of a single insight, such as the line that fixes a bug or the shape of a function's output. Its strengths are predictable alignment and the ability to show syntax highlighting on a platform that may strip formatting. A title above the snippet gives context when the image gets reshared with no caption. A short plain-text sentence below the example helps people who are unfamiliar with the language see the result.
Keep executable steps in a copyable form. Text hidden in an image is difficult to use with assistive technology and awkward to edit. If a question is about debugging a whole function or comparing several files, use a linked gist, code review, or documentation page. A single syntax card can still point to the important path or symptom. For examples containing secrets or sensitive values, substitute safe dummy data in the source. Covering the value with styling can leave the wrong version in a later export, while replacing it before rendering makes the sample safe to reuse.
Troubleshoot a clipping or highlighting failure
If the block is rendered as prose, inspect the opening and closing fences and leave blank lines between the surrounding text and the fence. If the code has no useful colors, verify the language identifier. TypeScript, Python, and shell share some tokens, but highlighting a shell example as JavaScript can make comments or quotes visually misleading. If colors remain weak, switch between the editor themes and compare the result at feed size. The underlying punctuation should still be readable with colors disabled or in a grayscale preview.
A code line can extend far beyond the visible card even when the editor shows a horizontal scroll area. Treat scrolling as a preview convenience and inspect the exported image all the way to the right edge. If shortening the line would change the lesson, choose a wider canvas or put that part in the article. Automatic pagination does not guarantee that one very long fenced block will split cleanly. Divide it yourself at meaningful boundaries and repeat enough context so that each card can be understood in sequence.
When a teaching image shows before and after code, label both blocks and use the same indentation. Keep the unchanged lines only if they help locate the edit. Show the observed output separately so readers can distinguish a line they should type from a line their terminal prints.
Before uploading multiple pages, open them in order and check that comments and expected output have stayed with the relevant command. In the accompanying text, describe what changed or what error the command addresses. A useful alt description states the purpose of the example and directs readers to a copyable version if they need every character.
Frequently asked questions
- How do I enable syntax highlighting?
- Add the language name after the opening fence, for example ts, python, or bash. Check how the chosen template renders it.
- Can a code block wrap in the image?
- Preview the line breaks and inspect the exported right edge. Shorten long commands, add deliberate line breaks where the language permits, or choose a wider preset.
- Should I export code as PNG or JPEG?
- Use PNG for fine punctuation and syntax colors. Compare JPG only when the destination requires it or file size justifies the trade.
- Does the tool execute a code snippet?
- The editor renders fenced code as formatted text for a visual preview and export.
- Will a long fenced block paginate cleanly?
- For a long block, split the source into separate examples with clear headings and verify the numbering in the export.
- How do I share a copyable version?
- Include the command or a stable link to the source in the surrounding post, article, or repository.