W3docs

HTML <tt> Tag

HTML <tt> tag defines monospace text. This tag is obsolete, see what tags or CSS properties you can use instead.

The <tt> tag creates an inline text which is displayed in monospace or fixed-width font as it would appear on a teletype or typewriter.

The terms monotype, monospace, and non-proportional have the same meaning. They are used interchangeably and describe a typeface the characters of which are the same number of pixels wide.

Danger

The <tt> is a deprecated HTML tag in HTML5.

Instead of the <tt> tag use CSS font-family property or appropriate HTML elements: the <kbd> tag for keyboard input, the <var> tag for variables, the <code> tag for computer code, and the <samp> tag for computer output, the <pre> tag for line breaks and indentation.

Syntax

The <tt> tag comes in pairs. The content is written between the opening (<tt>) and closing (</tt> ) tags.

Example of the HTML <tt> tag:

HTML <tt> Tag

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p>This is an ordinary text.</p>
    <p><tt>And this is a teletype text.</tt></p>
  </body>
</html>

Result

tt tag example

Example of the CSS font-family used instead of the HTML <tt> tag:

Example with css

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <p>This is an ordinary text.</p>
    <p style="font-family: monospace">And this is a teletype text.</p>
  </body>
</html>

Attributes

The <tt> tag supports the Global Attributes.

How to style an HTML <tt> tag

{
    "tag_name": "tt"
}

Practice

Practice

What is the primary use of the HTML <tt> tag and what replaces this element in HTML5?