I've inherited some CSS that has the charset set at the top of the CSS like this:
@charset "UTF-8";
But is this still necessary if I have a tag in the head of the HTML page like this?
<meta charset="UTF-8" />
Does it do the same thing?
I've inherited some CSS that has the charset set at the top of the CSS like this:
@charset "UTF-8";
But is this still necessary if I have a tag in the head of the HTML page like this?
<meta charset="UTF-8" />
Does it do the same thing?
Both do the same thing, they suggest the browser which charset was used when writing and saving the document.
It helps the browser decide which charset to display/parse the file in, so that it won't come out as gibberish.
If you don't use either one, the browser will take an educated guess and read the file in whatever charset it thinks most appropriate. Modern browser will generally do it easily.
I personally never used the CSS version, and my IDE adds the HTML version automatically, so I don't mind about it.
<meta charset="UTF-8" />
is for the HTML document while @charset
is for the CSS document. None of them is necessary if the http
header tells the browser that both the files are utf-8
encoded. These are only important if you view them locally.