过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

过时 HTML Teletype Text element ( <tt> ) creates inline text which is presented using the user agent's default monospace font face. This element was created for the purpose of rendering text as it would be displayed on a fixed-width display such as a teletype, text-only screen, or line printer.

The terms non-proportional , monotype ,和 monospace are used interchangeably and have the same general meaning: they describe a typeface whose characters are all the same number of pixels wide.

This element is obsolete, however. You should use the more semantically helpful <code> , <kbd> , <samp> ,或 <var> elements for inline text that needs to be presented in monospace type, or the <pre> tag for content that should be presented as a separate block.

If none of the semantic elements are appropriate for your use case (for example, if you simply need to show some content in a non-proportional font), you should consider using the <span> element, styling it as desired using CSS. The font-family property is a good place to start.

内容类别 流内容 , 措词内容 ,可触及内容。
准许内容 措词内容 .
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts 措词内容 .
Permitted ARIA roles 任何
DOM 接口 HTMLElement

属性

此元素只包括 全局属性

范例

基本范例

此范例使用 <tt> to show text entered into, and output by, a terminal application.

<p>Enter the following at the telnet command prompt: <code>set localecho</code><br />
The telnet client should display: <tt>Local Echo is on</tt></p>
				

结果

Overriding the default font

You can override the browser's default font—if the browser permits you to do so, which it isn't required to do—using CSS:

CSS

tt {
  font-family: "Lucida Console", "Menlo", "Monaco", "Courier",
               monospace;
}
				

HTML

<p>Enter the following at the telnet command prompt: <code>set localecho</code><br />
The telnet client should display: <tt>Local Echo is on</tt></p>
				

结果

用法注意事项

<tt> element is, by default, rendered using the browser's default non-proportional font. You can override this using CSS by creating a rule using the tt selector, as seen in the example Overriding the default font above.

User-configured changes to the default monospace font setting may take precedence over your CSS.

Although this element wasn't officially deprecated in HTML 4.01, its use was discouraged in favor of the semantic elements and/or CSS. The <tt> element is obsolete in HTML 5.

规范

规范 状态 注释
HTML5
The definition of '<tt>' in that specification.
推荐
HTML 4.01 Specification
The definition of '<tt>' in that specification.
推荐

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
tt 弃用 Chrome 完整支持 Yes Edge 完整支持 12 Firefox 完整支持 Yes 注意事项
完整支持 Yes 注意事项
注意事项 Before Firefox 4, this element implemented the HTMLSpanElement interface instead of the standard HTMLElement 接口。
IE 完整支持 Yes Opera 完整支持 Yes Safari 完整支持 Yes WebView Android 完整支持 Yes Chrome Android 完整支持 Yes Firefox Android 完整支持 Yes 注意事项
完整支持 Yes 注意事项
注意事项 Before Firefox 4, this element implemented the HTMLSpanElement interface instead of the standard HTMLElement 接口。
Opera Android 完整支持 Yes Safari iOS 完整支持 Yes Samsung Internet Android 完整支持 Yes

图例

完整支持

完整支持

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

见实现注意事项。

另请参阅

元数据

  • 最后修改: