Which web protocols are possible for the url of a CSS background image?

I am building an application that requires a str_replace() for any strings http: or https: in the URL of a background-image. Does anyone know of any other protocols that are possible for the URL of a background-image? For example, are any of the following possible, or has anyone seen any of the following in a CSS background-image URL?

TCP
UDP
ICMP
POP
FTP
IMAP

As one example, is this possible for CSS?

#myDiv {    background-image: URL("ftps://mysite.com/pub/myimage.png");    }

Thanks for any insight!

Upvotes: 5

Views: 216

Answers (2)

Tobia Tesan
Tobia Tesan

Reputation: 1936

Very interesting question.

The CSS2 standard doesn't seem to prescribe anything in particular as long as we have valid URIs as per RFC3986, nor does CSS1.

Whether your URIs will actually work then depends on whether your browser can access that URI (and you have the appropriate permissions, etc).

I imagine this is intended, for a reason: it means that the CSS specification is transport layer agnostic, which makes plenty of sense.

In practice you can thus, for example, link to HTTPS resources in a CSS1-compliant stylesheet, even if CSS1 predates the RFC for HTTPS.

Upvotes: 1

audun
audun

Reputation: 154

It's clearly legal syntax, following the CSS standard by W3C. You may put any legal URI there, but it depends on the browser whether it will work or not.

TCP, UDP and ICMP are a different type of protocols, so they won't work, but ftp, pop and imap can work in theory. See here for syntax: https://en.wikipedia.org/wiki/URI_scheme

You may also replace all the images with data URIs, basically embedding everything.

Upvotes: 2

Related Questions