sureshd sureshd - 3 months ago 24
HTML Question

Can HTML contain two HEAD tags

In my web application I got Header.jsp file which contains default header contents. Im including it in all other pages using jsp:include tag inside body tag of each individual pages.

Header.jsp contains its own HEAD tag to specify default meta tags, link stylesheets, scripts and some HTML elements. At the same time I will have another set of HEAD tag in all other individual pages to define title, page specific script and stylesheets.

For example:

Header.jsp

<head>
<link rel="shortcut icon" href="<%=request.getContextPath()%>/images/favicon.ico" type="image/x-icon" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<script src="js/jquery.js"></script>
<link rel=stylesheet type="text/css" href="dashboard.css" >
</head>
<h2>Dashboard</h2>


Main.jsp

<!DOCTYPE html>
<html>
<head>
<title>Main page</title>
<script src="main.js"></script>
</head>
<body>
<jsp:include page="Header.jsp" flush="true" />
.....
other HTML contents specific to main page
.....
</body>
</html>


whether it is valid to do like this?

Answer

It's not valid according to the standard

Relevant part:

4.2.1 The head element

Categories: None.

Contexts in which this element can be used: As the first element in an html element.

Your second <head> element wouldn't be the first element in the html document.