--- title: '<code>: 行内コード要素' slug: Web/HTML/Element/code tags: - Code - Element - HTML - HTML text-level semantics - Inline Code - Reference - Web translation_of: Web/HTML/Element/code --- <div>{{HTMLRef}}</div> <p id="Summary"><span class="seoSummary"><strong>HTML の <code><code></code> 要素</strong>は、コンピューターコードの短い断片の文字列であると識別できるような外見のコンテンツを表示します。</span>既定では、中の文字列が{{Glossary("user agent", "ユーザーエージェント")}}の既定の等幅フォントを使用して表示されます。</p> <div>{{EmbedInteractiveExample("pages/tabbed/code.html", "tabbed-shorter")}}</div> <div class="hidden">このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> をクローンしてプルリクエストを送信してください。</div> <table class="properties"> <tbody> <tr> <th scope="row"><a href="/ja/docs/Web/HTML/Content_categories">コンテンツカテゴリ</a></th> <td><a href="/ja/docs/Web/HTML/Content_categories#Flow_content">フローコンテンツ</a>, <a href="/ja/docs/Web/HTML/Content_categories#Phrasing_content">記述コンテンツ</a>, 知覚可能コンテンツ</td> </tr> <tr> <th scope="row">許可されている内容</th> <td><a href="/ja/docs/Web/HTML/Content_categories#Phrasing_content">記述コンテンツ</a></td> </tr> <tr> <th scope="row">タグの省略</th> <td>{{no_tag_omission}}</td> </tr> <tr> <th scope="row">許可されている親要素</th> <td><a href="/ja/docs/Web/HTML/Content_categories#Phrasing_content">記述コンテンツ</a>を受け入れるすべての要素</td> </tr> <tr> <th scope="row">暗黙の ARIA ロール</th> <td><a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role">対応するロールなし</a></td> </tr> <tr> <th scope="row">許可されている ARIA ロール</th> <td>すべて</td> </tr> <tr> <th scope="row">DOM インターフェイス</th> <td>{{domxref("HTMLElement")}}。Gecko 1.9.2 (Firefox 4) 以前では、この要素には {{domxref("HTMLSpanElement")}} インターフェイスが実装されています。</td> </tr> </tbody> </table> <h2 id="Attributes" name="Attributes">属性</h2> <p>この要素には<a href="/ja/docs/Web/HTML/Global_attributes">グローバル属性</a>以外の属性はありません。</p> <h2 id="Example" name="Example">例</h2> <p><code><code></code> を含むテキストの段落です。</p> <pre class="brush: html notranslate"><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> </pre> <p>この HTML によって生成される出力は以下のようになります。</p> <p>{{EmbedLiveSample("Example", 640, 70)}}</p> <h2 id="Notes" name="Notes">補足</h2> <p>複数行のコードを表すには、 <code><code></code> 要素を {{HTMLElement("pre")}} 要素の中に入れてください。 <code><code></code> 要素自身は、コードの単一のフレーズや1行のみを表します。</p> <p>CSS の規則によって、 <code>code</code> セレクターを定義して、ブラウザーの既定のフォントを上書きすることができます。ユーザーによる設定を CSS による指定より優先させることもできます。</p> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName('HTML WHATWG', 'semantics.html#the-code-element', '<code>')}}</td> <td>{{Spec2('HTML WHATWG')}}</td> <td></td> </tr> <tr> <td>{{SpecName('HTML5 W3C', 'textlevel-semantics.html#the-code-element', '<code>')}}</td> <td>{{Spec2('HTML5 W3C')}}</td> <td></td> </tr> <tr> <td>{{SpecName('HTML4.01', 'struct/text.html#h-9.2.1', '<code>')}}</td> <td>{{Spec2('HTML4.01')}}</td> <td></td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat("html.elements.code")}}</p> <h2 id="See_also" name="See_also">関連情報</h2> <ul> <li>{{HTMLElement("samp")}}</li> <li>{{HTMLElement("kbd")}}</li> <li>{{HTMLElement("command")}} (非推奨)</li> <li>{{HTMLElement("var")}}</li> <li>{{HTMLElement("pre")}}</li> </ul>