<code> HTML Tag

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.

We use cookies to personalize content and ads, and to analyze our traffic. We also share information about your use of our site with our social media, advertising and analytics partners who may combine it with other information that you’ve provided to them or that they’ve collected from your use of their services. You consent to our cookies if you continue to use our website.OkLearn more about how we use cookies in our Cookies Policy