The code Tag
The `<code>` tag in HTML is designed to display computer code snippets with fixed formatting for optimal readability. It renders the code in a monospace font, preserving the original spacing and layout. The `<code>` tag also supports both global attributes and event attributes, allowing for flexible styling and interaction.
Syntax:
<code> Computer code contents... </code>
Note: The program that is written inside the <code> tag has some different font sizes and font types to the basic heading tag and paragraph tag.
Example: The <code> tag displays a C program within a <pre> tag, preserving whitespace and formatting. The C program includes the stdio.h library and a main function that prints “Hello Geeks”.
<!DOCTYPE html>
<html>
<body>
<pre>
<code>
#include <stdio.h>
int main() {
printf("Hello Geeks");
}
</code>
</pre>
</body>
</html>
Output:
HTML Computer Code Elements
The computer has a unique formatting and text style for displaying the messages related to codes. There are several elements available to mark up computer code elements using HTML which are as follows:
Table of Content
- The code Tag
- The kbd Tag
- The pre Tag
- The samp Tag
- The var Tag
- HTML Computer Code Elements
- Supported Browsers
Contact Us