CKTIS / CSS
url(): a resource reference, not a promise of successful loading
Write quoted paths, understand their base URL and separate parsing from fetching a usable resource.
Version: CSS Modules
Syntax
background-image: url("images/pattern.svg");url() supplies a resource reference in contexts such as background-image, a font source or an SVG filter reference. A quoted string is convenient when a path contains spaces or parentheses. The unquoted form has stricter escaping rules; an unescaped internal space is not accepted as part of its URL token. A plain string is allowed instead only in contexts that explicitly permit one, such as @import.
Relative references in an external stylesheet are based on that stylesheet’s location. Embedded and inline CSS use the containing document’s base. Thus moving a stylesheet to another directory can break its relative images without changing the HTML address. A fragment-only reference such as url("#filter") has local-reference rules for elements in the applicable tree; it is not simply an ordinary relative file path.
Accepted syntax is separate from resource availability, allowed request policies and a format usable in the chosen property. An empty url("") is an invalid resource, not an instruction to load the current page. url(var(--path)) also fails because of the special URL-token parsing; a common alternative is to store the complete url("...") value in a custom property and use var() as the property value.
The example sets a document base under /pages/ and measures an inline relative reference resolving to /pages/tiles/pattern.svg. An absolute /assets/pattern.svg address stays absolute. The quoted-space check returns true, the unquoted-space check false, and the empty reference serializes as url(""). External requests are blocked in the recorded test: it verifies syntax and computed URL resolution, not successful downloads or displayed images.
Examples
const base=document.createElement('base');base.href='https://example.invalid/pages/';document.head.append(base);
const inline=document.createElement('div');inline.style.backgroundImage='url("tiles/pattern.svg")';document.body.append(inline);
const inlineResolved=getComputedStyle(inline).backgroundImage;
const absolute=document.createElement('div');absolute.style.backgroundImage='url("https://example.invalid/assets/pattern.svg")';document.body.append(absolute);
const absoluteResolved=getComputedStyle(absolute).backgroundImage;
inline.style.backgroundImage='url("")';const empty=getComputedStyle(inline).backgroundImage;
console.log('inline='+inlineResolved+'; absolute='+absoluteResolved+'; quoted-space='+CSS.supports('background-image','url("a b.svg")')+'; unquoted-space='+CSS.supports('background-image','url(a b.svg)')+'; empty='+empty);Result
inline=url("https://example.invalid/pages/tiles/pattern.svg"); absolute=url("https://example.invalid/assets/pattern.svg"); quoted-space=true; unquoted-space=false; empty=url("")The reserved example.invalid host makes these illustrative addresses explicit. The example uses inline styles; the separate rule for external stylesheet bases is explained in the text, not claimed as an executed network test.