Favorites

url() CSS Function

url()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The url() function points to a file, such as an image, font or SVG, by its address. Relative URLs are resolved against the style sheet.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The url() CSS function is used to reference a file, such as an image, a font, an SVG filter or another stylesheet. It produces a <url> value that can be used with properties such as background-image, list-style-image, border-image-source, cursor, mask-image and content, as well as in the src descriptor of @font-face and in @import rules.

The address can be absolute, such as https://example.com/logo.png, or relative. Relative URLs are resolved against the location of the stylesheet that contains them, not the HTML page, which is a common source of broken images when CSS files live in a different folder. The URL can be written with or without quotes; quotes are required if it contains spaces, parentheses or quotes. It can also be a data: URL that embeds the file directly in the CSS, which is handy for small icons, and a fragment such as #id to reference an element inside an SVG file.

.hero {
  background-image: url("../images/hero.jpg");
}

@font-face {
  font-family: "Brand";
  src: url("/fonts/brand.woff2") format("woff2");
}

/* Inline SVG icon as a data URL */
.check::before {
  content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M2 8l4 4 8-8' stroke='green' fill='none' stroke-width='2'/%3E%3C/svg%3E");
}

/* Reference an SVG filter by id */
.blurred {
  filter: url("filters.svg#soft-blur");
}

Interactive Demo

Demo Code
HTML Code
<div class="demo-element"></div>
CSS Code
.demo-element {
	width: 280px;
	height: 170px;
	background-color: #e7ecff;
	border: 2px solid #4361ee;
	background-image: url("/css-properties/images/sunset.jpg");
	background-size: cover;
}

Syntax

url() = url( <string> <url-modifier>* ) | url( <url-token> )

Values

  • <string>A quoted URL: absolute, relative to the stylesheet, a data: URL, or a fragment (#id) pointing to an element in an SVG document.
  • <url-token>An unquoted URL. Spaces, quotes and parentheses must be escaped with a backslash.
  • <url-modifier>Optional modifiers defined by specifications to change how the URL is fetched. None are widely supported yet.

Example

<div class="wrap">
<h1>CSS url() examples</h1>
<div class="grid">
<div class="card">
<div class="box"></div>
<div class="label">background-image: url("data:image/svg+xml,...")</div>
</div>
<div class="card">
<ul class="list">
<li>Relative to the stylesheet</li>
<li>Absolute URLs</li>
<li>Inline data URLs</li>
</ul>
<div class="label">list-style-image: url("data:image/svg+xml,...")</div>
</div>
</div>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* url() examples */
.box {
height: 140px;
border-radius: 12px;
background-color: #eff6ff;
/* an inline SVG pattern as a data URL */
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32'%3E%3Ccircle cx='16' cy='16' r='5' fill='%232563eb'/%3E%3C/svg%3E");
}

.list {
margin: 0;
padding-left: 26px;
/* data URL used as a custom list marker */
list-style-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16'%3E%3Cpath d='M2 8l4 4 8-8' stroke='%2316a34a' fill='none' stroke-width='3'/%3E%3C/svg%3E");
line-height: 1.8;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS url() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.