url() CSS Function
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.
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
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
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.
Desktop





Tablets & Mobile





