Computer Code


Computer Code

When we write computer programs it becomes necessary to show the output to the user. The output could be the result or an error. HTML has elements that can be used to write codes on the web page.

For displaying messages connected to codes, the computer uses a particular formatting and text style. The < code> tag is used to display the website's computer code. HTML allows you to mark up computer code with a variety of elements.

Some notes about the < code > tag:

  • It's primarily used to show a code snippet in a web browser.
  • This tag sets its element to match the default text format on the computer.
  • For the < code > tags element content, web browsers employ a monospace font family by default.

< code > tag

  • This tag is used to display computer code on the webpage. The data written in between the tags is displayed in monospaced format.
  • < kbd> tag

    It is used to define the keyboard input, user input, or voice command.
  • < samp> tag

    It is used to display the computer program’s sample output on the webpage. The content is displayed in monospaced format.
  • < var> tag

    It is used to define a variable in programming context or mathematical expression. The content inside the tags is mostly displayed in italic format.
  • < pre> tag

    It is used to define content in a preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers.

Example No.1:

<html> <body> <h2>Computer Code</h2> <p>Knowledge2life</p> <code> x = Knowledge2life; y = Website; z = x + y; </code> </body> </html>

OUTPUT:

Computer Code

Knowledge2life x = Knowledge2life; y = Website; z = x + y;

Example No.2:

<html> <body> <h2>knowledge2life</h2> <p>Message from my computer:</p> <p><samp>File not found.<br>Press F1 to continue</samp></p> </body> </html>

OUTPUT:

knowledge2life

Message from my computer:
File not found.
Press F1 to continue