HTML <tt> Tag

Beginner
5 min read
Updated: Nov 2026
4 examples
Deprecated

Definition and Usage

The <tt> (teletype) element once showed inline monospace text, like a fixed-width terminal or line printer. It was presentational only.

Learn it only to recognize legacy pages. For new work, pick a semantic element — <code>, <kbd>, <samp>, <var> — or a block with <pre>. If you only need the look, style with CSS font-family (MDN).

Deprecated / Obsolete.

Do not use <tt> in new HTML. MDN: avoid this feature; it is obsolete in HTML5.

Still rendered in many browsers.

Legacy support exists for old documents, but that is not permission to ship new <tt> markup.

HTML Syntax

syntax.html
<tt> monospace text</tt>

Modern equivalents: <code>…</code>, <kbd>…</kbd>, <samp>…</samp>, or <span style="font-family: monospace">…</span> (prefer a stylesheet class over inline style).

Attributes

<tt> had no element-specific attributes — only globals. Choose a modern replacement by meaning:

Use todayDescriptionTry it
<code>Computer source code (best default for many old tt cases)Try it
<kbd> / <samp>User input vs sample program outputTry it
<var> / <pre>Variables; multi-line preformatted blocksSee related
CSS monospaceLook only, no better semantics — style with font-familyTry it
Legacy <tt>Study only — do not author in new pagesTry it

Global Attributes

The <tt> tag also supports the Global Attributes in HTML (legacy recognition only — do not author new tt markup).

Live Preview

Compare legacy <tt> with modern code / samp replacements. Prefer modern markup for real pages.

markup style

Study only. New pages should use semantic monospace elements or CSS — not <tt>.

Preview

The client should display: Local Echo is on

Using deprecated <tt> — migrate to code / samp / CSS.

HTML Examples

Short snippets for study and migration. Use Try It Yourself for a live editor.

Example 1 — Legacy tt (Study Only)

Recognize old teletype markup. Do not copy this into new projects.

HTML
<!-- Deprecated — for study only -->
<p>
  The telnet client should display:
  <tt>Local Echo is on</tt>
</p>
Try It Yourself

How It Works

  1. Spot the tag name. <tt> wraps the monospace phrase.
  2. Default look: the browser’s monospace font.
  3. Treat as legacy. Valid for understanding old pages, not for new HTML.
  4. Plan a replacement based on meaning (code, samp, etc.).

Example 2 — Prefer code

For computer source or command names, use the semantic code element.

HTML
<p>
  Enter the following at the prompt:
  <code>set localecho</code>
</p>
Try It Yourself

How It Works

  1. Replace <tt> with <code> when the text is source or a command name.
  2. Keep the same visible text inside the tags.
  3. Default look is still usually monospace.
  4. Meaning improves: assistive tech and tools understand “code,” not just “teletype.”

Example 3 — Terminal: kbd + samp

Separate what the user typed from what the program printed.

HTML
<p>
  Type <kbd>set localecho</kbd>.
  The client should display
  <samp>Local Echo is on</samp>.
</p>
Try It Yourself

How It Works

  1. Wrap user input in <kbd>.
  2. Wrap sample output in <samp>.
  3. Do not use one tt for both roles.
  4. Optional: put longer sessions in <pre>.

Example 4 — CSS Monospace (No Semantics)

When no semantic tag fits, style a normal element with monospace — not tt.

HTML
<style>
  .mono {
    font-family: ui-monospace, monospace;
  }
</style>

<p>
  Fixed-width look only:
  <span class="mono">ABC 123</span>
</p>
Try It Yourself

How It Works

  1. Ask first: is this code, input, output, or a variable?
  2. If yes, use code / kbd / samp / var.
  3. If only the font matters, add a class and set font-family: monospace.
  4. Skip tt entirely in new documents.

Edge Cases & Pitfalls

The main risk is treating browser monospace rendering as permission to keep shipping tt.

deprecated

Do not use in new HTML

Validators flag <tt>. Author semantic tags or CSS instead.

semantics

Pick the right replacement

code ≠ kbd ≠ samp. Match meaning, not only the font.

CSS selectors

Update stylesheets when migrating

Rules targeting tt will miss code / samp until you change the selector.

fonts

User monospace preferences may win

MDN notes user-configured monospace fonts can override your CSS on teletype-style text.

blocks

Multi-line needs pre

tt was inline. For preserved line breaks, use <pre> (often with code or samp).

Browser Support

<tt> is a deprecated HTML element. Prefer semantic monospace tags or CSS in every modern document.

✓ Deprecated · Legacy rendering

<tt>

Still displayed as monospace in most browsers for old content, but obsolete for authors. Use code, kbd, samp, var, pre, or CSS instead.

Legacy Author guidance
Google Chrome Renders (legacy)
Deprecated
Mozilla Firefox Renders (legacy)
Deprecated
Apple Safari Renders (legacy)
Deprecated
Microsoft Edge Renders (legacy)
Deprecated
Opera Renders (legacy)
Deprecated
Samsung Internet Renders (legacy)
Deprecated
Internet Explorer Supported (legacy)
Deprecated
<tt> Do not use in new pages

Bottom line: Rendering support is not a green light. Migrate to semantic monospace elements or CSS and treat tt as archive knowledge.

Key Takeaways

One line: recognize <tt>, replace it with semantic monospace tags or CSS.

Default CSS Settings

Typical user-agent styling for tt (and common modern replacements):

default.css
tt {
  font-family: monospace;
}

/* Prefer these in modern stylesheets */
code, kbd, samp {
  font-family: monospace;
}

Prefer styling code / kbd / samp. Leave tt rules only while cleaning legacy CSS.

Frequently Asked Questions

Historically, tt (teletype) showed inline text in the browser’s default monospace font, like a fixed-width terminal. It is obsolete in HTML5 and should not be used in new pages.
No for authors. MDN marks tt Deprecated; HTML5 lists it as obsolete. Browsers may still render it for old content, but new markup should use semantic elements or CSS.
Prefer code for source, kbd for user input, samp for sample output, var for variables, or pre for multi-line blocks. If you only need monospace look with no better semantics, use a span (or similar) styled with font-family: monospace.
No. Only global attributes. Apply class or style on modern replacements instead.
Usually not visually — many browsers still show monospace for tt. Treat that as legacy recognition, not permission to keep shipping tt.
It was presentational only. HTML prefers semantic monospace elements (code, kbd, samp, var) or CSS for pure styling.

Use code instead

Mark computer code with the supported HTML element.

code tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful