- Home
- /
- HTML Code Tag
HTML Tutorial
INTRODUCTION
HTML BASIC TAGS
INLINE & BLOCK ELEMENTS
HTML LISTS
HTML TABLES
HTML FORMS
HEAD ELEMENTS
HTML MEDIA
MISCELLANEOUS TAGS
- Home
- /
- HTML Code Tag
HTML Code Tag
The <code>
tag in HTML is used to display code snippets, whether inline or as full blocks it’s a semantic tag that tells both browsers and developers: “This is code!”
What is the <code>
tag?
The <code>
tag represents a fragment of computer code. It’s typically used to display programming code. It’s typically used to display programming code in tutorial, documentation, and technical blogs.
- Inline usage: Great for short bits of code in a sentence.
- Block usage: Ideal when combined with
<pre>
for multiline code
Why use <code>
?
- Semantic clarity: clearly marks content as code.
- Easy styling: Works well with CSS or libraries like prism.js.
- Improve readability: Visually separate code from other text.
Inline Usage Example
Use the <img>
tag to embed images.
Output
Use the <img>
tag to embed images.
Multiline Code with <pre><code>
Wrap your code in both <pre>
and <code>
to preserve formatting:
function greet() {
alert("Hello, World!");
}
This keeps indentation and line breaks exactly as written.
Conclusion
The HTML <code>
tag is a simple yet powerful way to include code snippets in your webpage.