Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put important words in real HTML, then position them over an image with CSS. Use <figure> and <figcaption> when the words are a caption rather than an overlay. Keep the image’s alt text focused on the image’s essential content or function; it is not a duplicate of the visible caption.

This distinction matters for responsive layouts, keyboard and screen-reader users, translation, zooming, and situations where the image does not load. The examples below show a complete overlay, a semantic caption, responsive readability improvements, and a practical alternative when you need screenshots generated automatically.

Choose the right technique first

“Text on an image” can mean three different things. Decide which one you need before writing CSS:

Need Recommended HTML Why
Heading, label, price, or call to action displayed on the picture Image plus a separate text element, positioned with CSS The copy remains selectable, resizable, translatable, and available to assistive technology.
Visible context describing a photograph, chart, or illustration <figure> and <figcaption> The caption is structurally associated with the figure.
Words permanently printed into a graphic Text embedded in the file only when necessary, with equivalent alt text Users cannot resize, select, translate, or reliably read bitmap lettering.

W3C WAI recommends actual text styled with CSS where CSS capabilities allow it because it can resize without losing clarity and can respond to user-selected color preferences (W3C Images of Text guidance). MDN recommends <figure> and <figcaption> when an image needs a caption (MDN’s <img> reference).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Build a basic live-text overlay

Use a wrapper as the positioning context, make the image a block-level element, and place a real heading or paragraph over it. This example puts a label in the lower-left corner.

<div class="hero-card">
  <img
    src="images/mountain-lake.jpg"
    alt="A mountain reflected in a calm lake at sunrise"
  >
  <div class="hero-card__overlay">
    <p class="hero-card__eyebrow">Weekend guide</p>
    <h2>Three quiet lakes to visit this spring</h2>
    <a class="hero-card__link" href="/guides/lakes">Read the guide</a>
  </div>
</div>
.hero-card {
  position: relative;
  max-width: 48rem;
  overflow: hidden;
  border-radius: 0.75rem;
  isolation: isolate;
}

.hero-card > img {
  display: block;
  width: 100%;
  height: auto;
}

.hero-card__overlay {
  position: absolute;
  inset: auto 0 0;
  padding: clamp(1rem, 4vw, 2.5rem);
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
}

.hero-card__overlay h2 {
  max-width: 26ch;
  margin: 0.25rem 0 0.75rem;
  font-size: clamp(1.4rem, 4vw, 2.5rem);
  line-height: 1.1;
}

.hero-card__link {
  color: #fff;
  font-weight: 700;
}

.hero-card__link:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

Why each rule exists

  • position: relative on the wrapper makes the absolutely positioned overlay relative to the card rather than the page.
  • position: absolute and inset: auto 0 0 anchor the overlay to the bottom edge while allowing its height to grow with the text.
  • The gradient supplies contrast across photographs that contain both light and dark areas. Do not rely on color alone; test the actual image and copy.
  • clamp() lets type and padding scale between small and large viewports. The overlay should not cover the subject or become too small to read.
  • display: block removes the inline-image baseline gap that can otherwise create unexpected space below the image.

If the overlay is a link or contains controls, keep those elements in normal HTML. Users can tab to them, copy their text, and use browser zoom. Avoid putting a click handler only on the image unless the accessible name and keyboard behavior are also provided.

Make overlay text readable on every image

Use a contrast layer

A translucent solid background or gradient is usually more robust than a text shadow. For a short badge, use a compact background:

.badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  padding: 0.35rem 0.6rem;
  color: #111;
  background: rgb(255 255 255 / 0.9);
  border-radius: 999px;
  font-weight: 700;
}

Allow the text to wrap

Do not force a single line with white-space: nowrap unless truncation is intentional and the complete wording is available elsewhere. Long translations, browser zoom, and narrow phones need additional lines. Set a readable measure such as max-width: 26ch, and let the overlay’s height be automatic.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check mobile and reduced-motion states

Hover-only overlays fail on touch screens and are difficult for keyboard users. Keep essential text visible by default. If you animate an overlay, respect the user’s preference:

@media (prefers-reduced-motion: reduce) {
  .hero-card__overlay,
  .hero-card__overlay * {
    transition: none;
    animation: none;
  }
}

When the image is a CSS background

A background image can work for decorative art, but it has no alt attribute. If the image conveys information, use an <img> and provide an appropriate alternative. If you use a background for decoration, keep the meaningful words as ordinary HTML:

<section class="promo" aria-labelledby="promo-title">
  <h2 id="promo-title">Build a faster portfolio</h2>
  <p>A decorative background supports this heading.</p>
</section>
.promo {
  padding: 5rem 1.5rem;
  color: white;
  background: center / cover url("images/abstract-shapes.jpg");
}

Use a semantic caption with <figure>

A caption is visible context for people who can see the figure; it is not merely text placed at a convenient coordinate. Mark it up explicitly:

<figure class="article-figure">
  <img
    src="images/temperature-chart.png"
    alt="Line chart showing average monthly temperatures rising from January through July"
  >
  <figcaption>Average monthly temperature, 1990–2020.</figcaption>
</figure>
.article-figure {
  margin: 2rem 0;
}

.article-figure img {
  display: block;
  width: 100%;
  height: auto;
}

.article-figure figcaption {
  margin-top: 0.5rem;
  color: #555;
  font-size: 0.95rem;
}

MDN describes figcaption as the caption for a figure, and a figure may contain more than an image (MDN’s HTML images tutorial). You can style the caption to overlap the image if the design requires it, but retain the semantic elements:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<figure class="overlay-figure">
  <img src="images/city.jpg" alt="A city skyline viewed from the river">
  <figcaption>The riverfront at dusk</figcaption>
</figure>
.overlay-figure {
  position: relative;
  margin: 0;
}
.overlay-figure img {
  display: block;
  width: 100%;
}
.overlay-figure figcaption {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 0.75rem 1rem;
  color: #fff;
  background: rgb(0 0 0 / 0.7);
}

Use a caption for context such as a source, date, location, or explanation. Use alt as the image’s text replacement when it cannot be seen. The two may overlap in subject but should not automatically repeat the same sentence.

Write the right alt text

Informative image

Describe the essential content or function concisely: alt="A mountain reflected in a calm lake at sunrise". If the image is a button or link, describe its purpose rather than its pixels.

Decorative image

Use an empty alternative, alt="", when the image adds no information and nearby text already carries the meaning. W3C WAI explains that this signals assistive technology to skip the decoration (W3C Images Tutorial).

Complex image

For a chart, diagram, or infographic, put the complete data or explanation in surrounding text or a linked long description. Do not expect a caption alone to replace the information conveyed by the graphic.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The title attribute is not a replacement for alt or a visible caption. Important information should be present in the page itself rather than hidden in a hover tooltip.

When text is baked into the image

Sometimes a logo, poster, scanned document, or legally fixed artwork must contain lettering in the file. If so, include the same meaningful words in the image’s alternative, and provide additional HTML text when the wording is important to completing the task. Bitmap text can become blurry when enlarged, cannot be selected or translated, and may disappear when images are blocked. For ordinary headings, labels, and promotional copy, live HTML text is the more adaptable choice.

Or skip the browser setup

If your goal is to create screenshots of pages containing overlays or captions, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one GET request. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

See the complete parameter list in the ScreenshotNeo documentation. cURL example:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

Every plan includes the same features: full-page and element captures, device presets or custom viewports, retina scale, dark mode, custom CSS and JavaScript, waits, request blocking, cookies and headers, geolocation, transparent backgrounds, resizing, caching, signed links, asynchronous webhooks, bulk capture, usage reporting, and PDF controls. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common problems

Text is behind the image

Ensure the wrapper is position: relative and the text is positioned, or use a stacking order:

.hero-card__overlay { position: absolute; z-index: 1; }
.hero-card > img { position: relative; z-index: 0; }

The overlay is unreadable

Add a gradient or opaque background, increase font weight, and test bright and dark portions of the source image. Do not assume a shadow provides sufficient contrast.

The card is taller than expected

Remove fixed heights where possible and let the image preserve its aspect ratio. If a fixed crop is required, set aspect-ratio and object-fit: cover deliberately:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.hero-card > img {
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

Keyboard users cannot reach the call to action

Put the link in HTML, not in a click-only overlay script. Test with the Tab key and provide a visible :focus-visible style.

Screen readers announce unwanted words

Do not duplicate the same sentence in the overlay, caption, and alt by default. Mark purely decorative images with alt=""; revise informative alternatives to convey only the image’s essential role.

The caption does not describe the image when it fails to load

That is expected: a caption is visible context, while alt is the replacement for the image. Make the alternative meaningful and keep critical information in surrounding HTML.

Production checklist

  • Is the visible copy real HTML rather than pixels?
  • Does the wrapper establish the positioning context?
  • Can the text wrap at mobile widths and browser zoom?
  • Is contrast still sufficient over the actual image?
  • Are links and controls keyboard reachable with a visible focus indicator?
  • Does alt describe the image’s purpose, or is it correctly empty for decoration?
  • Would <figure> and <figcaption> better express a genuine caption?
  • Have you avoided using title as a substitute for either?

Frequently Asked Questions

Can I center text over an image?

Yes. Set the wrapper to position: relative, then use an absolutely positioned text element with inset: 50% auto auto 50% and transform: translate(-50%, -50%). Keep wrapping and contrast rules from the overlay example.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should a caption be inside or outside the image?

Use figcaption inside figure. CSS can display it below the image or overlay it; the semantic relationship remains the same.

Does CSS text work if images are disabled?

Yes. HTML headings, paragraphs, and links remain available. A background image may disappear, so do not make the image the only carrier of important information.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.