0

This code works:

<html>
  <head>
    <style>#a { height: 100%; }</style>
  </head>
  <body>
   <form>
     <textarea id="a"></textarea>
   </form>
  </body>
</html>

and produces a 100% height textarea.

If we add <!DOCTYPE html> on top, it doesn't work anymore (the height isn't 100% anymore).

Why? According to here, it seems that adding this DOCTYPE is making it HTML5. Why would HTML5 break the height: 100%;?

Red fx
  • 1,071
  • 2
  • 12
  • 26
Basj
  • 41,386
  • 99
  • 383
  • 673
  • height:100% is relative to parent element, and nothing is specified on the parent element (form) – Temani Afif Nov 15 '17 at 11:12
  • Why does it work without doctype then? – Basj Nov 15 '17 at 11:15
  • 3
    Possible duplicate of ["Height=100%" is not working in html when using , How i can fix this?](https://stackoverflow.com/questions/1966300/height-100-is-not-working-in-html-when-using-doctype-how-i-can-fix-this) – sol Nov 15 '17 at 11:15

1 Answers1

1

When you use of <!DOCTYPE html>,you are in standard mode and html and body have height equal his inside content,so you must use this code:

html, body, form, #a {
   height:100%;
} 

but when you don't use of DOCTYPE you are in quirks mode and , html and body have default height equal 100%,only use this code:

#a {
   height:100%;
}
Ehsan
  • 12,655
  • 3
  • 25
  • 44