# Expanding Cards

> A row of image panels where the one you hover or focus grows to fill the space.

- Category: [CSS Cards](https://copy-css.com/category/cards)
- Tags: expand, accordion, gallery, hover, flex, panels
- Live preview: https://copy-css.com/snippets/expanding-cards
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="expand-cards">
  <a href="#"><span>Mountains</span></a>
  <a href="#"><span>Forest</span></a>
  <a href="#"><span>Desert</span></a>
  <a href="#"><span>Ocean</span></a>
</div>
```

## CSS

```css
.expand-cards {
  display: flex;
  gap: 8px;
  width: 100%;
  height: 300px;
}

/* Set each panel's background-image inline */
.expand-cards > * {
  flex: 1;
  display: flex;
  align-items: flex-end;
  min-width: 0;
  padding: 12px;
  overflow: hidden;
  border-radius: 14px;
  background: #d4d4d8 center / cover;
  color: #fff;
  font: 700 14px system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
  transition: flex-grow 0.45s ease;
}

.expand-cards span {
  opacity: 0;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
  transition: opacity 0.3s ease;
}

/* The hovered or focused panel grows. The first one is open by default. */
.expand-cards > :hover,
.expand-cards > :focus-visible,
.expand-cards:not(:hover, :focus-within) > :first-child {
  flex-grow: 4;
}

.expand-cards > :hover span,
.expand-cards > :focus-visible span,
.expand-cards:not(:hover, :focus-within) > :first-child span {
  opacity: 1;
}

.expand-cards > :focus-visible {
  outline: 2px solid #4338ca;
  outline-offset: 2px;
}
```

## Notes

- This CSS Expanding Cards is 47 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses transitions, text shadows, Flexbox and keyboard focus styles.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
