Tutorials 参考 练习 Menu
Paid Courses

HTML <code> Tag


例子

Define some text as computer code in a document:

<p>The HTML <code>button</code> tag defines a clickable button.</p>

<p>The CSS <code>background-color</code> property defines the background color of an element.</p>
来试试吧 »

More "来试试吧" examples below.


Definition and Usage

The <code> tag is used to define a piece of computer code. The content inside is displayed in the browser's default monospace font.

Tip: This tag is not deprecated. However, it is possible to achieve richer effect by using CSS (see example below).

Also look at:

Tag 描述
<samp> Defines sample output from a computer program
<kbd> Defines keyboard input
<var> Defines a variable
<pre> Defines preformatted text

Browser Support

Element
<code> Yes Yes Yes Yes Yes

Global Attributes

The <code> tag also supports the Global Attributes in HTML.


Event Attributes

The <code> tag also supports the Event Attributes in HTML.


More 示例

例子

Use CSS to style the <code> element:

<html>
<head>
<style>
code {
  font-family: Consolas,"courier new";
  color: crimson;
  background-color: #f1f1f1;
  padding: 2px;
  font-size: 105%;
}
</style>
</head>
<body>

<p>The HTML <code>button</code> tag defines a clickable button.</p>
<p>The CSS <code>background-color</code> property defines the background color of an element.</p>

</body>
</html>
来试试吧 »

Related Pages

HTML tutorial: HTML Text Formatting

HTML DOM reference: Code Object


Default CSS Settings

Most browsers will display the <code> element with the following default values:

例子

code {
  font-family: monospace;
}
来试试吧 »