How to add images to README.md on GitHub without using third-party hosting services?
I recently started using GitHub and have hosted several projects there. I need to include images in my README files but don’t know how to do this effectively.
When I searched for solutions, most resources suggest hosting images on external web services and then referencing them in the README.md file. However, I’m looking for a solution that doesn’t require using third-party web hosting services.
What are the methods for adding images directly to a GitHub repository and referencing them in README.md files without external hosting?
You can add images to your GitHub README.md files without third-party hosting by either using relative paths to images stored directly in your repository or by embedding images as Base64 encoded strings within the README.md file itself. GitHub now fully supports relative linking to images that are part of your repository, making this approach both reliable and self-contained.
Contents
- Using Relative Paths
- Base64 Encoding Method
- Best Practices and Organizational Tips
- Troubleshooting Common Issues
- Advanced Techniques
Using Relative Paths
The most straightforward method for adding images to your README.md without external hosting is to store the image files directly in your GitHub repository and reference them using relative paths.
Basic Implementation
-
Add image files to your repository: Upload your image files (PNG, JPG, GIF, etc.) to your GitHub repository, typically in a dedicated folder like
images/,assets/, or at the root level. -
Use Markdown image syntax: In your README.md file, use the standard Markdown image syntax with a relative path:

Path Structure Examples
The relative path should be based on the location of your README.md file:
- Same directory as README.md:
 - In images folder:
 - In parent directory:
 - In nested folder:

Base64 Encoding Method
For ultimate self-containment, you can embed images directly within your README.md file using Base64 encoding. This method makes the image file part of the README itself, though it can significantly increase the file size.
How to Implement Base64 Images
-
Convert your image to Base64: Use online converters or command-line tools to convert your image to a Base64 string
-
Use data URL syntax: Embed the Base64 string using the data URL format:

Base64 Image Format
The general format is:

Where:
image-formatcan bepng,jpg,gif, etc.base64-encoded-datais the Base64 string of your image
Advantages and Disadvantages
Advantages:
- Completely self-contained - no external files needed
- Works even if the repository is forked
- No risk of broken links
Disadvantages:
- Significantly increases README.md file size
- Can make the file difficult to read and edit
- Not recommended for large images
- Base64 strings can be very long and unwieldy
Note: As noted in the research, “Embedding images as Base64 encoded strings makes them self-contained within the README.md file, avoiding the need for external image hosting.”
Best Practices and Organizational Tips
When working with images in GitHub README files, follow these best practices to ensure optimal performance and maintainability.
File Size Optimization
- Compress images: Use tools like ImageOptim, TinyPNG, or Squoosh to reduce file sizes
- Choose appropriate formats: Use WebP for better compression, PNG for graphics with transparency, JPG for photographs
- Limit dimensions: Scale images to appropriate sizes for web display
Repository Organization
- Create dedicated folders: Use logical folder structures like
images/,assets/, ordocs/images/ - Keep README.md clean: Place images in separate folders rather than cluttering the repository root
- Use consistent naming: Follow a naming convention like
feature-name.pngorlogo-brand.png
Version Control Considerations
- Add images to .gitignore: If you have many large images, consider adding them to .gitignore and using Git LFS
- Commit frequently: Ensure images and README.md are committed together
- Use descriptive alt text: This helps with accessibility and when images cannot be displayed
Troubleshooting Common Issues
Even with proper implementation, you might encounter some issues when adding images to GitHub README files.
Images Not Displaying
Problem: Images show as broken links in the README.md preview
Solutions:
- Verify the relative path is correct from the README.md location
- Ensure the image file is committed to the repository and not just staged
- Check for typos in the filename or path
- Try using the raw file URL if the relative path doesn’t work
Path Issues
From community discussions: “I usually host the image on the site, this can link to any hosted image. Just toss this in the readme. Works for .rst files, not sure about .md”
Common path problems:
- Using absolute paths instead of relative paths
- Incorrect directory structure assumptions
- Case sensitivity issues (GitHub is case-sensitive)
File Size Limits
- Large images: GitHub has file size limits; compress large images before uploading
- Repository size: Consider GitHub’s storage limits for your account type
- README.md size: Very large Base64 encoded images can make the file unwieldy
Advanced Techniques
For more sophisticated image management in GitHub repositories, consider these advanced approaches.
Conditional Image Display
Some markdown parsers support conditional content that can be useful for different viewing contexts:
<!-- Only visible on GitHub -->

<!-- Only visible locally -->

Image Galleries
Create organized image galleries using markdown tables or nested lists:
## Project Screenshots
| Feature 1 | Feature 2 | Feature 3 |
|-----------|-----------|-----------|
|  |  |  |
Combining Methods
You can combine multiple approaches for different use cases:
- Use relative paths for most images
- Use Base64 encoding for small, critical icons
- Host very large images externally as a last resort
Conclusion
Adding images to GitHub README files without third-party hosting is straightforward once you understand the available methods. The key takeaways are:
- Use relative paths for most cases - this is the recommended approach by GitHub and provides the best balance of simplicity and maintainability
- Consider Base64 encoding only for small, critical images where absolute self-containment is necessary
- Organize your repository with logical folder structures to keep your project clean and maintainable
- Optimize image sizes to ensure fast loading and respect GitHub’s storage limits
- Test your implementations by viewing the README on GitHub.com, as local markdown previews may not always render relative links correctly
Start with the relative path method, as it’s what GitHub officially supports and what most developers use successfully. If you need absolute self-containment for specific use cases, then consider Base64 encoding for those particular images.
Sources
- Including Pictures in Your GitHub README.md Without Relying on External Hosting - tempmail.us.com
- How to add images to README.md on GitHub? - Stack Overflow
- 4 Ways to Add Images to GitHub README + 1 Bonus Method - Cloudinary
- How do you put Images on the README.md file? - GitHub Community Discussion
- The Ultimate Guide to Embedding Images in GitHub READMEs! - openillumi.com
- How do I add images into my readme, and keep them there? - Reddit
- Markdown: How To Add Images To README.md On GitHub - Build5Nines
- 3 Ways to Add an Image to GitHub README - Sean C Davis
- About the repository README file - GitHub Docs