# Use encoding declarations for encoding detection in CotEditor on Mac

When the “Refer to encoding declaration in document” option in the Format settings pane is selected, CotEditor reads the following types of encoding declarations (if present) — `charset=`, `encoding=`, `@charset`, `encoding:` and `coding:` — when opening a file. If written properly, these declarations are used to determine the file’s text encoding.

A declaration can be anywhere in the document, the one either in the comment area or in a plain sentence is detected. When you want to use a phrase such as “charset=UTF-8” even though your document’s encoding is not UTF-8, you need to put an actual encoding declaration prior to the phrase, or, unselect the “Refer to encoding declaration in document” option in the Format settings.

- The scope to scan declarations is limited to 2,000 characters from the head of the document.
- To make the detection of declarations work, you have to put an equal sign (“=”, no other characters) right after “`charset`” or “`encoding`.”
- The encoding name which comes after “`charset=`” or “`encoding=`” can be without double-quotes (") around.
- In the case there are multiple encoding declarations in your document, CotEditor uses the first one to determine the text encoding.

## See also

- Change Format settings
- Change priorities of text encodings
- Use four kinds of Shift JIS properly