<code> element?In <code> element is used to show content as a fragment of computer code.
By default, monospace font style is used to display the text/piece of code in between the opening <code> and closing </code> tags.
<code> supports almost every latest browser or browser engine.
This element is still available in the latest version of HTML, but you can also use
. CSS Cascading Style Sheets
<code> .....Content Here.....</code>
The code element supports global attributes as well as event attributes. Some useful properties are mentioned below.
Special attributes | Description |
<samp> | Quoted or Sample output from a computer program. |
<pre> | Preformatted text means same output as it is in Html document. |
<var> | Define a variable name e.g. for mathematical expression. |
<kbd> | Keyboard Input means a span of inline text. |
<command> | Not Available (Discontinued) |
The code snippet below shows how to use the <code> element in HTML documents.
The first line between the <p> tags will get green after execution. Therefore, its font style will also change.
We use a <code> element in line 10.
The code snippet represents how the <code> element can be used to show code in HTML as it is.