Character Encoding
HC · Document Structuresyntax
<meta charset="UTF-8">example
<head>
<meta charset="UTF-8">
</head>Note Must appear within the first 1024 bytes of the document. UTF-8 handles virtually all global characters and emoji.
2 snippets across 2 stacks — HTML & CSS, Python
<meta charset="UTF-8"><head>
<meta charset="UTF-8">
</head>Note Must appear within the first 1024 bytes of the document. UTF-8 handles virtually all global characters and emoji.
str.encode(encoding)
bytes.decode(encoding)text = "caf\u00e9"
encoded = text.encode("utf-8")
print(encoded)
print(encoded.decode("utf-8"))b'caf\xc3\xa9'
caf\u00e9Note UTF-8 is the default encoding. Use errors='ignore' or errors='replace' to handle characters that cannot be encoded in the target encoding.