DAILY NEWS

Stay Ahead, Stay Informed – Every Day

Advertisement
When (and when not) to inline images as Base64



Base64 image data URIs are one of those web techniques that look like a magic shortcut the first time you use them.

Instead of referencing an external file:

src=”/logo.png” alt=”Logo”>

Enter fullscreen mode

Exit fullscreen mode

you can put the image bytes directly in the document as text:

src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…” alt=”Logo”>

Enter fullscreen mode

Exit fullscreen mode

That can be useful. It can also make a page slower, harder to cache, and more annoying to maintain.

Here is the practical rule: inline images as Base64 when self-containment matters more than caching. Keep normal image files when the browser should be able to cache, resize, lazy-load, or optimize them independently.

What a Base64 image actually is

An image file is binary data. Base64 rewrites that binary data as plain text using a limited character set. To make the browser treat the text as an image, you wrap it in a data URI:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…

Enter fullscreen mode

Exit fullscreen mode

The first part tells the browser the MIME type. The second part tells it the data is Base64 encoded. The long tail is the image itself.

Base64 is not compression. It is not encryption. It is just a text representation of the same bytes.

When inlining an image is worth it

1. Tiny icons and UI assets

For very small images, removing an extra HTTP request can be worth the extra bytes. This is especially true for small icons, logos, placeholders, simple UI sprites, or tiny transparent PNGs.

Modern HTTP/2 and HTTP/3 make extra requests cheaper than they used to be, so this is not an automatic win. But for a one-off tiny asset inside a small page or widget, a data URI can still be a clean choice.

2. Single-file deliverables

Sometimes the point is not raw page speed. Sometimes you need one file that carries everything with it:

an HTML report
an email template
a CodePen or demo snippet
a CMS block where you cannot upload assets
a test fixture that should not depend on external hosting

In those cases, Base64 is useful because the image travels with the HTML, CSS, JSON, or JavaScript.

3. Prototypes and throwaway snippets

If you are testing a layout, writing a bug reproduction, or pasting a minimal example into a ticket, a data URI can save time. You do not need to set up static hosting just to show one image.

4. Local-only conversion workflows

If the image is private, it is nice to avoid uploading it to a random converter. Browser APIs can generate a Base64 data URI locally, so the file never leaves your device.

When you should not inline the image

1. Large photos and hero images

Base64 usually makes the encoded data about 33% larger than the original binary file. That is because Base64 stores every 3 bytes as 4 text characters.

For a large JPG, PNG, or WebP, that extra size is not a rounding error. Keep big images as normal files.

2. Images reused across pages

An external image can be cached once and reused across page views. An inlined image is bundled into every document or stylesheet that contains it.

If the same logo appears on 20 pages, inlining it 20 times is usually worse than letting the browser cache one file.

3. Responsive images

Normal image files can use srcset, sizes, lazy loading, CDN transforms, format negotiation, and caching headers.

src=”/hero-800.webp”
srcset=”/hero-400.webp 400w, /hero-800.webp 800w, /hero-1600.webp 1600w”
sizes=”100vw”
loading=”lazy”
alt=”Product screenshot”
>

Enter fullscreen mode

Exit fullscreen mode

That is much harder to preserve when the image is baked into a string.

4. Anything you expect humans to edit

Base64 strings are unpleasant to review in Git diffs, easy to truncate by accident, and noisy inside templates. If designers, marketers, or other engineers need to update the image regularly, use a normal asset file.

How to generate a Base64 data URI in the browser

The simplest browser-native path is FileReader.readAsDataURL().

The result will look like this:

data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…

Enter fullscreen mode

Exit fullscreen mode

You can use that string directly in HTML:

src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…” alt=”Logo”>

Enter fullscreen mode

Exit fullscreen mode

or in CSS:

.logo {
background-image: url(“data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…”);
}

Enter fullscreen mode

Exit fullscreen mode

A simple checklist

Inline the image if:

it is small
it is not reused across many pages
self-contained delivery matters
you do not need responsive image behavior
the string will not make your source files painful to maintain

Keep it as a normal file if:

it is a photo or large graphic
it should be cached separately
it appears on many pages
it needs srcset, lazy loading, CDN resizing, or image optimization
non-developers need to replace it often

Tiny tool note

I built a small free tool for this workflow: PNG to Base64 converter. It runs entirely in the browser with FileReader, so the PNG is not uploaded, and it gives you the raw Base64 string plus ready-to-paste HTML and CSS snippets.

There is also a general image to Base64 converter for JPG, SVG, WebP, GIF, and other image formats.

Use Base64 as a packaging tool, not a default image strategy. When the image is tiny or the deliverable must be self-contained, it can be perfect. When performance, caching, and responsive delivery matter, boring old image files are still the better answer.



Source link

Stop Hardcoding Hex #d9d9d9 In Your CSS



If you open any massive legacy codebase or inspect a fresh Figma handoff, you will probably see one hex code repeating everywhere: #d9d9d9.

It’s the ultimate default. Developers use it for disabled buttons, subtle borders, card backgrounds, and dividers. But treating this specific light gray as a “safe” neutral is causing massive UI bugs in your production apps right now.

Here is why you need to stop hardcoding #d9d9d9 and how to handle it properly.

The Dark Mode Theme Breaker

****The most common mistake junior developers make is hardcoding border: 1px solid #d9d9d9; directly into their component CSS.

When your app switches to dark mode, that 85% lightness gray becomes a glaring, dominant bright line that ruins the dark UI ergonomics.

The Fix: Never hardcode this hex. Always map it to a semantic CSS variable or a design token.

CSS`/* ❌ Bad Practice */.card { border: 1px solid #d9d9d9; }

/* ✅ Good Practice /:root {–color-border-subtle: #d9d9d9;}@media (prefers-color-scheme: dark) {:root {–color-border-subtle: #3d3d3d; / Adjusted for dark mode */`}}.card { border: 1px solid var(–color-border-subtle); }

The Accessibility (a11y) TrapA lot of devs layer #d9d9d9 backgrounds with #9e9e9e text to create a “subtle” disabled state. This combination completely fails WCAG AA standards. While pure black text on #d9d9d9 passes Lighthouse audits, using gray-on-gray is an accessibility anti-pattern. If you are using it for a disabled button, you must pair it with a secondary indicator (like cursor: not-allowed or a specific icon) because color-blind users might not see the difference.
Display P3 vs. sRGB RenderingDid you know #d9d9d9 looks completely different depending on the monitor? On modern MacBooks (which use the Display P3 color space), it looks sharp and cool. But on cheaper, uncalibrated TN panels (which many of your users have), it washes out and becomes almost indistinguishable from a white background (#ffffff).

The Ultimate #d9d9d9 Developer GuideHandling gray scales properly separates mid-level devs from senior frontend engineers.

I have written a massive, deep-dive guide on everything you need to know about #d9d9d9. It includes:

How to use it with OKLCH for uniform rendering.

The exact Tailwind CSS equivalents (gray-300).

Copy-paste platform codes for SwiftUI, Jetpack Compose, React Native, and Flutter.

👉 Read the Full Developer Guide on Hex #d9d9d9 Here

(Need to quickly convert #d9d9d9 to RGB, HSL, or CMYK for your current project? Check out our (free Hex to RGB Converter tool as well)“



Source link

How I Built a Cinematic Portfolio with React and Framer Motion



Hi, I’m Akshay Bhawar, a Full Stack Developer from Maharashtra, India.

Recently, I decided to completely redesign my portfolio. Instead of going with a traditional, minimalist layout, I wanted something bold, immersive, and interactive—something that feels like a high-tech Sci-Fi Heads-Up Display (HUD).

You can see the live result here: https://akshaybhawar03.github.io/portfolio/

In this article, I’ll explain how I used framer-motion and React to bring this cinematic experience to life, the challenges I faced, and the key tech stack behind it.

🛠️ The Tech StackTo build a smooth, high-performance UI without compromising on developer experience, I used:

React.js: For building a component-driven, scalable architecture.

Framer Motion: The powerhouse behind all the futuristic animations, staggered text reveals, and UI transitions.

Tailwind CSS / CSS Modules: For styling the glowing neon effects, grids, and cyber-punk aesthetics.

🚀 Key Features & How They Were Built

The Futuristic HUD Boot-up Sequence
First impressions matter. When a user lands on the site, they are greeted with a dynamic “system loading” animation.
Using Framer Motion’s animate and variants, I staggered the entry of various UI panels to mimic a computer system powering up.

JavaScriptconst bootVariants = {hidden: { opacity: 0, scale: 0.95 },visible: { opacity: 1, scale: 1,transition: { duration: 0.8, ease: “easeOut” }}};

Glowing Neon & Cyberpunk AestheticsA true HUD needs to look alive. I heavy relied on CSS box-shadow and drop-shadow filters combined with subtle infinite floating animations. By using Framer Motion’s animate={{ y: (0, -5, 0) }} with a loop transition, elements appear to float seamlessly in space.
Interactive Data PanelsEvery section (About, Projects, Experience) behaves like an interactive module. When you switch tabs, the data doesn’t just instantly appear; it clips, slides, and reveals itself like data stream lines on a real monitor.

🧠 Challenges I FacedPerformance Optimization: Rendering multiple heavy glowing elements and continuous animations can easily drop frame rates. I optimized this by using layoutId for smooth layout transitions and ensuring hardware acceleration was active for transforms.

Responsive Design: HUDs are notoriously difficult to make mobile-friendly because they rely on fixed panels. I had to create a completely adapted layout for smaller screens that retains the “cyber” feel without cluttering the viewport.

🎯 Conclusion & Key TakeawaysBuilding this portfolio taught me a lot about the fine line between “cool animations” and “good user experience.” Framer Motion made it incredibly easy to orchestrate complex UI timelines that would have taken hundreds of lines of pure CSS.

What do you think of this high-tech approach? Would you use a HUD-style layout for your own portfolio, or do you prefer classic minimalism?

Check out the live site here: Akshay Bhawar Portfolio

Let me know your thoughts or drop your questions in the comments below! 👇



Source link