HTML-<code> Tag
Definition und Verwendung
<code>
Das Tag wird verwendet, um Code-Schnipsel zu definieren, deren Inhalt in der Standardbreitenschrift des Browsers angezeigt wird.
Tipp:Dieser Tag ist nicht abgekündigt. Er kann jedoch durch die Verwendung von CSS effizientere Effekte erzielen (siehe untenes Beispiel).
Siehe auch:
Tag | Beschreibung |
---|---|
<samp> | Definieren Sie Beispiel-Ausgaben von Computerprogrammen. |
<kbd> | Definieren Sie Tastatureingaben. |
<var> | Definieren Sie Variablen. |
<pre> | Definieren Sie vorformatierten Text. |
Siehe auch:
HTML-Tutorial:HTML Text Formatting
HTML DOM Referenzhandbuch:Code-Objekt
Beispiel
Beispiel 1
Definieren Sie einige Texte als Computercode im Dokument:
<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 the element.</p>
Beispiel 2
Stellen Sie den Stil des <code>-Elements mit CSS ein:
<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 the element.</p> </body> </html>
Global Attributes
<code>
The tag also supports Global Attributes in HTML.
event attributes
<code>
The tag also supports Event Attributes in HTML.
Default CSS Settings
Most browsers will display the following default values <code>
Element:
code { font-family: monospace; }
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |