Elementary Standards
HTMLCSSWeb StandardsSEOBlogStart reading
Home / CSS / Mobile Web CSS Image Replacement
CSS

Mobile Web CSS Image Replacement

The clever hacks we once used to swap text for logos were a symptom of a missing feature, and the cure was better markup, not better trickery.

5 min read·CSS

There was an era when every stylesheet had a favourite way to hide text. You wrote a real word inside an element, then contorted the CSS so a background image showed instead. On the mobile web, where bandwidth was precious and Retina logos were fashionable, this felt like craft. Mostly it was a workaround for a gap the platform hadn't yet closed.

@layer reset@layer base@layer components@layer utilities

The techniques, briefly

Image replacement had a genealogy of increasingly clever hacks, each fixing the last one's sins:

/* The classic, now a curiosity */
.logo {
  display: block;
  width: 160px;
  height: 40px;
  background: url(logo.png) no-repeat;
  text-indent: -9999px;
  overflow: hidden;
}

Why they mattered on mobile

On small screens the appeal was real. You could keep a genuine text heading — good for SEO, selectable, translatable — while presenting a crisp bitmap logo. Swap the background in a media query and you had an art-directed header before responsive images existed. For a while, this was the responsible thing to do.

Every image-replacement hack was really an apology: sorry, the platform can't yet say "this is an image with this text alternative" cleanly.

Why they became unnecessary

The ground shifted underneath the technique. Three changes retired it almost completely:

  1. Inline SVG. A vector logo scales to any density, carries a <title> for accessibility, and needs no font-hiding gymnastics at all. Put the mark in the markup where it belongs.
  2. Responsive images. With srcset and <picture>, the browser picks the right resolution for the device. The whole reason to smuggle images through CSS backgrounds — density switching — moved into HTML.
  3. Better accessibility norms. A background image has no accessible name. A real <img alt> or a titled SVG does. Screen-reader users stopped being an afterthought.

What to do instead today

If the image is the content — a logo, a diagram — put it in the HTML with an honest text alternative:

<a href="/" class="logo">
  <svg role="img" aria-label="Elementary Standards">…</svg>
</a>

When you genuinely need to hide text for assistive tech only — an icon-only button, a skip link — use the modern visually-hidden pattern (a clipped, one-pixel box), not a five-figure negative indent. It keeps the text in the accessibility tree while removing it visually, which is exactly what those old hacks were fumbling toward.

Image replacement was good engineering under bad constraints. The constraints are gone. The honest lesson is that when you find yourself hiding real text to show a picture, the platform has probably grown a better way — and usually the better way is simply to write the image into the page.

More on CSS
Keep reading

Related essays