Home  >  Article  >  Backend Development  >  How to embed a .png image directly into an HTML document without linking to an external file?

How to embed a .png image directly into an HTML document without linking to an external file?

DDD
DDDOriginal
2024-10-28 21:30:30559browse

How to embed a .png image directly into an HTML document without linking to an external file?

Embedding a .png Image into an HTML Page

How can one embed a .png file into a blank "file.html" document so that the image displays when the file is opened in any browser, without linking to it from the HTML code?

Answer:

To embed an image into HTML without linking, utilize online Base64 encoders. One recommended option is http://www.greywyvern.com/code/php/binary2base64.

There are two main methods for embedding the image:

  • CSS:
div.image {
  width: 100px;
  height: 100px;
  background-image: url(data:image/png;base64,iVBORwA<MoreBase64StringHere>);
}
  • Tag:
<img alt="My Image" src="data:image/png;base64,iVBORwA<MoreBase64StringHere>" />

In both cases, replace with the output from the Base64 encoder.

The above is the detailed content of How to embed a .png image directly into an HTML document without linking to an external file?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn