Utf-8

2 snippets across 2 stacks — HTML & CSS, Python

HCHTML & CSS

Character Encoding

HC · Document Structure
syntax
<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.

PYPython

Encode & Decode

PY · Strings
syntax
str.encode(encoding)
bytes.decode(encoding)
example
text = "caf\u00e9"
encoded = text.encode("utf-8")
print(encoded)
print(encoded.decode("utf-8"))
output
b'caf\xc3\xa9'
caf\u00e9

Note UTF-8 is the default encoding. Use errors='ignore' or errors='replace' to handle characters that cannot be encoded in the target encoding.