search
HomeWeb Front-endHTML TutorialWhat are the uses of the HTML head tag?

This time I will show you how to use the HTML head tag. What are the precautions when using the HTML head tag? The following is a practical case, let's take a look.

HTML head There are many tags and elements in the head part, which involve the browser's rendering of web pages, SEO, etc. Each browser kernel and each domestic browser manufacturer have their own tag elements. This is caused a lot of differences. In the era of mobile Internet, the head structure and meta elements of mobile terminals are even more important. Understanding the meaning of each tag and writing a head tag that meets your own needs is the purpose of this article. This article is based on Yishi's article and provides an expanded summary to introduce the meaning and usage scenarios of each tag and element in commonly used heads.
DOCTYPE
DOCTYPE(Document Type), this declaration is located at the forefront of the document, before the html tag. This tag tells the browser which HTML or XHTML specification the document uses.
DTD (Document Type Definition) declaration starts with , is not case-sensitive, and has no content in front. If there is other content (except spaces), the browser will turn on quirks mode under IE. Render the web page. Public DTD, the name format is registration // organization // type tag // language, registration refers to whether the organization is registered by the International Organization for Standardization (ISO), + means yes, - means no. Organization is the name of the organization, such as: W3C. The type is usually DTD. A tag specifies a description of the public text, that is, a unique descriptive name for the referenced public text, which can be followed by a version number. The final language is the ISO 639 language identifier of the DTD language, such as: EN for English, ZH for Chinese. XHTML 1.0 can declare three DTD types. Represents strict version, transitional version, and frame-based HTML document respectively.

●HTML 4.01 strict

XML/HTML Code copy content to clipboard

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

●HTML 4.01 Transitional

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

● HTML 4.01 Frameset

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

●The latest HTML5 introduces more concise writing. It is forward and backward compatible and is recommended for use.

<!doctype html>

In HTML doctype has two main purposes.

●Verify the validity of documents.

It tells the user agent and validator what DTD this document is written according to. This action is passive. Every time the page is loaded, the browser does not download the DTD and check the validity. It is only enabled when the page is manually verified.

●Determine the browser's rendering mode

For actual operations, inform the browser which parsing algorithm to use when reading the document. If it is not written, the browser will parse the code according to its own rules, which may seriously affect the html layout. Browsers have three ways to parse HTML documents.

●Non-weird (standard) mode
●Weird mode
●Partially weird (nearly standard) mode About the document mode, browser mode, and strict mode of IE browser , weird mode, DOCTYPE tag, verbose mode? standard! Content.

charset

Declares the character encoding used in the document,

<meta charset="utf-8">

html5 The previous web page would write like this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

These two are equivalent, For details, you can read: <meta charset="utf-8"> vs , so it is recommended to use a shorter one, which is easier to remember.

lang attribute

Simplified Chinese

<html lang="zh-cmn-Hans">

Traditional Chinese

<html lang="zh-cmn-Hant">

Why not what we usually write, please read: The header of the page The statement should be made using or.

Prioritize using the latest version of IE and Chrome

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

360 Use Google Chrome Frame

<meta name="renderer" content="webkit">

360 The browser will immediately switch to the corresponding speed after reading this tag nuclear. In addition, add

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">

for the sake of insurance. The effect that can be achieved by writing this way is that if Google Chrome Frame is installed, GCF will be used to render the page. If GCF is not installed, the highest version of the IE kernel will be used for rendering.

Related links: Browser kernel control Meta tag documentation

Baidu prohibits transcoding

When you open a webpage through Baidu mobile phone, Baidu may transcode your webpage , take off your clothes, and put an advertisement of dog skin plaster on your body. For this purpose, you can add

<meta http-equiv="Cache-Control" content="no-siteapp" />

in the head. Related links: SiteApp transcoding statement

SEO optimization part

Page title

tag (head header is required) <pre class='brush:php;toolbar:false;'><title>your title</title></pre><p>Page keywordskeywords </p><pre class='brush:php;toolbar:false;'><meta name="keywords" content="your keywords"></pre><p>Page description content description </p><pre class='brush:php;toolbar:false;'><meta name="description" content="your description"></pre><p>Definition of web page author author </p><pre class='brush:php;toolbar:false;'><meta name="author" content="author,email address"></pre><p> Define the web search engine indexing method. Robotterms is a set of values ​​separated by English commas ",". It usually has the following values: none, noindex, nofollow, all, index and follow. <br></p><pre class='brush:php;toolbar:false;'><meta name="robots" content="index,follow"></pre><p>Related links: WEB1038 - Tag contains invalid value <br><br><a href="http://www.php.cn/css/css-rwd-viewport.html" target="_blank">viewport</a><br></p> <p>  viewport 可以让布局在移动浏览器上显示的更好。 通常会写</p><pre class='brush:php;toolbar:false;'><meta name="viewport" content="width=device-width, initial-scale=1.0"></pre><p>width=device-width 会导致 iPhone 5 添加到主屏后以 WebApp 全屏模式打开页面时出现黑边(http://bigc.at/ios-webapp-viewport-meta.orz)<br></p> <p>content 参数:</p> <p>width viewport 宽度(数值/device-width)<br>height viewport 高度(数值/device-height)<br>initial-scale 初始缩放比例<br>maximum-scale 最大缩放比例<br>minimum-scale 最小缩放比例<br>user-scalable 是否允许用户缩放(yes/no)<br>minimal-ui iOS 7.1 beta 2 中新增属性,可以在页面加载时最小化上下状态栏。这是一个布尔值,可以直接这样写:</p><pre class='brush:php;toolbar:false;'><meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui"></pre><p>而如果你的网站不是响应式的,请不要使用 initial-scale 或者禁用缩放。</p><pre class='brush:php;toolbar:false;'><meta name="viewport" content="width=device-width,user-scalable=yes"></pre><p>相关链接:非响应式设计的viewport <br><br>  适配 iPhone 6 和 iPhone 6plus 则需要写: <br><br></p><pre class='brush:php;toolbar:false;'><meta name="viewport" content="width=375"> <meta name="viewport" content="width=414"></pre><p>大部分 4.7~5 寸的安卓设备的 viewport 宽设为 360px,iPhone 6 上却是 375px,大部分 5.5 寸安卓机器(比如说三星 Note)的 viewport 宽为 400,iPhone 6 plus 上是 414px。 <br>  ios 设备 <br>  添加到主屏后的标题(iOS 6 新增)</p><pre class='brush:php;toolbar:false;'><meta name="apple-mobile-web-app-title" content="标题"> <!-- 添加到主屏后的标题(iOS 6 新增) --></pre><p>是否启用 WebApp 全屏模式</p><pre class='brush:php;toolbar:false;'><meta name="apple-mobile-web-app-capable" content="yes" /> <!-- 是否启用 WebApp 全屏模式 --></pre><p>设置状态栏的背景颜色</p><pre class='brush:php;toolbar:false;'><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <!-- 设置状态栏的背景颜色,只有在 `"apple-mobile-web-app-capable" content="yes"` 时生效 --></pre><p>只有在 "apple-mobile-web-app-capable" content="yes" 时生效 <br><br>  content 参数: <br><br>default 默认值。 <br>black 状态栏背景是黑色。 <br>black-translucent 状态栏背景是黑色半透明。 如果设置为 default 或 black ,网页内容从状态栏底部开始。 如果设置为 black-translucent ,网页内容充满整个屏幕,顶部会被状态栏遮挡。 <br><br>禁止数字识自动别为电话号码</p><pre class='brush:php;toolbar:false;'><meta name="format-detection" content="telephone=no" /> <!-- 禁止数字识自动别为电话号码 --></pre><p>iOS 图标<br></p> <p>  rel 参数: apple-touch-icon 图片自动处理成圆角和高光等效果。 apple-touch-icon-precomposed 禁止系统自动添加效果,直接显示设计原图。 iPhone 和 iTouch,默认 57x57 像素,必须有</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone 和 iTouch,默认 57x57 像素,必须有 --></pre><p>  iPad,72x72 像素,可以没有,但推荐有<br></p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png" /> <!-- iPad,72x72 像素,可以没有,但推荐有 --></pre><p>  Retina iPhone 和 Retina iTouch,114x114 像素,可以没有,但推荐有</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone 和 Retina iTouch,114x114 像素,可以没有,但推荐有 --></pre><p>  Retina iPad,144x144 像素,可以没有,但推荐有</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad,144x144 像素,可以没有,但推荐有 --></pre><p>  IOS 图标大小在iPhone 6 plus上是180×180,iPhone 6 是120x120。 适配iPhone 6 plus,则需要在中加上这段</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-icon-precomposed" sizes="180x180" href="retinahd_icon.png"></pre><p>iOS 启动画面<br><br>官方文档:<a href="http://www.php.cn/wiki/373.html" target="_blank">https://</a>developer.apple.com/library/ios/qa/qa1686/_index.html <br>参考文章:http://wxd.ctrip.com/blog/2013/09/ios7-hig-24/ <br><br>iPad 的启动画面是不包括状态栏区域的。</p> <p>  iPad 竖屏 768 x 1004(标准分辨率)</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad 竖屏 768 x 1004(标准分辨率) --></pre><p>  iPad 竖屏 1536x2008(Retina)</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad 竖屏 1536x2008(Retina) --></pre><p>  iPad 横屏 1024x748(标准分辨率)</p> <p>复制代码代码如下:<br></p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad 横屏 1024x748(标准分辨率) --></pre><p>  iPad 横屏 2048x1496(Retina)</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad 横屏 2048x1496(Retina) --></pre><p>  iPhone 和 iPod touch 的启动画面是包含状态栏区域的。</p> <p>  iPhone/iPod Touch 竖屏 320x480 (标准分辨率)<br></p> <p><link rel="apple-touch-startup-image" href="/splash-screen-320x480.png"> <!-- iPhone/iPod Touch 竖屏 320x480 (标准分辨率) --></p> <p>  iPhone/iPod Touch 竖屏 640x960 (Retina)</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch 竖屏 640x960 (Retina) --></pre><p>  iPhone 5/iPod Touch 5 竖屏 640x1136 (Retina)</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 竖屏 640x1136 (Retina) --></pre><p>  添加智能 App 广告条 Smart App Banner(iOS 6+ Safari)</p><pre class='brush:php;toolbar:false;'><meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- 添加智能 App 广告条 Smart App Banner(iOS 6+ Safari) --></pre><p>  iPhone 6对应的图片大小是750×1294,iPhone 6 Plus 对应的是1242×2148 。</p><pre class='brush:php;toolbar:false;'><link rel="apple-touch-startup-image" href="launch6.png" media="(device-width: 375px)"><link rel="apple-touch-startup-image" href="launch6plus.png" media="(device-width: 414px)"></pre><p>Windows 8<br>  Windows 8 磁贴颜色<br></p> <p>复制代码代码如下:<br></p><pre class='brush:php;toolbar:false;'><meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 磁贴颜色 --></pre><p>  Windows 8 磁贴图标</p><pre class='brush:php;toolbar:false;'><meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 磁贴图标 --></pre><p>  rss订阅<br></p><pre class='brush:php;toolbar:false;'><link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- 添加 RSS 订阅 -->   favicon icon</pre><pre class='brush:php;toolbar:false;'><link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- 添加 favicon icon --></pre><p>比较详细的 favicon 介绍可参考https://github.com/audreyr/favicon-cheat-sheet<br><br>移动端的meta <br></p><pre class='brush:php;toolbar:false;'><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <meta name="format-detection"content="telephone=no, email=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="apple-mobile-web-app-capable" content="yes" /><!-- 删除苹果默认的工具栏和菜单栏 --> <meta name="apple-mobile-web-app-status-bar-style" content="black" /><!-- 设置苹果工具栏颜色 --> <meta name="format-detection" content="telphone=no, email=no" /><!-- 忽略页面中的数字识别为电话,忽略email识别 --> <!-- 启用360浏览器的极速模式(webkit) --> <meta name="renderer" content="webkit"> <!-- 避免IE使用兼容模式 --> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 --> <meta name="HandheldFriendly" content="true"> <!-- 微软的老式浏览器 --> <meta name="MobileOptimized" content="320"> <!-- uc强制竖屏 --> <meta name="screen-orientation" content="portrait"> <!-- QQ强制竖屏 --> <meta name="x5-orientation" content="portrait"> <!-- UC强制全屏 --> <meta name="full-screen" content="yes"> <!-- QQ强制全屏 --> <meta name="x5-fullscreen" content="true"> <!-- UC应用模式 --> <meta name="browsermode" content="application"> <!-- QQ应用模式 --> <meta name="x5-page-mode" content="app"> <!-- windows phone 点击无高光 --> <meta name="msapplication-tap-highlight" content="no"> <!-- 适应移动端end --></pre><p>相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!</p> <p>相关阅读:</p> <p><a href="http://www.php.cn/div-tutorial-385639.html" target="_blank">html怎样使用style添加属性</a><br></p> <p><a href="http://www.php.cn/div-tutorial-385623.html" target="_blank">a标签href属性与onclick事件应该如何使用</a><br></p> <p><a href="http://www.php.cn/div-tutorial-385616.html" target="_blank">html文件中include文件内容应该如何使用</a><br></p>

The above is the detailed content of What are the uses of the HTML head tag?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.