Overlay Text on Image Card

Create visually compelling links with this template that places text directly on top of a full-card background image.

This "hero" style card is perfect for grabbing user attention and works well for featured articles, travel destinations, or portfolio highlights where a strong visual is important.

Screenshot of three cards with text overlaid on dramatic landscape photos.

Get Source Code Preview

About this Component

The main feature of this card is its layered structure, achieved through CSS positioning. An image serves as the bottom layer, a semi-transparent gradient is layered on top to ensure the text is readable, and the text content itself forms the top layer. The result is a dynamic, modern card that prioritizes imagery.

Features

Code Breakdown

HTML Structure

The entire card is an anchor (a) tag with the class .oti-card. This makes the whole unit a single clickable link. Inside, the structure is simple: an img element for the background and a div that wraps the text content (h3 and p).

CSS Styling

The layering effect is controlled by a CSS stacking context.

  1. The main card (.oti-card) is set to position: relative, which establishes the positioning boundary for its children.
  2. The image (.oti-card-image) is set to position: absolute with a z-index of 1. This places it in the background layer and makes it fill the card's dimensions.
  3. A CSS pseudo-element (.oti-card::before) is used to create the gradient overlay. It is also absolutely positioned, but with a z-index of 2, placing it directly on top of the image. The background uses the linear-gradient() function to transition from dark and opaque at the bottom to transparent at the top.
  4. The text container (.oti-card-content) has a position: relative and a z-index of 3, which ensures it sits on the very top layer, above the gradient and image.
  5. Finally, Flexbox properties on the main card are used to push this content block to the bottom of the card.

Code

Here's the complete code for the card. The template is ready to use and can be customized by changing the images or modifying the CSS variables.

View Output