-
Hajipur, Bihar, 844101
HTML provides several tags to display computer-related content such as code snippets, keyboard input, and program output. These tags help preserve formatting and convey technical meaning clearly.
Tag | Purpose |
---|---|
<code> |
Displays code in a monospace font |
<kbd> |
Indicates keyboard input |
<samp> |
Represents sample output from a program |
<var> |
Displays a variable in programming context |
<pre> |
Preserves formatting and whitespace |
<code>
– Code SnippetDisplays code in monospace font (does not preserve whitespace).
<p>This is <code>console.log("Hello")</code> in JavaScript.</p>
<pre>
– Preformatted TextPreserves spaces, line breaks, and tabs as they appear.
<pre>
function hello() {
console.log("Hello World");
}
</pre>
<kbd>
– Keyboard InputRepresents input from the user via keyboard.
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy text.</p>
<samp>
– Sample OutputUsed to show the output of a program or command.
<p>Output: <samp>Hello, user!</samp></p>
<var>
– VariableRepresents a variable in code, usually styled in italic by default.
<p>The value of <var>x</var> is 10.</p>
<pre>
<code>
let x = 10;
let y = 20;
console.log(x + y);
</code>
</pre>
<p>Type <kbd>Alt</kbd> + <kbd>F4</kbd> to close the window.</p>
<p>Sample Output: <samp>30</samp></p>
<p>Here, <var>sum</var> stores the result.</p>
Q1. Write a JavaScript function using <pre>
and <code>
tags.
Q2. Use <kbd>
to show keyboard shortcuts for copying text.
Q3. Display a sample output using the <samp>
tag.
Q4. Highlight the variable total
using the <var>
tag.
Q5. Show a command-line snippet using <code>
inside <pre>
.
Q6. Create a layout showing input (with <kbd>
) and output (with <samp>
).
Q7. Nest <code>
inside <pre>
for correct formatting.
Q8. Use <kbd>
to show a shortcut to refresh a page.
Q9. Display a Python print()
statement using <code>
.
Q10. Highlight multiple variables in a paragraph using <var>
.
Q1: Which tag is used to display code snippets?
Q2: What does the <pre> tag do?
Q3: Which tag is used to show keyboard input?
Q4: Which tag is used for program output?
Q5: What is the purpose of the <var> tag?
Q6: Which of the following tags renders in a monospace font?
Q7: Can <kbd> and <samp> be used together?
Q8: What is the default style for <var> in browsers?
Q9: Which tag pair is best for displaying formatted code with line breaks?
Q10: Which tag is not a computercode tag?