2

Just want to know if it's possible to have a div tag inside the head element?

12
  • 1
    Whether or not an element is a valid child of another can be checked in the specs. For the head element the only valid children are [...]zero or more elements of metadata content, of which no more than one is a title element and no more than one is a base element[...] Commented Oct 26, 2014 at 22:17
  • Does that mean I can have a div tag in the head tag? Commented Oct 26, 2014 at 22:22
  • 2
    You mean head not header. header is a different tag. Commented Oct 26, 2014 at 22:22
  • I mean the head tag. Can I have a div tag inside the head tag? Commented Oct 26, 2014 at 22:25
  • 4
    I think a bigger question is why in the world would you want to? Commented Oct 26, 2014 at 22:27

1 Answer 1

6

No, <div> is not a valid tag to be inside of the <head> tag, since the <head> tag is only meant to be for metadata (such as title and page description), scripts, styles, and other stuff which isn't meant to be displayed. Although putting it in the <head> works, it's horrible to do so, and you shouldn't put it there (and the specification says that doing that is not valid HTML. Thanks @t.niese); it's invalid HTML

Also, there is no difference between using " or ' for attribute values (such as id in your case), it's just what you prefer. And yes, using ' is completely valid. I like doing that, since I don't have to hold shift, but it's completely up to you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.