<code> HTML Tag
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Element of
- Learn How Fonts And Web Typography Work In HTML: A Beginner's Guide
- What does
<code> HTML Tag
do? - The <code> element is used to define enclosed text as computer code. It is often paired with the <pre> element to preserve line breaks and indentation when presenting blocks of computer code.
- Display
- inline
- Usage
- textual
Code Example
The <code><code></code> element defines inline code.
The
<code>
element defines inline code.Not all you need
If you want to present code samples in your site, the <code>
element is not the only thing you’ll need. For multi-line (“block”) code presentation, the most common approach is to use the <pre>
element, and then put the <code>
element inside that. Additionally, special characters that don’t render properly in HTML (like angle-brackets and ampersands) may need to be converted into their appropriate HTML Character Entity codes. This is highly error-prone work if done by hand. If you are writing a lot of code samples for your site, you may want to look at automated code rendering via a system like Markdown or an embedding service like Github’s gist.
Browser Support for code
![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
All | All | All | All | All | All |