Home Web Front-end HTML Tutorial Can html5 charset be used?

Can html5 charset be used?

Dec 01, 2016 am 10:39 AM
charset html5

Some time ago, the page in a project suddenly appeared garbled in IE6. I did various troubleshooting at that time, and finally speculated that it was a problem with the use of HTML5 DOCTYPE and Charset and Chinese comments, so I temporarily used the old Charset method to fix it. Later The garbled code never appeared again.

In fact, I have never been sure whether HTML5 Charset can be recognized by IE6, so I did some tests.

First, let’s talk about the two Charset declaration methods. In fact, everyone should be familiar with them:

We will refer to the first method as the HTML5 method and the second method as the HTML4 method.

Test environment:

Windows XP Sp2, Chinese version + English version of IE6, and IE9 under Windows 7 and its various compatibility modes and the current Stable version of Chrome, Firefox, etc.;

Because we use HTML files are all encoded in UTF8, so the HTML files in the test cases here are also in UTF8 (no BOM) format. The project is similarly encoded with gbk or gb2312.

Two methods are used for testing:

meta method: including HTML5 and HTML4 methods and their mashups

Server-side method: setting charset on the server side, nginx is used here, charset=utf-8

Test case—— Meta method:

UTF8

UTF8 HTML4 method

UTF8-GB2312

UTF8+ Chinese comment before meta

UTF8+ Chinese comment between HTML and HEAD

GB2312

GB2312 HTML4 method

GB2312-UTF8

GB2312+Chinese comments before meta

GB2312+Chinese comments between HTML and HEAD

Test case - server method:

Server setting encoding

meta encoding and server encoding are inconsistent

Each use case above can be accessed directly

Test results:

The test cases performed consistently in each browser;

UTF-8 solutions were all displayed normally;

charset was declared as gb2312, which was inconsistent with the UTF-8 encoding of the document, so all garbled characters;

1, 6 use HTML5 charset to define UTF8 and gb2312 respectively. 1 displays normally without garbled characters, and 6 has garbled characters - this is true for both the Chinese version of IE6 and the English version of IE6, indicating that IE6 can recognize the HTML5 charset;

1,2 use cases As with use cases 6 and 7, defining charset using HTML5 and HTML4 methods respectively has the same effect;

It is worth noting that the third use case first uses the HTML5 method to set the UTF-8 encoding, and then uses the HTML4 encoding setting. It is gb2312, but the page is displayed normally, while in the eighth use case, the result page displays garbled characters, so it can be inferred that the second meta tag does not take effect;

4 and 5 use cases are not garbled, indicating that simple HTML comments are not It will definitely lead to garbled characters. There is no test here about what may happen when loading external files such as js with different encodings in these two locations;

In the server method, use case 1 does not use meta to set charset, and the page displays normally, while use case 2 uses The meta setting charset=gb2312 is different from the server version, but there is still no garbled code, indicating that the charset returned by the server has a higher priority;

Conclusion:

In fact, regarding the specifications of charset, Google's development documents also explain it:

must be in the HEAD tag;

must be before any other content, that is, it must be at the front of HEAD;

including spaces and DOCTYPE declarations , should be within the first 512 bytes;

HTML5 and HTML4 have the same effect, just use one of them;

The above test also proves that item 4 is correct, and both writing methods are acceptable.

In addition, it is also a good idea to set charset on the server side. The charset statement is obtained directly in the HTTP response, which is more efficient and more convenient. Google is currently using this approach.

So as long as the page is written in a standardized way, there will be no problem of garbled characters. So you can boldly use HTML5's DOCTYPE and Charset declarations. But please try to follow the specifications in Google documents mentioned above. Don’t put too many things in the head, and put external resources such as js at the back.

It is inevitable that there will be omissions during the test. If there are any errors, please correct them and discuss them together~~


Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles