SVG images not rendering in README
Overview
When an SVG file in a repository is referenced from a README (for example ), 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: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.pngEmbed as data URI
For small files, base64-encode the SVG and embed it directly in markdown: so it can be reviewed.