# @charset

> The `@charset` CSS directive defines the character encoding of the stylesheet.

## Do I need @charset in my CSS file?

The directive that declares the character encoding of a stylesheet, like UTF-8. It should be placed at the very top of the CSS file, ensuring that the browser correctly interprets the characters in the file.

- Topic: Directives
- Type: directive
- Browser support: Chrome 2+, Chrome Android 18+, Edge 12+, Firefox 1.5+, Firefox Android 4+, Safari 4+, Safari iOS 4+

## Example

Wrong:

```css
/* styles */
@charset 'utf-8';
```

Right:

```css
@charset "UTF-8";
/* styles */
```

`@charset` must be the first bytes of the file and use double quotes, or browsers skip it.

## Common mistakes

- Placing `@charset` after a comment or blank line, so it is ignored.
- Using single quotes, which makes the rule invalid.

## Key points

- `@charset` is the very first thing in the file, with double quotes and a semicolon.
- Stylesheets are saved as UTF-8, served with a UTF-8 `Content-Type` header.

## Interview questions

### When is `@charset` needed?

Only when the CSS has non-ASCII characters and the server does not send a charset. A UTF-8 file with a correct header doesn't need it.

### Can I use `@charset` in a `<style>` tag?

No, it is ignored in inline styles and `style` attributes; the HTML document encoding applies.

## Related cards

- [UTF-8](https://wonderium.dev/web/utf-8.md)
- [Directive](https://wonderium.dev/css/directive.md)
- [`<meta>`](https://wonderium.dev/html/meta.md)
- [HTTP Header](https://wonderium.dev/web/http-header.md)
- [content](https://wonderium.dev/css/content.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/charset
- Last updated: 2026-11-25
