Skip to content
Sourcegraph Help Center home
Sourcegraph Help Center home

SVG images not rendering in README

Overview

When an SVG file in a repository is referenced from a README (for example ![diagram](./docs/abc.svg)), the file may not render inline on the README page even though the raw file is accessible. This is caused by security sanitization: raw repository files (including SVGs) are often served with a generic Content-Type: text/plain or otherwise sanitized to prevent execution of scripts or unsafe SVG features, so browsers will not render them as images.

Why this happens

  • SVGs can contain scripts, external resources, or embedded content (e.g., <script>, <foreignObject>, external fonts/images) that could be abused. To be safe, the platform serves or sanitizes raw files so they are not interpreted as images by the browser.

  • This behavior can affect repositories on various code hosts (Gerrit, GitHub, GitLab, etc.).

Workarounds

  • Link instead of embed
    Use a link so users can open the SVG in the repository viewer (which may render it correctly):
    [View Architecture Diagram](./abc.svg)

  • Host externally
    Put the SVG on a trusted CDN, S3 bucket, or image host and reference the absolute URL so the browser receives the correct image content type:
    ![diagram](https://your-cdn.example.com/docs/abc.svg)

  • Convert to PNG
    Convert the SVG to a raster image with tools like Inkscape or ImageMagick and reference the PNG:
    inkscape abc.svg --export-filename=abc.png

  • Embed as data URI
    For small files, base64-encode the SVG and embed it directly in markdown:
    ![diagram]("heading-3" id="next-steps">Next steps

    • If you want platform-level support for inline SVGs, file a feature request with the product team.

    • If you need assistance inspecting the SVG for unsafe elements, provide the file (without any private data) so it can be reviewed.