HTML 标签

HTML 标签

HTML5 标签集合

HTML 标签 - 图1

文档章节

<body> 页面内容<header> 文档头部<nav> 导航<aside> 侧边栏<article> 定义外部内容(如外部引用的文章)<section> 一个独立的块<footer> 尾部

页面通常结构

Web Structure

文本标签

  1. <!-- 默认超链接 -->
  2. <a href="http://sample-link.com" title="Sample Link">Sample</a>
  3. <!-- 当前窗口显示 -->
  4. <a href="http://sample-link.com" title="Sample Link" target="_self">Sample</a>
  5. <!-- 新窗口显示 -->
  6. <a href="http://sample-link.com" title="Sample Link" target="_blank">Sample</a>
  7. <!-- iframe 中打开链接 -->
  8. <a href="http://sample-link.com" title="Sample Link" target="iframe-name">Sample</a>
  9. <iframe name="iframe-name" frameborder="0"></iframe>
  10. <!-- 页面中的锚点 -->
  11. <a href="#achor">Achor Point</a>
  12. <section id="achor">Achor Content</section>
  13. <!-- 邮箱及电话需系统支持 -->
  14. <a href="mailto:sample-address@me.com" title="Email">Contact Us</a>
  15. <!-- 多个邮箱地址 -->
  16. <a href="mailto:sample-address@me.com, sample-address0@me.com" title="Email">Contact Us</a>
  17. <!-- 添加抄送,主题和内容 -->
  18. <a href="mailto:sample-address@me.com?cc=admin@me.com&subject=Help&body=sample-body-text" title="Email">Contact Us</a>
  19. <!-- 电话示例 -->
  20. <a href="tel:99999999" title="Phone">Ring Us</a>

组合内容标签

  • <div>
  • <p>
  • <ol>
  • <ul>
  • <dl>
  • <pre>
  • <blockquote>

文档章节

<body> 页面内容<header> 文档头部<nav> 导航<aside> 侧边栏<article> 定义外部内容(如外部引用的文章)<section> 一个独立的块<footer> 尾部

引用

  • <cite> 引用作品的名字、作者的名字等
  • <q> 引用一小段文字(大段文字引用用<blockquote>
  • <blockquote> 引用大块文字
  • <pre> 保存格式化的内容(其空格、换行等格式不会丢失)
  1. <pre>
  2. <code>
  3. int main(void) {
  4. printf('Hello, world!');
  5. return 0;
  6. }
  7. </code>
  8. </pre>

代码

<code> 引用代码

格式化

<b> 加粗<i> 斜体

强调

<em> 斜体。着重于强调内容,会改变语义的强调<strong> 粗体。着重于强调内容的重要性

换行

<br> 换行

列表

无序列表

  1. <ul>
  2. <li>标题</li>
  3. <li>结论</li>
  4. </ul>

有序列表

  1. <ol>
  2. <li>第一</li>
  3. <li>第二</li>
  4. </ol>

自定义列表

  1. <dl>
  2. <dt>作者</dt>
  3. <dd>爱因斯坦</dd>
  4. <dt>作品</dt>
  5. <dd>《相对论》</dd>
  6. <dd>《时间与空间》</dd>
  7. </dl>

一个<dt>可以对应多个<dd>

NOTE: <dl> 为自定义列表,其中包含一个或多个 <dt> 及 一个或多个 <dd>,并且dtdl列表会有缩进的效果。<pre> 会保留换行和空格,通常与 <code> 一同使用。

  1. <pre>
  2. <code>
  3. int main(void) {
  4. printf('Hello, world!');
  5. return 0;
  6. }
  7. </code>
  8. </pre>

<blockquote> 拥有 cite 属性,它包含引用文本的出处,示例如下所示:

  1. <blockquote cite="http://example.com/facts">
  2. <p>Sample Quote...</p>
  3. </blockquote>

嵌入

  1. <iframe src=""></iframe> 页面操作可以不影响到iframe的内容
  2. <!--object embed通常用来嵌入外部资源 -->
  3. <object type="application/x-shockwave-player">
  4. <param name="movie" value="book.pdf">
  5. </object>
  6. <!--视频 track可以引入字幕 autoplay可以使视频加载后自动播放,loop可以使其循环播放 -->
  7. <video autoplay loop controls="controls" poster="poster.jpg">
  8. <source src="movie.mp4" type="video/mp4">
  9. <source src="movie.webm" type="video/webm">
  10. <source src="movie.ogg" type="video/ogg">
  11. <track kind="subtitles" src="video.vtt" srclang="cn" label="cn">
  12. </video>

资源标签

图标签

canvas 基于像素,性能要求比较高,可用于实时数据展示。svg 为矢量图形图像。

热点区域标签

img中套用map以及area可以实现点击某部分图片触发一个链接,点击另一部分触发另一个链接

  1. <img src="mama.jpg" width=100 height=100 usemap="#map" />
  2. <map name="map">
  3. <area shap="rect" coords="0,0,50,50" href="" alt="">
  4. <area shap="circle" coords="75,75,25" href="" alt="">
  5. </map>

表格

表格代码示例

  1. <table>
  2. <caption>table title and/or explanatory text</caption>
  3. <thead>
  4. <tr>
  5. <th>header</th>
  6. </tr>
  7. </thead>
  8. <tbody>
  9. <tr>
  10. <td>data</td>
  11. </tr>
  12. </tbody>
  13. </table>

使用 colspan=val 进行跨列,使用 rowspan=val 进行跨行。

表单

  1. <form action="WebCreation_submit" method="get" accept-charset="utf-8">
  2. <fieldset>
  3. <legend>title or explanatory caption</legend>
  4. <!-- 第一种添加标签的方法 -->
  5. <label><input type="text/submit/hidden/button/etc" name="" value=""></label>
  6. <!-- 第二种添加标签的方法 -->
  7. <label for="input-id">Sample Label</label>
  8. <input type="text" id="input-id">
  9. </fieldset>
  10. <fieldset>
  11. <legend>title or explanatory caption</legend>
  12. <!-- 只读文本框 -->
  13. <input type="text" readonly>
  14. <!-- 隐藏文本框,可提交影藏数据 -->
  15. <input type="text" name="hidden-info" value="hiden-info-value" hidden>
  16. </fieldset>
  17. <button type="submit">Submit</button>
  18. <button type="reset">Reset</button>
  19. </form>

使用fieldset可用于对表单进行分区

表单中的其他控件类型:

  • textarea (文本框)
  • selectoption (下拉菜单可多选)
    input 类型支持值列表
    ValueDescription
    buttonDefines a clickable button (mostly used with a JavaScript to activate a script)
    checkboxDefines a checkbox
    HTML 标签 - 图3colorDefines a color picker
    HTML 标签 - 图4dateDefines a date control (year, month and day (no time))
    HTML 标签 - 图5datetimeThe input type datetime has been removed from the HTML standard. Use datetime-local instead.
    HTML 标签 - 图6datetime-localDefines a date and time control (year, month, day, hour, minute, second, and fraction of a second (no time zone)
    HTML 标签 - 图7emailDefines a field for an e-mail address
    fileDefines a file-select field and a “Browse…” button (for file uploads)
    hiddenDefines a hidden input field
    imageDefines an image as the submit button
    HTML 标签 - 图8monthDefines a month and year control (no time zone)
    HTML 标签 - 图9numberDefines a field for entering a number
    passwordDefines a password field (characters are masked)
    radioDefines a radio button
    HTML 标签 - 图10rangeDefines a control for entering a number whose exact value is not important (like a slider control)
    resetDefines a reset button (resets all form values to default values)
    HTML 标签 - 图11searchDefines a text field for entering a search string
    submitDefines a submit button
    HTML 标签 - 图12telDefines a field for entering a telephone number
    textDefault. Defines a single-line text field (default width is 20 characters)
    HTML 标签 - 图13timeDefines a control for entering a time (no time zone)
    HTML 标签 - 图14urlDefines a field for entering a URL
    HTML 标签 - 图15weekDefines a week and year control (no time zone)

语义化

语义化(Semantic Tag)是指用合适的标签标识适当的内容,它可以起到搜索引擎优化(Search Engine Optimization),提高可访问性(例如盲人使用的屏幕阅读器),与此同时还可以提高代码的可读性。简而言之也就是在正确的地方使用正确的标签