👀 Live Preview
Comparison of normal text vs teletype text (browsers still render <tt> for compatibility):
Normal: This is regular paragraph text.
Monospaced: This text uses a teletype font.

By the end of this tutorial, you’ll understand legacy teletype markup, when developers used it, and the modern HTML elements that replace it.
How <tt> rendered monospaced teletype text.
Why HTML5 removed <tt> from the specification.
Compare presentational teletype with semantic code markup.
Use code, kbd, samp, and pre instead.
Inline code snippets and command-line examples.
Recognize tt in old tutorials and migrate to modern tags.
<tt> Tag?The <tt> element was an inline HTML tag that displayed enclosed text in a teletype or monospaced font. Every character occupied the same width, which made it useful for code snippets, terminal commands, and technical documentation.
code InsteadDo not use <tt> in new projects. Use <code> for inline code, <kbd> for keyboard input, <samp> for program output, and CSS font-family: monospace when you only need visual styling. Browsers still render tt for backward compatibility only.
HTML5 moved presentational formatting to semantic elements and stylesheets. Learn <tt> to read legacy HTML, but mark up code with <code> in all new work.
<p>Run <code>print("Hello")</code> to greet the user.</p>Wrap text between opening and closing <tt> tags:
<tt>Your Text Here</tt><tt> is an inline element—it nests inside paragraphs and lists.<tt />) is not valid in HTML.| Use Case | Legacy (tt) | Modern Replacement |
|---|---|---|
| Inline code snippet | <tt>print()</tt> | <code>print()</code> |
| Keyboard shortcut | <tt>Ctrl+C</tt> | <kbd>Ctrl+C</kbd> |
| Program output | <tt>Hello</tt> | <samp>Hello</samp> |
| Multi-line code block | Multiple tt tags (poor practice) | <pre><code>...</code></pre> |
| Styled monospace only | <tt style="..."> | CSS font-family: monospace on span or code |
<tt> vs <code> vs <kbd> vs <samp>These elements can look similar, but only the modern tags carry semantic meaning in HTML5:
| Element | Purpose | HTML5 status |
|---|---|---|
<tt> | Monospaced teletype text (presentation only) | Obsolete — use code |
<code> | Inline code fragment or file name | Valid — preferred for code snippets |
<kbd> | User keyboard input | Valid — for shortcuts and keys |
<samp> | Sample or program output | Valid — for terminal or app output |
<pre> | Preformatted multi-line block | Valid — pair with code for blocks |
The <tt> tag had no tag-specific attributes. Global attributes and inline style could be applied, but modern semantic elements are the proper approach today:
class / id GlobalHook for CSS selectors—prefer a class on code instead of tt.
<code class="mono">style InlineInline font-family worked but external CSS is cleaner.
style="font-family: monospace;"The entire <tt> element is obsolete. Use code, kbd, samp, or CSS in new projects.
Historical <tt> patterns plus the modern <code> replacement. Legacy examples render for compatibility only—do not use in new code.
Comparison of normal text vs teletype text (browsers still render <tt> for compatibility):
Normal: This is regular paragraph text.
Monospaced: This text uses a teletype font.
Apply a specific monospace font with the inline style attribute on <tt>.
<p>This is an example of the <tt>tt</tt> tag:</p>
<tt style="font-family: 'Courier New', monospace;">Your Styled Text Here</tt>Developers once used <tt> for inline code and terminal commands. Today use semantic elements instead.
Embed a short code snippet inside a sentence while keeping fixed-width spacing.
<p>
In this example, we use the <tt>print("Hello, World!")</tt> statement to display a message.
</p>Show a shell command with monospace spacing—a common pattern in technical docs.
<p>Using the <tt> tag:</p>
<tt>$ cd /path/to/directory</tt>code ReplacementThis is what beginners should use today. The <code> element conveys semantic meaning and is styled with CSS.
<p>
Run <code>print("Hello, World!")</code> to display a message.
</p>
<p>
Then type <kbd>Enter</kbd> to execute.
</p>For readable, accessible code and technical text:
code, kbd, and samp communicate purpose to assistive technology<pre><code> for screen reader clarityMark words that should appear in a fixed-width teletype font.
Default user-agent styles rendered the text in a teletype or monospaced typeface.
HTML5 introduced code, kbd, and samp for meaningful technical text.
codeLearn tt for history. Mark up code with code in all new projects.
Browsers still render <tt> with monospace styling for backward compatibility, but the element is obsolete and not part of HTML5.
codeAll major browsers still apply default monospace styles to <tt> for old pages, but the tag is removed from the HTML5 specification. Never use it in new projects.
Bottom line: Browsers render old tt markup, but the element is obsolete—use code for new work.
The <tt> tag was a useful tool for displaying monospaced teletype text in early HTML, but HTML5 replaced it with semantic elements like <code>, <kbd>, and <samp>. Understanding its history helps you read legacy pages and migrate them to modern, accessible markup.
<code> for inline code fragments<kbd> for keyboard shortcuts and typed input<pre><code> for multi-line code blockstt when maintaining legacy HTML<tt> in new HTML5 projectstt for semantic code meaningtt, font, center)code when the content is actual source code<tt>Bookmark these before you mark up your next code snippet.
<tt> rendered monospaced teletype text inline.
Removed from the spec—do not use in new projects.
Essential<code> is the modern inline code element.
Keyboard input and program output have their own tags.
SemanticsBrowsers still render tt for backward compatibility.
<tt> element displayed text in a teletype or monospaced font. Developers used it for inline code snippets, command-line input, and any text where fixed character width mattered.tt tag is obsolete and removed from the HTML5 specification. Browsers still render it with monospace styling for backward compatibility.<code> for inline code, <kbd> for keyboard input, <samp> for program output, and <pre> for multi-line blocks.code is the modern semantic element for code fragments. tt only changed presentation and is obsolete.code for inline snippets and pre for blocks. Learn tt only to recognize it in legacy tutorials.tt in legacy pages. In new projects, apply font-family: monospace to code or a CSS class instead.Practice legacy <tt> examples, then switch to <code> for real projects.
5 people found this page helpful