HTML head tag detailed introduction

HTML head tag detailed introduction
There are many tags and elements in the HTML head part, which are related to the browser's rendering of web pages, SEO, etc., and each browser kernel and each domestic browser manufacturer has some of their own tag elements, which causes a lot of differences. In the era of mobile Internet, the head structure and meta elements of the mobile terminal become more important. The purpose of this article is to understand the meaning of each tag and write a head tag that meets your needs. This article is based on Yisi's article and expands on the summary to introduce the meaning and usage scenarios of various tags and elements in the commonly used head.

DOCTYPE

DOCTYPE (Document Type), this declaration is located at the very beginning of the document, before the html tag. This tag tells the browser which HTML or XHTML specification the document uses.

The DTD (Document Type Definition) declaration starts with <!DOCTYPE>, which is case-insensitive. There is nothing in front of it. If there is other content (except spaces), the browser will render the web page in quirks mode under IE. 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 generally DTD. A tag specifies a public text description, which is a unique descriptive name for the referenced public text, optionally followed by a version number. The last language is the ISO 639 language identifier of the DTD language, such as EN for English and ZH for Chinese. XHTML 1.0 can declare three DTD types. Respectively represent strict version, transitional version, and frame-based HTML documents.

●HTML 4.01 strict

XML/HTML CodeCopy content to clipboard
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >   
●HTML 4.01 Transitional

XML/HTML CodeCopy content to clipboard
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >   
●HTML 4.01 Frameset

XML/HTML CodeCopy content to clipboard
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd" >   
●The latest HTML5 introduces a more concise writing method, which is forward and backward compatible and is recommended for use.

XML/HTML CodeCopy content to clipboard
  1. <!doctype html >   

The doctype has two main purposes in HTML.

●Verify the validity of documents.

It tells user agents and validators what DTD the document was written in. This action is passive. The browser does not download the DTD and check the validity every time the page is loaded. It is only enabled when the page is manually verified.

●Determine the browser's rendering mode

For actual operation, tell 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. There are three ways for browsers to parse HTML documents.

●Non-weird (standard) mode●Weird mode●Partially weird (near-standard) mode Regarding IE's document mode, browser mode, strict mode, quirks mode, and DOCTYPE tag, you can read Mode in detail? standard! content.

charset

Declare the character encoding used by the document,

XML/HTML CodeCopy content to clipboard
  1. < meta   charset = "utf-8" >   

Before HTML5, web pages would be written like this:

XML/HTML CodeCopy content to clipboard
  1. < meta   http-equiv = "Content-Type"   content = "text/html; charset=utf-8" >   

These two are equivalent, as described in <meta charset='utf-8'> vs <meta http-equiv='Content-Type'>, so it is recommended to use the shorter one that is easier to remember.

The lang attribute

Simplified Chinese

XML/HTML CodeCopy content to clipboard
  1. < html   lang = "zh-cmn-Hans" >   

Traditional Chinese

XML/HTML CodeCopy content to clipboard
  1. < html   lang = "zh-cmn-Hant" >     

Why is it lang="zh-cmn-Hans" instead of the usual lang="zh-CN"? Please read: Should the declaration in the page header use lang="zh" or lang="zh-cn"?

Prioritize the latest version of IE and Chrome

XML/HTML CodeCopy content to clipboard
  1. < meta   http-equiv = "X-UA-Compatible"   content = "IE=edge,chrome=1"   />   

360 Using Google Chrome Frame

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "renderer"   content = "webkit" >   

After reading this tag, the 360 ​​browser will immediately switch to the corresponding high-speed core. In addition, for the sake of insurance, add

XML/HTML CodeCopy content to clipboard
  1. < meta   http-equiv = "X-UA-Compatible"   content = "IE=Edge,chrome=1" >   

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

Related links: Browser kernel control Meta tag description document

Baidu prohibits transcoding

When you open a web page through Baidu Mobile, Baidu may transcode your web page, take off your clothes, and put a dog-skin plaster advertisement on you. To do this, you can add

XML/HTML CodeCopy content to clipboard
  1. < meta   http-equiv = "Cache-Control"   content = "no-siteapp"   />   

Related link: SiteApp Transcoding Statement


SEO optimization section

Page title <title> tag (head required)

XML/HTML CodeCopy content to clipboard
  1. < title > your title </ title >   

Page keywords

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "keywords"   content = "your keywords" >    


Page description

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "description"   content = "your description" >   

Define the author of the web page

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "author"   content = "author,email address" >   

Defines how web search engines index web pages. Robotterms is a set of values ​​separated by commas "," and usually has the following values: none, noindex, nofollow, all, index, and follow.

XML/HTML CodeCopy content to clipboard

  1. < meta   name = "robots"   content = "index,follow" >   

Related Link: WEB1038 - Tag contains an invalid value

viewport

The viewport allows the layout to display better on mobile browsers. Usually write

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "viewport"   content = "width=device-width, initial-scale=1.0" >   

width=device-width will cause black edges to appear when opening the page in WebApp full-screen mode after adding it to the home screen on iPhone 5 (http://bigc.at/ios-webapp-viewport-meta.orz)

content parameter:

width viewport width (value/device-width)
height viewport height (value/device-height)
initial-scale initial scaling
maximum-scale maximum zoom ratio
minimum-scale minimum zoom ratio
user-scalable Whether to allow users to zoom (yes/no)
New in minimal-ui iOS 7.1 beta 2, which minimizes the upper and lower status bars when the page is loaded. This is a Boolean value, which can be written directly like this:

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "viewport"   content = "width=device-width, initial-scale=1, minimal-ui" >   

If your website is not responsive, please do not use initial-scale or disable scaling.

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "viewport"   content = "width=device-width,user-scalable=yes" >   

Related link: Non-responsive viewport

To adapt to iPhone 6 and iPhone 6plus, you need to write:

XML/HTML CodeCopy
content to clipboard

  1. < meta   name = "viewport"   content = "width=375" >   
  2. < meta   name = "viewport"   content = "width=414" >   

Most 4.7~5-inch Android devices have a viewport width of 360px, but on iPhone 6 it is 375px. Most 5.5-inch Android devices (such as Samsung Note) have a viewport width of 400, but on iPhone 6 plus it is 414px.

iOS devices

Title after adding to the home screen (New in iOS 6)

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "apple-mobile-web-app-title"   content = "title" >   <!-- Title after adding to the home screen (new in iOS 6) -->   


Whether to enable WebApp full screen mode

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "apple-mobile-web-app-capable"   content = "yes"   />   <!-- Whether to enable WebApp full screen mode -->   

Set the background color of the status bar

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "apple-mobile-web-app-status-bar-style"   content = "black-translucent"   />     
  2. <!-- Set the background color of the status bar. Only takes effect when `"apple-mobile-web-app-capable" content="yes"` -->   

Only works when "apple-mobile-web-app-capable" content="yes"

content parameter:

default The default value.
black The status bar background is black.
black-translucent The status bar background is black and translucent. If set to default or black, the web page content starts at the bottom of the status bar. If set to black-translucent, the web page content fills the entire screen and the top is blocked by the status bar.

Disable automatic identification of numbers as phone numbers

XML/HTML CodeCopy content to clipboard
  1. < meta   name = "format-detection"   content = "telephone=no"   />   <!-- Disable automatic identification of numbers as phone numbers -->   

iOS Icons

rel parameter: apple-touch-icon The image is automatically processed with rounded corners, highlights and other effects. apple-touch-icon-precomposed prohibits the system from automatically adding effects and directly displays the original design. iPhone and iTouch, default 57x57 pixels, must have


Copy code
The code is as follows:

<link rel="apple-touch-icon-precomposed" href="/apple-touch-icon-57x57-precomposed.png" /> <!-- iPhone and iTouch, default 57x57 pixels, required -->

iPad, 72x72 pixels, optional but recommended


Copy code
The code is as follows:

<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/apple-touch-icon-72x72-precomposed.png" /> <!-- iPad, 72x72 pixels, optional but recommended -->

Retina iPhone and Retina iTouch, 114x114 pixels, optional but recommended


Copy code
The code is as follows:

<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114-precomposed.png" /> <!-- Retina iPhone and Retina iTouch, 114x114 pixels, optional but recommended -->

Retina iPad, 144x144 pixels, optional but recommended


Copy code
The code is as follows:

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/apple-touch-icon-144x144-precomposed.png" /> <!-- Retina iPad, 144x144 pixels, optional but recommended -->

The iOS icon size is 180×180 on iPhone 6 plus and 120x120 on iPhone 6. To adapt to iPhone 6 plus, you need to add this paragraph


Copy code
The code is as follows:

<link rel="apple-touch-icon-precomposed" sizes="180x180" href="retinahd_icon.png">

iOS Splash Screen

Official documentation: https://developer.apple.com/library/ios/qa/qa1686/_index.html
Reference article: http://wxd.ctrip.com/blog/2013/09/ios7-hig-24/

The iPad startup screen does not include the status bar area.

iPad vertical screen 768 x 1004 (standard resolution)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="768x1004" href="/splash-screen-768x1004.png" /> <!-- iPad vertical screen 768 x 1004 (standard resolution) -->

iPad vertical screen 1536x2008 (Retina)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="1536x2008" href="/splash-screen-1536x2008.png" /> <!-- iPad vertical screen 1536x2008 (Retina) -->

iPad landscape 1024x748 (standard resolution)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="1024x748" href="/Default-Portrait-1024x748.png" /> <!-- iPad landscape 1024x748 (standard resolution) -->

iPad landscape 2048x1496 (Retina)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="2048x1496" href="/splash-screen-2048x1496.png" /> <!-- iPad landscape 2048x1496 (Retina) -->

The startup screen of iPhone and iPod touch includes the status bar area.

iPhone/iPod Touch vertical screen 320x480 (standard resolution)

Copy code
The code is as follows:

<link rel="apple-touch-startup-image" href="/splash-screen-320x480.png" /> <!-- iPhone/iPod Touch vertical screen 320x480 (standard resolution) -->

iPhone/iPod Touch Portrait 640x960 (Retina)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="640x960" href="/splash-screen-640x960.png" /> <!-- iPhone/iPod Touch Portrait 640x960 (Retina) -->

iPhone 5/iPod Touch 5 Portrait 640x1136 (Retina)


Copy code
The code is as follows:

<link rel="apple-touch-startup-image" sizes="640x1136" href="/splash-screen-640x1136.png" /> <!-- iPhone 5/iPod Touch 5 Portrait 640x1136 (Retina) -->

Add Smart App Banner (iOS 6+ Safari)


Copy code
The code is as follows:

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL"> <!-- Add Smart App Banner (iOS 6+ Safari) -->

The image size for iPhone 6 is 750×1294, and for iPhone 6 Plus it is 1242×2148.


Copy code
The code is as follows:

<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)">

Windows 8
Windows 8 tile colors


Copy code
The code is as follows:

<meta name="msapplication-TileColor" content="#000"/> <!-- Windows 8 tile color -->

Windows 8 Tile Icons


Copy code
The code is as follows:

<meta name="msapplication-TileImage" content="icon.png"/> <!-- Windows 8 tile icon -->

RSS Subscription


Copy code
The code is as follows:

<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" /> <!-- Add RSS subscription -->

favicon icon


Copy code
The code is as follows:

<link rel="shortcut icon" type="image/ico" href="/favicon.ico" /> <!-- Add favicon icon -->

For a more detailed introduction to favicon, please refer to https://github.com/audreyr/favicon-cheat-sheet

Mobile meta

XML/HTML CodeCopy content to clipboard

  1. < meta   name = "viewport"   content = "width=device-width, initial-scale=1, user-scalable=no"   />   
  2. < meta   name = "apple-mobile-web-app-capable"   content = "yes"   />   
  3. < meta   name = "apple-mobile-web-app-status-bar-style"   content = "black"   />   
  4. < meta   name = "format-detection" content = " telephone = no , email = no " />   
  5. < meta   name = "viewport"   content = "width=device-width, initial-scale=1, user-scalable=no"   />   
  6. < meta   name = "apple-mobile-web-app-capable"   content = "yes"   /> <!-- Delete Apple's default toolbar and menu bar -->   
  7. < meta   name = "apple-mobile-web-app-status-bar-style"   content = "black"   /> <!-- Set Apple toolbar color -->   
  8. < meta   name = "format-detection"   content = "telphone=no, email=no"   /> <!-- Ignore the numbers in the page and recognize them as phone numbers, ignore email recognition -->   
  9. <!-- Enable 360 ​​browser's extreme speed mode (webkit) -->   
  10. < meta   name = "renderer"   content = "webkit" >   
  11. <!-- Avoid IE using compatibility mode -->   
  12. < meta   http-equiv = "X-UA-Compatible"   content = "IE=edge" >   
  13. <!-- Optimized for handheld devices, mainly for some old browsers that do not recognize viewport, such as BlackBerry -->   
  14. < meta   name = "HandheldFriendly"   content = "true" >   
  15. <!-- Microsoft's old browser -->   
  16. < meta   name = "MobileOptimized"   content = "320" >   
  17. <!-- uc forces vertical screen -->   
  18. < meta   name = "screen-orientation"   content = "portrait" >   
  19. <!-- QQ forced vertical screen -->   
  20. < meta   name = "x5-orientation"   content = "portrait" >   
  21. <!-- UC forced full screen -->   
  22. < meta   name = "full-screen"   content = "yes" >   
  23. <!-- QQ forced full screen -->   
  24. < meta   name = "x5-fullscreen"   content = "true" >   
  25. <!-- UC application mode -->   
  26. < meta   name = "browsermode"   content = "application" >   
  27. <!-- QQ application mode -->   
  28. < meta   name = "x5-page-mode"   content = "app" >   
  29. <!-- No highlight when clicking on windows phone -->   
  30. < meta   name = "msapplication-tap-highlight"   content = "no" >   
  31. <!-- Adapt to mobile end -->   


This is a sharing summary from toobug.

More meta tag references

  • COMPLETE LIST OF HTML META TAGS
  • 18 Meta Tags Every Webpage Should Have in 2013

Reference articles:

  • Commonly used HTML head tags
  • html5_header
  • amazeui css
  • DOCTYPE
  • 10 iOS 8 Fresh Changes That Web Engineers and Designers Must Learn

<<:  Implementation of CSS child element selection parent element

>>:  Detailed explanation of the process of using GPU in Docker

Recommend

Classification of web page color properties

Classification of color properties Any color can ...

Detailed explanation of JavaScript program loop structure

Table of contents Select Structure Loop Structure...

CSS Transition expands and collapses elements by changing the Height

A common development need is that we want to coll...

Implementation of CSS equal division of parent container (perfect thirds)

The width of the parent container is fixed. In or...

Install Docker on Centos7 (2020 latest version available, just copy and paste)

Refer to the official documentation here for oper...

Drawing fireworks effect of 2021 based on JS with source code download

This work uses the knowledge of front-end develop...

How to reset the root password in CentOS7

There are various environmental and configuration...

A brief discussion on using Vue to complete the mobile apk project

Table of contents Basic Configuration Entry file ...

Mini Program to implement Token generation and verification

Table of contents process Demo Mini Program Backe...

Detailed explanation of SSH password-free login configuration under Linux

Assume there are two Linux servers A and B, and w...

Complete steps to install FFmpeg in CentOS server

Preface The server system environment is: CentOS ...

mysql5.7 create user authorization delete user revoke authorization

1. Create a user: Order: CREATE USER 'usernam...