图片转 Data URL (Base64)
将图片转为 Base64 data URL,用于 HTML/CSS 或测试。
文件
About this tool
将图片编码为 Base64 数据 URL,可直接粘贴到 HTML 或 CSS 中。图片随标记一起传输,减少一次网络请求。
Why use it
- 嵌入小图标,省去额外 HTTP 请求。
- 在邮件或单文件原型中插入图片。
- 一键复制可用的 data URI;编码在浏览器本地完成。
Common use cases
- 将小徽标嵌入 CSS 背景规则。
- 发送不含外部资源的自包含 HTML 演示。
- 将小型图片存入 JSON 配置。
Tips
- 仅适合小图:Base64 会使体积增大约 33%。
- 过大的 data URL 会膨胀 HTML 并影响缓存;大图仍应作为文件引用。
使用方法
- 选择文件。
- 复制生成的字符串。
- 用于 img src 或 CSS。
常见问题
- What is a data URL?
- A Base64 string that embeds the whole image inside HTML or CSS so it loads without a separate file request.
- When should I use a data URL?
- For tiny icons or inline emails where avoiding an extra network request is worth the larger text size.
- Is my image uploaded to make the data URL?
- No. The Base64 string is generated locally in your browser.
- Why is the data URL larger than the file?
- Base64 encoding adds about 33% overhead, so data URLs suit small images best.
- Can I paste the result into CSS?
- Yes, use it as the value of a background-image url() or an img src attribute.
- Does it work for SVG and PNG?
- Yes, any image type your browser can read can be turned into a data URL.