HTML Basics

HTML Computer Code Elements

HTML has several elements built for displaying computer code, keyboard input, and program output in a clear, monospaced style.


The code and pre Elements

The <code> element marks a snippet of code inline. On its own it does not preserve spaces or line breaks, so wrap multi-line code in a <pre> element too.

Inline and block code
<p>Use the <code>console.log()</code> function.</p>

<pre><code>function greet() {
  console.log("Hello!");
}</code></pre>

Other Code-Related Elements

ElementRepresentsExample use
<kbd>Keyboard input the user typesPress <kbd>Ctrl</kbd> + <kbd>S</kbd>
<samp>Sample output from a program<samp>File saved.</samp>
<var>A variable or placeholderThe area is <var>width</var> x <var>height</var>
Using kbd, samp, and var
<p>Press <kbd>Enter</kbd> to run the program.</p>
<p>The program printed <samp>Done!</samp></p>
<p>Solve for <var>x</var> in the equation.</p>
💡

Inside a <pre> block, use the entity &lt; instead of < so the browser shows the character rather than treating it as a real tag.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships