03. Math and Computer Code <sub>, <sup>, <var>, <kbd>, <samp>, <code>, <pre>

Mathematic or Scientific Elements

To specify a subscript or superscript, use <sub> and <sup>.

Additionally, we use the <var> tag to specify any variables.

H<sub>2</sub>O
<var>y</var> = <var>x</var><sup>3</sup>

H2O

y = x3

Keyboard Formatting and User Input

Use the <kbd> to specify keyboard input.

<kbd>$ alias ..="cd .."</kbd>

$ alias ..="cd .."

Sample output

To specify sample output, use the <samp> tag.

<samp>Sample code output goes here.</samp>

Sample code output goes here.

Sample code

To specify a code snippet, use the <code> tag.

<code>
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
</code>

Using the <pre> tag for preformatted text

You may have noticed that HTML truncates white space and line breaks. For example, consider the following code snippet:

<p>         hello 
 
world     </p>

The white space and line breaks don't appear on the document page. HTML truncates all that and simply prints out: hello world.

To get around this, simply wrap your content in the <pre> tags.

<pre><p>         hello 
 
 world     <p></pre>

Build modern and responsive webpages

HTML & CSS

Build modern and responsive webpages Try Front-end

This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.

$ Check price
29.9929.99Amazon 4.5 logo(926+ reviews)

More Front-end resources

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Ad