
- HTML - Home
- HTML - Roadmap
- HTML - Introduction
- HTML - History & Evolution
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML Computer Code Elements
HTML computer code elements (tags) provide unique formatting and text styles for different types of code-related messages, such as keyboard input, preformatted text, code snippets, variables, and sample outputs. The computer code elements are listed as follows:
HTML <kbd> Element
The <kbd>
tag is used to define the keyboard input. Use this when you want the user to type on their keyboard, for example, shortcut keys Ctrl+C for copy, Esc for exit, etc.
Example
Let us now see an example to implement the <kbd>
tag:
<!DOCTYPE html> <html> <body> <h2>Example of kbd Tag</h2> <p>Use the following shortcut keys:</p> <p><strong>Cut</strong> <kbd>CTRL</kbd>+<kbd>X</kbd></p> <p><strong>Copy</strong> <kbd>CTRL</kbd>+<kbd>C</kbd></p> <p><strong>Paste</strong> <kbd>CTRL</kbd>+<kbd>V</kbd></p> <p><strong>Undo</strong> <kbd>CTRL</kbd>+<kbd>Z</kbd></p> </body> </html>
HTML <pre> Element
The <pre>
tag in HTML is used to set preformatted text. The text preserves spaces and line breaks, appearing the same on the web page as in the HTML code.
Example
Let us now see an example to implement the <pre>
tag:
<!DOCTYPE html> <html> <body> <h2>Example of pre Tag</h2> <pre> This is a demo text and will appear in the same format as it is visible here. The pre tag displays the text in a fixed-width font. It preserves both spaces and line breaks as you can see here. </pre> </body> </html>
HTML <code> Element
The <code>
tag is used to format code in an HTML document. For example, to write and format Java code properly, use the <code> element.
Example
Let us now see an example to implement the <code>
element:
<!DOCTYPE html> <html> <body> <h1>Example of code Tag</h1> <h2>C++</h2> <code> #include <iostream> </code> <h2>C</h2> <code> #include <stdio.h> </code> </body> </html>
HTML <var> Element
The <var>
tag in HTML is used to display mathematical expressions for calculations.
Example
Let us now see an example to implement the <var>
tag:
<!DOCTYPE html> <html> <body> <h2>Example of var Tag</h2> Sample equation <var>2x</var> - <var>2z</var> = <var>3y</var> + 9 </body> </html>
HTML <samp> Element
The <samp>
tag is a phrase tag used to format text in an HTML document.
Example
Let us now see an example to implement the <samp>
element:
<!DOCTYPE html> <html> <body> <h2>Exam Results</h2> <p><s>Result would be announced on 6th June.</s></p> <samp>New date for results is 7th June.</samp> </body> </html>
HTML Computer Code Elements
Here is the list of the computer code tags along with their descriptions used for defining user input and computer code:
Tag | Description |
---|---|
<kbd> |
Defines keyboard input. |
<pre> |
Displays preformatted text with preserved spaces and line breaks. |
<code> |
Defines a piece of computer code. |
<var> |
Represents a variable in programming or math expressions. |
<samp> |
Defines sample output from a program or device. |