HTML 是否区分大小写?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4351857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:35:15  来源:igfitidea点击:

Is HTML case sensitive?

html

提问by David Oneill

Is HTML case sensitive?

HTML 是否区分大小写?

In an example I'm working with it says:

在我正在使用的一个例子中,它说:

<!DOCTYPE html>

Would <!doctype html>or <!DocType Html>work differently (or not at all)?

<!doctype html>或会以<!DocType Html>不同的方式工作(或根本不会)?

回答by Roddick

No, but it's considered good practice to keep HTML markup lowercase.

不,但将 HTML 标记保持为小写被认为是一种很好的做法。

回答by Kenny Dorman

From http://www.w3.org/TR/html5/syntax.html

来自http://www.w3.org/TR/html5/syntax.html

In other words, <!DOCTYPE html>, case-insensitively.

Many strings in the HTML syntax (e.g. the names of elements and their attributes) are case-insensitive, but only for characters in the ranges U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z) and U+0061 to U+007A (LATIN SMALL LETTER A to LATIN SMALL LETTER Z). For convenience, in this section this is just referred to as "case-insensitive".

换句话说,<!DOCTYPE html>不区分大小写。

HTML 语法中的许多字符串(例如元素的名称及其属性)不区分大小写,但仅适用于 U+0041 到 U+005A(拉丁文大写字母 A 到 LATIN CAPITAL LETTER Z)和 U+0061 范围内的字符到 U+007A(拉丁文小写字母 A 到拉丁文小写字母 Z)。为方便起见,在本节中,这仅称为“不区分大小写”。

回答by Liam Newmarch

In addition to the other answers given, if you set the header Content-type: application/xhtml+xml, your browser will throw and XHML error if you don't type DOCTYPE in uppercase and html in lowercase:

除了给出的其他答案之外,如果您设置了 header Content-type: application/xhtml+xml,如果您不输入大写 DOCTYPE 和小写 html ,您的浏览器将抛出 XHML 错误:

<!DOCTYPE html>

Using the XHTML content type isn't recommended because the page won't be rendered in some browsers (e.g. IE8 and below), but it's certainly interesting to know.

不推荐使用 XHTML 内容类型,因为该页面不会在某些浏览器(例如 IE8 及更低版本)中呈现,但了解它当然很有趣。

Source: http://blog.whatwg.org/xhtml5-in-a-nutshell

来源:http: //blog.whatwg.org/xhtml5-in-a-nutshell

回答by Russell Dias

HTML is case insensitive. XHTML, that is being XMLis case sensitive.

HTML 不区分大小写。XHTML中,要XML大小写敏感的

回答by supercat

Generally, HTML is case-insensitive, but there are a few exceptions. Entity names (the things that follow ampersands) are case-senstive, but many browsers will accept many of them entirely in uppercase or entirely in lowercase; a few must be cased in particular ways. For example, Ç is &Ccedil; and ç is &ccedil;. Other combinations of upper and lower case are no good.

通常,HTML 不区分大小写,但也有一些例外。实体名称(与符号后面的内容)区分大小写,但许多浏览器会接受其中许多完全大写或完全小写;一些必须以特定方式加以区分。例如,Ç 是 Ç ç 是 ç。其他大小写组合都不好。

回答by Ryan Pedersen

No, you can use any case you want.

不,你可以使用任何你想要的案例。