Beautiful Code Images for GitHub README: Best Practices and Examples
Table of Contents
A great GitHub README makes a project immediately understandable. One of the most effective README elements is a code image near the top — a styled screenshot showing what it looks like to actually use the library or tool. Done well, it sets expectations, demonstrates the API, and makes the project look polished before the reader reads a single word of documentation.
This guide covers when to use code images vs code blocks in READMEs, how to create high-quality images, and what makes a README code image effective.
Code Image vs Fenced Code Block: When to Use Each
Use a fenced code block when:
- The code needs to be copy-pasteable by the reader
- It is documentation the reader will reference while using the library
- You want GitHub's built-in syntax highlighting (which is free and automatic)
- The code may change and needs to be updated easily
Use a code image when:
- It is a hero section or marketing visual at the top of the README — showing the aesthetic, not providing reference docs
- You want a specific visual style that goes beyond GitHub's default highlighting
- The image accompanies a blog post or social media post alongside the README
- You want consistent appearance across all Markdown renderers (GitHub, npm, PyPI, crates.io all render differently)
The two approaches are complementary: a styled code image at the top, then fenced code blocks below for reference documentation.
What to Show in a README Code Image
The code image at the top of a README should answer one question: what does it feel like to use this?
The installation line is not interesting: "npm install my-package" is not a good README code image. Every package has an install command.
The "hello world" usage is the right choice: Show the smallest working example that demonstrates the library's value proposition. If you are building a parser, show a 5-line example that parses something interesting. If you are building a UI component, show the JSX that renders the component with its key props.
Good candidates for README code images:
- The first example from your documentation (the "quick start" snippet)
- Before/after showing your library's value — verbose manual approach vs clean library call
- A distinctive, idiomatic API call that would not exist in other libraries
Creating the Image: Settings and Dimensions
Theme: Match your project's aesthetic. A Python data library might use GitHub Dark or Atom One Dark. A frontend component library might use VS Code Dark. A systems library in Rust or Go might use Nord. Whatever you choose, use it consistently across all your README images.
Background: A slightly saturated color that contrasts with the code window. Deep navy, charcoal blue, or dark teal work for dark themes. Use the color picker in the Ocelot tool to dial it in.
Font size: 13-14px. README images are displayed full-width in the GitHub UI, so smaller text is readable. Going larger wastes vertical space.
Width: GitHub displays README images at the container width (roughly 820px on desktop). Your exported image will display at that width automatically. Taller images require more scrolling — keep snippets short.
Export at 2x: The tool exports at 2x resolution by default. On retina/high-DPI screens (most modern displays), this produces a sharp image rather than a blurry one.
Embedding the Code Image in a GitHub README
After exporting the PNG from the Ocelot tool, upload it to your repository and reference it in your README. Two approaches:
Option 1 — Upload to the repo: Add the image to an assets/ or docs/ folder in your repository. Then reference it:

Option 2 — Paste directly in the README editor: On GitHub, you can paste an image into the README editor and GitHub auto-uploads it. This puts the image at a GitHub CDN URL — convenient but the image is detached from your repository files.
Alt text: Always add descriptive alt text for the image. Describe what the code does: "JavaScript example showing how to initialize the client and make a query." This helps screen reader users and improves SEO for packages on npm or PyPI.
Keeping Code Images Updated as the Code Changes
The main maintenance burden of code images: when the API changes, you need to regenerate the image. Unlike a fenced code block that you can edit in the README directly, an image requires opening the tool, pasting the updated code, and re-exporting.
Strategies to reduce this friction:
- Keep a saved copy of the code snippet used for each image in a text file in your repo. When you update the API, updating the image takes 60 seconds: paste the new snippet, adjust if needed, export.
- Only image the most stable parts of your API. Core entry points that rarely change are the best code image candidates. Avoid imaging experimental or rapidly-evolving parts.
- Consider Mermaid for documentation that changes often. Mermaid code blocks in GitHub READMEs render natively and update when you edit the text — no image regeneration needed.
Try It Free — No Signup Required
Runs 100% in your browser. No data is collected, stored, or sent anywhere.
Open Free Code Screenshot ToolFrequently Asked Questions
Does GitHub render code images differently than regular images?
No. GitHub renders PNG and SVG images inline in READMEs at the container width. There is no special treatment for code images. Export high-resolution PNGs to ensure they look sharp on retina displays.
Should I use SVG or PNG for GitHub README code images?
PNG is safer for compatibility across all Markdown renderers (GitHub, PyPI, npm, crates.io). SVG works on GitHub but may have issues on other package registries. Use PNG unless you have a specific reason for SVG.
How do I keep the code image from becoming outdated?
Save the code snippet used for each image in a text file in your repo. When the API changes, regenerating the image takes under a minute: paste the updated snippet, verify the preview, export.
Can I use a code image as the og:image for my project website?
Yes. A code image makes an effective social preview image when someone shares a link to your project. It is more informative than a generic logo or blank image. Export at 1200x630px equivalent for best results on social platforms.

