For displaying text as code
codeelement for inline code and the
preelement for multiple lines of code:
const user = await fetch(url, init); alert(user.name);
||Native element||Multi-line text|
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!
You should use
aria-description to explain the code. For example: