HTML5 <code> Tag

The HTML <code> tag is used to represent a fragment of computer code. Unless explicitly specified, its contents are displayed in the browser’s default monospace font.

The only content permitted inside this element is phrasing content. Both the starting and ending tag are mandatory for this element. The parent of the <code> tag can be any element that accepts phrasing content.

The following style is applied to this element by default:

code {
  font-family: monospace;

Here is an example of using this tag:

<p>This is how we declare a Javascript variable:<br\>    
  <code>var i = 0;</code> 


This element only accepts global attributes.


See the Pen HTML code Tag by Tutorialio (@tutorialio) on CodePen.

Further Reading

  1. Read more about the HTML <code> element on MDN.
  2. You can also read the HTML <code> tag reference on W3C.

Reader Comments

1. You can register or login to post a comment. Asking readers to register improves the quality of discussion.

2. As a registered user, you will also get to access features like choosing between a light and dark theme or anything else that we might implement in future.

Follow Us For Updates

Go To Top