Words of the W3C
You should Always use UTF-8
as the Character encoding of your style Sheets and your HTML pages, and declare that encoding in your HTML. If you do that, there is no need to declare the encoding of your style sheet.
PORTUGUÊS:
"You should always wear UTF-8
like the character encoding of your style sheets and your HTML pages and declare this encoding in your HTML. If you do, there is no need to declare encoding your stylesheet."
Source: https://www.w3.org/International/questions/qa-css-charset
So briefly we can say that if you have already declared the Charset
in the HTML that will index this stylesheet vc does not necessarily have to declare the Charset
within the .CSS
To declare Charset in HTML you can use:
<meta charset="utf-8" />
Or
<meta http-equiv="Content-Type" content="text/html; charset=IANAcharset">
Also take these points into account:
- That element
<meta>
is only a part of the algorithm to determine the character set of a page that browsers apply. The header HTTP Content-Type
and any elements of BOM
take precedence over that element.
- It is good practice, and highly recommended, to define the character set using this attribute.
- various cross scripting techniques may harm the page user, such as the
cross-scripting
of fallback UTF-7
. Always setting this goal will protect against these risks.
Then define the Charset
HTML is a security issue and is considered a good practice and highly recommended.
Source: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
See that Mozilla says that:
The rule @charset
specifies the character encoding used in the stylesheet.
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/@charset
Note! It is not enough to simply put @charset "utf-8";
at the top of the style sheet - you also need to save your style sheet in character encoding UTF-8
.
Important: Like the header HTTP
has a higher precedence than the statement in-document @charset
, you should always consider whether character encoding is already stated in the HTTP header. If you are, @charset
should be set to declare the same encoding and will only take effect when the stylesheet is read in a context where there are no HTTP headers (for example, from a local unit).
Supplementary question: CSS operators with @
– Bacco
Know if there is any difference between declaring in HTML or CSS?
<meta charset="utf-8" />
?– hugocsl
@hugocsl That’s right, that’s my question. What would be the technical explanation for this? : D
– Sam
I’ll do a search, but since one is indexed inside the other I think declaring in html would be more prudent... But I’ll look it up before you know it
– hugocsl
Something that is related, if not answer in part to the question is to put styles like
.cabeçalho { }
in a css without@charset
? How the browser should interpret this name once it is out of normal ascii?– Isac