Html html标签使用大写字母是不是不好?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19808514/
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 15:05:51  来源:igfitidea点击:

Is it bad to use uppercase letters for html tags?

htmluppercaselowercase

提问by pown

What is the best practice?

最佳做法是什么?

 <HTML> or <html>

And why we should stick with one particular case?

为什么我们应该坚持一个特定的案例?

However all browsers seems to interpret both cases and returns the expected output.

然而,所有浏览器似乎都能解释这两种情况并返回预期的输出。

回答by Spudley

The lower-case "requirement" is a legacy of xHTML, which explicitly required it.

小写的“要求”是 xHTML 的遗留问题,它明确要求它。

Plain old HTML on the other hand does not follow the rigid struct requirements of XML, and does not therefore have the fixed requirement for use of case.

另一方面,普通的旧 HTML 不遵循 XML 的严格结构要求,因此没有使用 case 的固定要求。

However developers have tended to stick with lower case as a convention anyway, mainly on the grounds that it's a lot easier to read when you're working on it, and easier to type. But it is only a convention; there's nothing forcing it. If you have existing code with upper case tags, they will work, and there's nothing stopping you continuing to write your tags that way.

然而,无论如何,开发人员都倾向于坚持使用小写字母作为惯例,主要是因为它在您工作时更容易阅读,并且更容易输入。但这只是一个约定;没有什么强迫它。如果您有带有大写标签的现有代码,它们将起作用,并且没有什么能阻止您继续以这种方式编写标签。

One other thing to be aware of though: In all browsers, when the browser loads the HTML document and parses it, it converts it into a DOM (Document object model). If you then use the browser's built-in developer tools to inspect the site, when you view the DOM, all elements in the DOM will be shown as lower case, regardless of how they were written in the actual source code.

但是要注意的另一件事是:在所有浏览器中,当浏览器加载 HTML 文档并对其进行解析时,它会将其转换为 DOM(文档对象模型)。如果您随后使用浏览器的内置开发人员工具检查站点,当您查看 DOM 时,DOM 中的所有元素都将显示为小写,无论它们在实际源代码中是如何编写的。

For this reason, if you stick with lower case, you'll find it easier to work with the developer tools, because the code you see in the DOM view will be more consistent with the source code you've written.

因此,如果您坚持使用小写字母,您会发现使用开发人员工具更容易,因为您在 DOM 视图中看到的代码将与您编写的源代码更加一致。

回答by Quentin

The only relevant parts of specifications say:

规格的唯一相关部分说:

  • HTML tag and attribute names are case insensitive.
  • XHTML tag and attribute names are case sensitive and must be lower case
  • HTML 标记和属性名称不区分大小写。
  • XHTML 标记和属性名称区分大小写且必须小写

Stuff that isn't mentioned in any standard:

任何标准中未提及的内容:

  • Lower case is generally considered easier to read
  • Lower case is most common (and what people are used to working with)
  • Holding down the shift key or toggling CAPS LOCK all the time is a pain
  • 小写通常被认为更容易阅读
  • 小写是最常见的(也是人们习惯使用的)
  • 一直按住shift键或切换CAPS LOCK很痛苦

回答by tremby

Probably very minor, and I have no evidence to back it up, but I bet using lowercase tags would very marginally improve gzip/deflate compressibility of the page, since most text is also likely to be lowercase.

可能非常小,我没有证据支持它,但我打赌使用小写标签会非常轻微地提高页面的 gzip/deflate 可压缩性,因为大多数文本也可能是小写的。

回答by NaNtastic

It is important to use one particular case, to prevent confusion. But using upper or lower case does not change a thing.

使用一种特殊情况很重要,以防止混淆。但是使用大写或小写不会改变任何事情。

回答by Krish R

Basically HTML is case insensitive. you can use lower case or upper case when entering HTML tags or HTML tag attributes but with XHTML lower case is required. In preparation for future upgrades, use lower case HTML tags and HTML tag attributes

基本上 HTML 不区分大小写。您可以在输入 HTML 标签或 HTML 标签属性时使用小写或大写,但需要使用 XHTML 小写。为将来的升级做准备,使用小写的 HTML 标签和 HTML 标签属性

回答by user13097

I prefer lowercase, because that is what is used by the HTML 5.2 specification: https://www.w3.org/TR/html52/introduction.html#a-quick-introduction-to-html

我更喜欢小写,因为这是 HTML 5.2 规范所使用的:https: //www.w3.org/TR/html52/introduction.html#a-quick-introduction-to-html

The HTML 4.0 specification shows HTML tags in uppercase, but the specification itself uses lowercase tags in its HTML code: https://www.w3.org/TR/html40/struct/global.html

HTML 4.0 规范以大写形式显示 HTML 标签,但规范本身在其 HTML 代码中使用小写标签:https: //www.w3.org/TR/html40/struct/global.html

Java's javax.swing.text.html.Html.Tag class uses lowercase (even though the Java constants are in uppercase, as is consistent with Java's naming conventions).

Java 的 javax.swing.text.html.Html.Tag 类使用小写(即使 Java 常量是大写的,这与 Java 的命名约定一致)。

Go's godoc tool uses lowercase.

Go 的 godoc 工具使用小写。