Description
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.
The below table summarizes its usage.
Usage Details | |
Placement | It is displayed as an Inline element. |
Contents | It can contain Inline elements and text. |
Tags | Both the opening and closing tags are required. |
Versions | HTML 2, 3.2, 4, 4.01 This element is deprecated in HTML 4.01 and obsolete since HTML5, so avoid using this element in your markup. Instead, use the <code>, <samp>, <var>, <kbd> elements, or CSS font properties. |
Syntax
Here is the basic syntax of the <tt>
element.
<tt>...</tt>
Examples
<!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>
Attributes
The following table shows the list of supported and unsupported attributes for the <tt>
element.
Attribute Type | Details |
Element-Specific Attributes | The tag <tt> doesn't have any element-specific attributes. |
Global Attributes | Like all other HTML tags, the tag <tt> supports the HTML Global Attributes. |
Event Attributes | The tag <tt> also supports the HTML Event Attributes. |
Browser Compatibility
The tag <tt>
is supported in all modern browsers.
- Google Chrome 1+
- Internet Explorer or Edge 2+
- Firefox 1+
- Apple Safari 1+
- Opera 2.1+