HTML Element <tt> Example

The HTML element <tt> is used to specify a text in teletype or monospaced style.

The word tt stands for teletype text, which is used to be the text format in early computers, where each character took the same width.

It is used just to format a text and doesn't provide any semantic information to the browsers like <b> and <i> elements.

This element is not supported in HTML5 and you should avoid using it in the markup. Instead, use the below elements or CSS font properties.

  • Element <code> for computer code.
  • Element <samp> for computer output.
  • Element <var> for variables.
  • Element <kbd> for keyboard inputs.

Here is an example that explains the element in action. Click the below link to see the live demo.

Run this on IDE

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Example - HTML Element tt</title>
</head>
<body>
    <!-- Sample code defined using the element "tt" which is not supported in HTML5, so avoid using it in your markup -->
    <p>This paragraph contains a <tt>sample code</tt> using the "tt" element</p>
    <!-- Alternative approach using the "code" element, which is supported in HTML5 -->
    <p>This paragraph contains a <code>sample code</code> using the "code" element.</p>
</body>
</html>

Related Links