Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

<code>: The Inline Code element

BaselineWidely available

The<code>HTML element displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code. By default, the content text is displayed using theuser agent's default monospace font.

Try it

<p>  The <code>push()</code> method adds one or more elements to the end of an  array and returns the new length of the array.</p>
code {  background-color: #eee;  border-radius: 3px;  font-family: courier, monospace;  padding: 0 3px;}

Attributes

This element only includes theglobal attributes.

Examples

A paragraph of text that includes<code>:

html
<p>  The function <code>selectAll()</code> highlights all the text in the input  field so the user can, for example, copy or delete the text.</p>

Result

Notes

To represent multiple lines of code, wrap the<code> element within a<pre> element. The<code> element by itself only represents a single phrase of code or line of code.

A CSS rule can be defined for thecode selector to override the browser's default font face. Preferences set by the user might take precedence over the specified CSS.

Technical summary

Content categoriesFlow content,phrasing content, palpable content.
Permitted contentPhrasing content.
Tag omissionNone, both the starting and ending tag are mandatory.
Permitted parents Any element that acceptsphrasing content.
Implicit ARIA rolecode
Permitted ARIA rolesAny
DOM interfaceHTMLElement Up to Gecko 1.9.2 (Firefox 4) inclusive, Firefox implements theHTMLSpanElement interface for this element.

Specifications

Specification
HTML
# the-code-element

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp