title
global attribute
contains text representing advisory information related to the element it belongs to.
Some typical uses:
<iframe>
elements for assistive technology
<input>
element as a fallback for a real
<label>
Additional semantics are attached to the
title
属性对于
<link>
,
<abbr>
,
<input>
,和
<menuitem>
元素。
title
attribute may contain several lines. Each
U+000A LINE FEED
(
LF
) character represents a line break. Some caution must be taken, as this means the following renders across two lines:
<p>Newlines in <code>title</code> should be taken into account, like <abbr title="This is a multiline title">example</abbr>.</p>
If an element has no
title
attribute, then it inherits it from its parent node, which in turn may inherit it from its parent, and so on.
If this attribute is set to the empty string, it means its ancestors'
title
s are irrelevant and shouldn't be used in the tooltip for this element.
<div title="CoolTip"> <p>Hovering here will show “CoolTip”.</p> <p title="">Hovering here will show nothing.</p> </div>
Use of the
title
attribute is highly problematic for:
This is due to inconsistent browser support, compounded by the additional assistive technology parsing of the browser-rendered page. If a tooltip effect is desired, it is better to use a more accessible technique that can be accessed with the above browsing methods.
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'title' in that specification. |
实时标准 | No change from latest snapshot, HTML 5.1 |
|
HTML 5.1
The definition of 'title' in that specification. |
推荐 | 快照 HTML 实时标准 , no change from HTML5 |
|
HTML5
The definition of 'title' in that specification. |
推荐 | 快照 HTML 实时标准 . From HTML 4.01 Specification , it is now a true global attribute. |
|
HTML 4.01 Specification
The definition of 'title' in that specification. |
推荐 |
Supported on all elements but
<base>
,
<basefont>
,
<head>
,
<html>
,
<meta>
,
<param>
,
<script>
,和
<title>
.
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
title
|
Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android 完整支持 Yes | Safari iOS 完整支持 Yes | Samsung Internet Android 完整支持 Yes |
| Multi-line support | Chrome 完整支持 Yes | Edge 完整支持 12 | Firefox 完整支持 Yes | IE 完整支持 Yes | Opera 完整支持 Yes | Safari 完整支持 Yes | WebView Android 完整支持 Yes | Chrome Android 完整支持 Yes | Firefox Android 完整支持 Yes | Opera Android ? | Safari iOS ? | Samsung Internet Android 完整支持 Yes |
完整支持
兼容性未知
HTMLElement.title
that reflects this attribute.
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<article>
<aside>
<audio>
<b>
<base>
<basefont>
<bdi>
<bdo>
<bgsound>
<big>
<blink>
<blockquote>
<body>
<br>
<button>
<canvas>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<command>
<content>
<data>
<datalist>
<dd>
<del>
<details>
<dfn>
<dialog>
<dir>
<div>
<dl>
<dt>
<element>
<em>
<embed>
<fieldset>
<figcaption>
<figure>
<font>
<footer>
<form>
<frame>
<frameset>
<h1>
<head>
<header>
<hgroup>
<hr>
<html>
<i>
<iframe>
<image>
<img>
<input>
<ins>
<isindex>
<kbd>
<keygen>
<label>
<legend>
<li>
<link>
<listing>
<main>
<map>
<mark>
<marquee>
<menu>
<menuitem>
<meta>
<meter>
<multicol>
<nav>
<nextid>
<nobr>
<noembed>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<picture>
<plaintext>
<pre>
<progress>
<q>
<rb>
<rp>
<rt>
<rtc>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<shadow>
<slot>
<small>
<source>
<spacer>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<template>
<textarea>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
<xmp>
<input>
类型
<input type="button">
<input type="checkbox">
<input type="color">
<input type="date">
<input type="datetime">
<input type="datetime-local">
<input type="email">
<input type="file">
<input type="hidden">
<input type="image">
<input type="month">
<input type="number">
<input type="password">
<input type="radio">
<input type="range">
<input type="reset">
<input type="search">
<input type="submit">
<input type="tel">
<input type="text">
<input type="time">
<input type="url">
<input type="week">