Users Pricing

articles

Home Articles How to display Base64 images in HTML – MindStick
How to display Base64 images in HTML

How to display Base64 images in HTML

Ashutosh Patel 1840 10 Jun 2024 Updated 10 Jun 2024

HTML Base64 Images

To display a Base64 encoded image in HTML, you can use the img element by setting the src attribute to the Data URI that represents the Base64 encoded image data.

Syntax- 

<img src="base64-image-data" alt="Base64 Image">

Example- 

Here is a basic example showing the base64 image in HTML,

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Base64 Image Example</title>
</head>
<body>

<h2>Base64 Image Example</h2>

<!-- Displaying a Base64 encoded image -->
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAAJklEQVR42mL8//8/AwgwMSAA9CNFsQcDG0FYABRhsdU2SK+AAAAAElFTkSuQmCC" alt="Base64 Image">

</body>
</html>

In the above example-

The src attribute of the img element contains the Data URI that represents the Base64 encoded PNG image. The format of the data URI is data:[<mediatype>][;base64],<data>, where <mediatype> specifies the media type of the data (image/png in this case), and <data> is Base64 image data which is encoded.

Note  make sure replace the src data from your actual base64 image url

Output

How to display Base64 images in HTML

Also, Read: What is the use of HTML Iframe?


Ashutosh Patel

Web Developer

I am a professional .NET developer with over 4 years of hands-on industry experience in designing, developing, and maintaining scalable web applications. I specialize in .NET Core, C#, RESTful APIs, and database-driven systems using SQL Server.


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md