---
title: "How to Use an SVG Shape as a Background Image in CSS"
slug: "svg-shape-background-image"
description: "Use an SVG shape as a background image in CSS. Covers sizing, stretching, placement, data URIs, changing color with masks and fixes for common problems."
primaryKeyword: "svg shape background image"
secondaryKeywords: []
relatedTools:
  - "/svg-maker"
  - "/svg-blob-generator"
  - "/svg-wave-generator"
  - "/svg-pattern-generator"
  - "/svg-to-base64"
date: "2026-11-27"
author: "MintConvert Team"
---

# How to Use an SVG Shape as a Background Image in CSS

A curve under a header or a soft shape behind a heading can lift a plain layout. With SVG, it stays sharp at any width. The tricky part is getting it to sit and stretch the way you intended.

## Step 1: Prepare the shape

Save this as `curve.svg`:

```svg
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 20" preserveAspectRatio="none">
  <path d="M0 10 C25 20 75 0 100 10 V20 H0 Z" fill="#10b981" />
</svg>
```

You can also create a starting shape with the [SVG maker](/svg-maker), or pick a dedicated [blob tool](/svg-blob-generator) or [wave tool](/svg-wave-generator). Our guide on [how to make an SVG file](/blog/how-to-make-an-svg-file) covers other methods.

## Step 2: Add it with CSS

```css
.hero {
  min-height: 24rem;
  padding-bottom: 5rem;
  background-image: url("/shapes/curve.svg");
  background-repeat: no-repeat;
  background-position: center bottom;
  background-size: 100% 5rem;
}
```

The element needs its own size, from content, padding or a height. A background image doesn't make an empty box grow.

## Step 3: Choose how it scales

| Goal | `background-size` | Result |
|---|---|---|
| Show the whole shape | `contain` | Keeps proportions; may leave space |
| Fill the area | `cover` | Keeps proportions; may crop |
| Stretch a divider across | `100% 5rem` | Fixed height, full width |
| Repeat a small shape | `40px 40px` | Fixed tile size |

To stretch a shape to different proportions, include `preserveAspectRatio="none"` in the SVG file. MDN explains the [sizing rules for SVG backgrounds](https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Backgrounds_and_borders/Scaling_SVG_backgrounds). Stretching suits curves, but it will distort circles and logos.

For a repeating design, the edges of the tile need to match. A [pattern tool](/svg-pattern-generator) can build tiles for you.

## Layer shapes over a color

```css
.card {
  background-color: #f0fdf4;
  background-image: url("/shapes/corner.svg"), url("/shapes/curve.svg");
  background-repeat: no-repeat, no-repeat;
  background-position: top right, bottom center;
  background-size: 8rem auto, 100% 4rem;
}
```

Replace `corner.svg` with your second shape. The first image in the list is the top layer.

## Inline the shape with a data URI

A very small shape can live in your stylesheet, which avoids a separate request:

```css
.dot {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Ccircle cx='5' cy='5' r='4' fill='%2310b981'/%3E%3C/svg%3E");
}
```

Keep `xmlns`, and write `#` in colors as `%23`. An [SVG to Base64 tool](/svg-to-base64) can prepare the encoded string. Separate files are easier to edit and can be cached on their own.

## Change the color from CSS

Page styles such as `fill` don't reach inside a background SVG. For a one-color shape, use it as a mask:

```css
.shape {
  height: 5rem;
  background-color: rebeccapurple;
  -webkit-mask: url("/shapes/curve.svg") center / 100% 100% no-repeat;
  mask: url("/shapes/curve.svg") center / 100% 100% no-repeat;
}
```

A mask hides parts of the whole element, including its text. Use it on an empty decorative element or pseudo-element, and test in the browsers you support.

## Troubleshooting

| Problem | What to check |
|---|---|
| Nothing appears | The file path, and that the element has a width and height |
| Shape won't stretch | `preserveAspectRatio="none"` in the SVG |
| Data URI is blank | Missing `xmlns`, an unencoded `#` or clashing quotes |
| External picture or font is missing | SVG used as an image [can't load external resources](https://developer.mozilla.org/en-US/docs/Web/SVG/Guides/SVG_as_an_image) |
| Thin gap below a divider | Check spacing and the bottom edge of the path |

## Frequently asked questions

### Should I use a background or an img element?

Use a CSS background for decoration. If the picture carries information, use an `img` element with useful `alt` text.

### Can scripts run in a background SVG?

No. Scripts are disabled when SVG is used as an image.

### Is this the same as placing a picture inside SVG?

No. Here the SVG goes into a web page's CSS. To go the other way, see [the SVG image element](/blog/svg-image-element).

## Key takeaways

Give the box a size, set repeat, position and size deliberately, and add `preserveAspectRatio="none"` only when distortion is acceptable. Use a mask when CSS needs to control a one-color shape.