Path // www.yourhtmlsource.comReference → <tt>

<tt>


The <tt> element (teletype text) was used to render text in a monospace (fixed-width) font, mimicking the appearance of old teletype machines or typewriters. It was a purely presentational element with no semantic meaning.

Clock This page was last updated on 2025-11-17



Deprecation Warning

This element is obsolete and should not be used. The <tt> element is not supported in HTML5. Use semantic elements that describe the meaning of the monospace text, or CSS for purely presentational purposes.

The <tt> element was problematic because it described only how text should look (monospace font) without conveying why. HTML5 provides semantic elements that explain the purpose of monospace text: <code> for code, <kbd> for keyboard input, <samp> for sample output, and <var> for variables.

Syntax

<tt>monospace text</tt>

The element required both opening and closing tags.

Modern Alternatives

Choose the appropriate semantic element based on the meaning of your monospace text:

For Computer Code: Use <code>

<p>Use the <code>console.log()</code> function for debugging.</p>

For Keyboard Input: Use <kbd>

<p>Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to copy.</p>

For Program Output: Use <samp>

<p>The program returned: <samp>Error 404: File not found</samp></p>

For Variables: Use <var>

<p>Set the value of <var>x</var> to 10.</p>

For Purely Visual Monospace: Use CSS

<!-- HTML -->
<span class="mono">monospace text</span>

<!-- CSS -->
.mono {
  font-family: monospace;
}

Migration Example

<!-- Old way (obsolete) -->
<p>Type <tt>npm install</tt> to install dependencies.</p>

<!-- New way (semantic) -->
<p>Type <kbd>npm install</kbd> to install dependencies.</p>

<!-- Or if showing code -->
<p>The command <code>npm install</code> installs dependencies.</p>

When to Avoid

Always avoid using <tt>. There is no valid use case for this element:

  • It is obsolete in HTML5 and not supported
  • It has no semantic meaning
  • It fails validation for HTML5 documents
  • Semantic alternatives exist for all common use cases
  • CSS provides precise control when no semantic meaning is intended

Always consider what the monospace text represents and choose the appropriate semantic element.

  • <code> - For inline code snippets
  • <kbd> - For keyboard input
  • <samp> - For sample output from programs
  • <var> - For variables in mathematical or programming context
  • <pre> - For preformatted text blocks