21/4/2020 HTML Computer Code Elements
w3schools.com
HTML CSS MORE
HTML Computer Code Elements
❮ Previous Next ❯
Computer Code
<code>
x = 5;<br>
y = 6;<br>
z = x + y;
</code>
Try it Yourself »
HTML <kbd> For Keyboard Input
The HTML <kbd> element represents user input, like keyboard input or voice
commands.
Text surrounded by <kbd> tags is typically displayed in a monospace font:
Example
<p>Save the document by pressing <kbd>Ctrl + S</kbd></p>
Result:
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 1/8
21/4/2020 HTML Computer Code Elements
Save the document by pressing Ctrl + S
Try it Yourself »
HTML <samp> For Program Output
The HTML <samp> element represents output from a program or computing system.
Text surrounded by <samp> tags is typically displayed in a monospace font:
Example
<p>If you input wrong value, the program will return <samp>Error!</samp></p>
Result:
If you input wrong value, the program will return Error!
Try it Yourself »
HTML <code> For Computer Code
The HTML <code> element defines a fragment of computer code.
Text surrounded by <code> tags is typically displayed in a monospace font:
Example
<code>
x = 5;
y = 6;
z = x + y;
</code>
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 2/8
21/4/2020 HTML Computer Code Elements
Result:
x = 5; y = 6; z = x + y;
Try it Yourself »
Notice that the <code> element does not preserve extra whitespace and line-breaks.
To fix this, you can put the <code> element inside a <pre> element:
Example
<pre>
<code>
x = 5;
y = 6;
z = x + y;
</code>
</pre>
Result:
x = 5;
y = 6;
z = x + y;
Try it Yourself »
HTML <var> For Variables
The HTML <var> element defines a variable.
The variable could be a variable in a mathematical expression or a variable in
programming context:
Example
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 3/8
21/4/2020 HTML Computer Code Elements
Einstein wrote: <var>E</var> = <var>mc</var><sup>2</sup>.
Result:
Einstein wrote: E = mc2.
Try it Yourself »
HTML Exercises
Test Yourself With Exercises
Exercise:
Define the text "var person;" as programming code.
<p>Code example: var person; </p>
Submit Answer »
Start the Exercise
HTML Computer Code Elements
Tag Description
<code> Defines programming code
<kbd> Defines keyboard input
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 4/8
21/4/2020 HTML Computer Code Elements
<samp> Defines computer output
<var> Defines a variable
<pre> Defines preformatted text
For a complete list of all available HTML tags, visit our HTML Tag Reference.
❮ Previous Next ❯
COLOR PICKER
HOW TO
Tabs
Dropdowns
Accordions
Side Navigation
Top Navigation
Modal Boxes
Progress Bars
Parallax
Login Form
HTML Includes
Google Maps
Range Sliders
Tooltips
Slideshow
Filter List
Sort List
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 5/8
21/4/2020 HTML Computer Code Elements
SHARE
CERTIFICATES
HTML
CSS
JavaScript
SQL
Python
PHP
jQuery
Bootstrap
XML
Read More »
REPORT ERROR
PRINT PAGE
FORUM
ABOUT
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
jQuery Tutorial
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 6/8
21/4/2020 HTML Computer Code Elements
Java Tutorial
C++ Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
jQuery Reference
Java Reference
Angular Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
jQuery Examples
Java Examples
XML Examples
Web Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
jQuery Certificate
PHP Certificate
Bootstrap Certificate
XML Certificate
Get Certified »
W3Schools is optimized for learning, testing, and training. Examples might be simplified to improve
reading and basic understanding. Tutorials, references, and examples are constantly reviewed to avoid
errors, but we cannot warrant full correctness of all content. While using this site, you agree to have
read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data.
All Rights Reserved.
Powered by W3.CSS.
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 7/8
21/4/2020 HTML Computer Code Elements
file:///C:/Users/Peregrin0/Documents/cursos programacion/www.w3schools.com/html/html_computercode_elements.html 8/8