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

DDD
Release: 2024-10-28 21:30:30
Original
470 people have browsed it

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>);
}
Copy after login
  • Tag:
<img alt="My Image" src="data:image/png;base64,iVBORwA<MoreBase64StringHere>" />
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!