PDFのミカタ

画像をデータURLにしてHTMLに埋め込む

公開日:2026年10月19日|最終更新:2026年10月19日|運営者情報

この記事のポイント
  • 選ぶ
  • 印をつける
  • 貼る

小さな画像を、別ファイルにせず、HTMLやCSSの中に直接埋め込みたい。そのときに使うのが、データURLです。ファイルとBase64を相互変換する の「データURLの形式にする(data:…;base64,)」で作れます。

手順

  1. 「向きを選ぶ」で、「ファイル → Base64」を選びます。
  2. 「ファイルを1つ選ぶ」で、画像のファイルを選びます。
  3. 「データURLの形式にする(data:…;base64,)」にチェックを入れます。
  4. 「変換後のBase64」に、「data:image/png;base64,…」のような文字列が出ます。
  5. 「結果をコピー」でコピーして、HTMLの画像のsrcに貼り付けます。
小さな画像に向いています。大きな画像だと、ページが重くなります。

使い方の例

HTMLに貼り付けるときの形:画像のタグのsrcに、作った文字列を入れます。CSSの背景画像のurl()の中にも、入れられます。

データURLのメリット

データURLのデメリット

向いている画像

向かない画像

目安の大きさ

一般には、数KB〜十数KB程度までの画像が、埋め込みに向くと言われます。それ以上は、別ファイルにするほうが扱いやすいです。

例

2KBの小さなアイコンを、メール用のHTMLに埋め込んだ。画像を添付しなくても、表示できるようになった。

つまずきやすい点

よくある質問

画像以外でも、データURLにできますか?

できます。PDFやテキストなども、データURLにできます。ただし、使える場面は限られます。

まとめ

小さな画像だけを、データURLにして埋め込む。大きな画像は、別ファイルにしましょう。

ファイルとBase64を相互変換するを使う(無料)

あわせて使えるツール

この解説が役に立ったら、応援してもらえるとうれしいです。

応援する(300円)ほしい物リストで応援

同じツールの、ほかの解説

解説の一覧を見る

Embedding an Image in HTML as a Data URL

Published: Oct 19, 2026 | Updated: Oct 19, 2026 | About (Japanese)

Key points
  • Choose
  • Tick
  • Paste

You want to embed a small image directly in HTML or CSS without making it a separate file. A data URL is what you use. You can make one with "Use data URL format (data:…;base64,)" in Convert Files and Base64.

Steps

  1. For "Direction", choose "File → Base64".
  2. With "Choose one file", choose the image file.
  3. Tick "Use data URL format (data:…;base64,)".
  4. A string like "data:image/png;base64,…" appears under "Base64 after conversion".
  5. Copy with "Copy result" and paste it into the HTML image's src.
It suits small images. Large images make the page heavy.

Example of use

The form for pasting into HTML: put the string you made in the src of the image tag. It can also go inside url() of a CSS background image.

Advantages of data URLs

Disadvantages of data URLs

Images that suit

Images that don't suit

A guide to size

Generally images up to a few KB to a dozen or so KB are said to suit embedding. Larger ones are easier to handle as separate files.

Example

Embedded a 2KB small icon in HTML for email. It could be displayed without attaching the image.

Common stumbling blocks

Frequently asked questions

Can things other than images become data URLs?

Yes. PDFs, text and so on can also be data URLs. But the situations to use them are limited.

Summary

Make only small images into data URLs and embed them. Keep large images as separate files.

Use "Convert Files and Base64" (free)

Tools that go well with this

If this guide helped, a small tip would mean a lot.

Send a tip (¥300)Send a gift (Amazon wishlist)

More guides for this tool

See all guides