HTML code
HTML Code <code>
tag is used to define computer code in an HTML document. The text in this tag is applied with font-family of monospace.
Example
A simple Code element is shown in the following example.
index.html
</>
Copy
<!DOCTYPE html>
<html>
<body>
<p>normal text <code>some code</code></p>
</body>
</html>
Note: HTML Code element starts with the tag <code>
and ends with an end tag </code>
.
Default CSS for HTML <code>
By default, following CSS properties are set for a Code element.
</>
Copy
font-family: monospace;
Inline Style for HTML Code Element
We can change the style of Code element through inline styling using style attribute.
In the following example, we have set the color to red for the Code element.
index.html
</>
Copy
<!DOCTYPE html>
<html>
<body>
<p>normal text <code style="color:red">some code</code></p>
</body>
</html>
Apply CSS for HTML Code Element
We can apply CSS for all Code elements using the code
tag name.
index.html
</>
Copy
<!DOCTYPE html>
<html>
<head>
<style>
code {
color:red;
}
</style>
</head>
<body>
<p>normal text <code>some code</code></p>
</body>
</html>
Conclusion
In this HTML Tutorial, we learned about HTML <code> tag and went through different examples that cover defining an HTML Code element, and styling it.