A URL parser exposes the canonical host representation of an internationalized name. Keep display text separate from comparison keys.
Worked example
const url = new URL("https://café.example/menu");
console.log(url.hostname, url.pathname);Result
xn--caf-dma.example /menuImplementation notes
Do hostname comparisons on parsed hostnames. Comparing the raw address text can conflate a port, user information or path text with the host.
Try it yourself
Inspect hostname and href for a Unicode label and its ASCII encoding.
Open the JavaScript example →Editorial date March 13, 2026 · Published December 6, 2026