Code

For displaying text as code

Demo

Use the code element for inline code and the pre element for multiple lines of code:
const user = await fetch(url, init);
alert(user.name);

API

Tags

Name Type Content
code Native element Text
pre Native element Multi-line text

Guidelines

Security

Because these elements' content is code, take extra care to ensure you're preventing cross-site scripting. There's nothing that makes these elements more or less secure than any other, but in this case you know for sure you're dumping code into the DOM, so be careful!

Accessibility

You should use aria-label and/or aria-description to explain the code. For example:

fetch(url, init)