Is it bad to use uppercase letters for html tags?

前端 未结 6 1778
星月不相逢
星月不相逢 2020-11-27 19:04

What is the best practice?

  or 

And why we should stick with one particular case?

However all browsers see

相关标签:
6条回答
  • 2020-11-27 19:16

    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

    0 讨论(0)
  • 2020-11-27 19:17

    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.

    0 讨论(0)
  • 2020-11-27 19:27

    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

    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
    0 讨论(0)
  • 2020-11-27 19:30

    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

    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

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

    Go's godoc tool uses lowercase.

    0 讨论(0)
  • 2020-11-27 19:31

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

    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.

    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.

    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.

    0 讨论(0)
  • 2020-11-27 19:35

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

    0 讨论(0)
提交回复
热议问题