51

Is HTML case sensitive?

In an example I'm working with it says:

<!DOCTYPE html>

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
David Oneill
  • 12,502
  • 16
  • 58
  • 70

6 Answers6

61

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Roddick
  • 757
  • 6
  • 7
25

From 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".

Community
  • 1
  • 1
Kenny Dorman
  • 381
  • 2
  • 5
16

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:

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

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

Liam Newmarch
  • 3,935
  • 3
  • 32
  • 46
8

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

Russell Dias
  • 70,980
  • 5
  • 54
  • 71
7

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.

supercat
  • 77,689
  • 9
  • 166
  • 211
1

No, you can use any case you want.

Ryan Pedersen
  • 3,177
  • 27
  • 39