Favorites

CSS <url> Data Type

<url>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <url> data type points to a file such as an image or font, written with url() or as a string. 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 data type represents a reference to a resource, most commonly an image, font, or other external file that the browser can fetch and use. It is a fundamental type in CSS because it allows styles to link to external content dynamically, enabling rich visual design and flexible content management. The <url> type can accept both absolute URLs, like https://example.com/image.png, and relative URLs, which are resolved relative to the location of the CSS file or document.

When used with properties such as background-image, content, or src in @font-face rules, the <url> type allows the browser to fetch external resources and apply them in the context of the rendered page. Its usage is often wrapped with the url() function, which accepts a string containing the resource path. Quotes around the URL are optional, but recommended when the URL contains characters such as spaces or parentheses.

<url> values can be combined with other types, for example using multiple background images in background shorthand or fallbacks for fonts. Proper use of <url> ensures that resources load efficiently and that fallback strategies can be implemented if a resource fails to load. Additionally, URLs can point to images for pseudo-elements like ::before or ::after, making them highly versatile in creative CSS designs.

Code Examples

Background image using <url>:

body {
    background-image: url("images/background.jpg");
    background-size: cover;
}

Using <url> in @font-face:

@font-face {
    font-family: "CustomFont";
    src: url("fonts/customfont.woff2") format("woff2"),
         url("fonts/customfont.woff") format("woff");
}

Using <url> in content for pseudo-elements:

button::before {
    content: url("icons/arrow.svg");
    margin-right: 8px;
}

Relative vs Absolute URL:

/* Relative URL */
div {
    background-image: url("../images/pattern.png");
}

/* Absolute URL */
div {
    background-image: url("https://example.com/images/pattern.png");
}

In essence, the <url> data type is a versatile tool for linking CSS to external resources, making it indispensable for both visual styling and functional content delivery on the web.

Interactive Demo

Demo Code
HTML Code
<div class="demo-element"></div>
CSS Code
.demo-element {
	width: 280px;
	height: 160px;
	border-radius: 8px;
	background-color: #e7ecff;
	background-size: auto 80%;
	background-repeat: no-repeat;
	background-position: center;
	background-image: url("/css-properties/images/sunset.jpg");
}

Syntax

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

Values

  • <string>Represents a reference to a file or file fragment.

Example

<body>

<div class="image-container">
<h1>Hello World</h1>
</div>

</body>
/* Using the <url> data type for a background image */
.image-container {
    width: 100%;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    background-color: #334155; /* shown while the image loads */
    
    /* Absolute URL example */
    background-image: url("https://images.unsplash.com/photo-1506744038136-46273834b3fb");
    
    /* Formatting the background */
    background-size: cover;
    background-position: center;
}
Open in editor

Browser Support

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

This data type 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.