FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Image to Base64: Complete Guide to Data URIs in HTML, CSS, and JavaScript
How-ToWeb Development

Image to Base64: Complete Guide to Data URIs in HTML, CSS, and JavaScript

via Dev.to Webdevarenasbob2024-cell1mo ago

Base64 image encoding eliminates separate HTTP requests but adds ~33% file size. Here's when and how to use it. What Is a Base64 Data URI? <!-- Traditional external image --> <img src= "/images/logo.png" alt= "Logo" > <!-- Base64 data URI - no HTTP request needed --> <img src= "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..." alt= "Logo" > Format: data:[MIME type];base64,[base64-encoded-data] Convert in JavaScript (Browser) FileReader API (for user-uploaded files) function fileToBase64 ( file ) { return new Promise (( resolve , reject ) => { const reader = new FileReader (); reader . onload = () => resolve ( reader . result ); // "data:image/png;base64,..." reader . onerror = reject ; reader . readAsDataURL ( file ); }); } // Usage with file input document . getElementById ( ' file-input ' ). addEventListener ( ' change ' , async ( e ) => { const file = e . target . files [ 0 ]; const dataUri = await fileToBase64 ( file ); document . getElementById ( ' preview ' ). src = dataUri ; })

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
30 views

Related Articles

Week 6 — No New Problems. Just Me and Everything I Already Learned.
How-To

Week 6 — No New Problems. Just Me and Everything I Already Learned.

Medium Programming • 2d ago

What OpenClaw Gets Wrong Out of the Box (And How to Fix It)
How-To

What OpenClaw Gets Wrong Out of the Box (And How to Fix It)

Medium Programming • 2d ago

Android Remote Compose:讓 Android UI 不用發版也能更新
How-To

Android Remote Compose:讓 Android UI 不用發版也能更新

Medium Programming • 3d ago

How-To

Learn Something Old Every Day, Part XVIII: How Does FPU Detection Work?

Lobsters • 3d ago

“Learn to Code” Is Dead… Learn to Think Instead
How-To

“Learn to Code” Is Dead… Learn to Think Instead

Medium Programming • 3d ago

Discover More Articles