<code> element represents a fragment of computer code. This could be any string-based data a computer would recognize. It’s a very useful inline element; I’ve even used it in this opening paragraph!
<p>First set a constant variable <code>const name = "Jane";</code></p>
<code> tag is supported in all modern browsers. Read more on caniuse.com.
<code> tag supports Global Attributes in HTML. Global Attributes are common to all HTML elements and can be used on all of them (though they may not have much of an effect on some of them).
Related HTML Elements
preelement is sometimes confused with the
codeelement, and they’re often rendered in a similar way. However, the
pretag is for preformatted text, and tells the browser “the whitespace (new lines and spaces) should be preserved”. The
codetag is purely for representing inline code.
<code> element accepts phrasing content.
Code Syntax Highlighting Libraries
pre tag surrounding the
code tag so be sure to account for that. Below are some options to consider for your next project.