← 返回完整题库
HTML简单

常用的 meta 元素有哪些?

参考答案

meta 是空元素,放在 <head>,用于声明文档元信息。按用途分组:

字符集与视口(必写)

  • <meta charset="utf-8">:必须在前 1024 字节内,越靠前越好;
  • <meta name="viewport" content="width=device-width, initial-scale=1">:移动端适配基础。

SEO 与搜索引擎

  • <meta name="description" content="...">:搜索结果摘要(约 150-160 字符);
  • <meta name="keywords" content="...">:已基本不被主流引擎重视,可留可删;
  • <meta name="robots" content="index,follow">(noindex/nofollow/noarchive/max-image-preview:large);
  • <meta name="googlebot" content="...">:针对特定爬虫;
  • <link rel="canonical"> 不是 meta 但常一起配置,用于去重。

社交分享

  • Open Graph:<meta property="og:title">、og:description、og:image、og:url、og:type、og:site_name;
  • Twitter:<meta name="twitter:card" content="summary_large_image">、twitter:title、twitter:image。

浏览器/系统行为

  • <meta http-equiv="X-UA-Compatible" content="IE=edge">:让 IE 用最新内核(历史兼容用);
  • <meta name="theme-color" content="#ffffff">:移动端地址栏/状态栏配色;
  • <meta name="format-detection" content="telephone=no">:禁止自动识别电话号码;
  • <meta name="referrer" content="no-referrer">(或 strict-origin-when-cross-origin):Referer 策略;
  • <meta http-equiv="refresh" content="5;url=/next">:定时刷新/跳转(不推荐用于正式跳转);
  • <meta http-equiv="Content-Security-Policy" content="...">:CSP(现多用响应头);
  • <meta http-equiv="Content-Type" content="text/html; charset=utf-8">:老写法,已被 charset 取代。

移动端(PWA/苹果)

  • <meta name="apple-mobile-web-app-capable" content="yes">(新标准为 mobile-web-app-capable);
  • <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">;
  • <meta name="apple-mobile-web-app-title" content="...">;
  • <meta name="application-name" content="...">;
  • <link rel="manifest"> 配合 PWA。

其他

author、copyright、generator、rating、distribution、HandheldFriendly(历史)。

注意

  • name 与 http-equiv 二选一,property 主要用于 OG;
  • 编码相关一定要早于任何非 ASCII 内容;
  • 现代项目用框架的 head 管理(next/head、@vueuse/head)按路由动态注入;
  • 过期/无用的 meta(keywords、X-UA-Compatible 在非 IE 场景)可精简。

本题来自 计算机知识面试题库,共 921 道题。