Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In CSS, when does/should one use the `url()` function versus a string?

Tags:

css

url

What's the difference between

.class { background-image: 'bg.png'; }

and

.class { background-image: url('bg.png'); }

?

Equivalently,

@import 'file.css';

vs.

@import url('file.css');
like image 716
chharvey Avatar asked Jul 04 '14 18:07

chharvey


1 Answers

In my testing and research, background-image: 'bg.png'; is completely invalid. According to MDN, background-image must be defined as a keyword or an <image> which when referencing an image file must use the url function.

For @import however, the url function is optional and there is no difference.


Invalid:

.class {
    background-image: 'bg.png';
}

Valid:

.class {
    background-image: url('bg.png');
}

Valid and Identical:

@import 'file.css';
@import url('file.css');
like image 86
Alexander O'Mara Avatar answered Nov 14 '22 23:11

Alexander O'Mara