Search code examples
phpcsshead

Why are items showing up in my <body> instead of <head>


I'm adding my code below. I am working on a php webpage, but for some reason elements that I have in the <head> are showing up in the <body> instead. I don't understand why this is but it's also messing up my styles.

Could i get a clear explanation of the use of the tag in PHP/HTML in order to better understand how styles in my css sheet relates to them?


Solution

  • To me, it looks like you're using <head></head> as your navigation and <body></body> as your page's content. It should look something more like this:

    <html>
      <head>
        <link rel="stylesheet" type="text/css" href="style.css">
        <title>Your Title</title>
      </head>
      <body>
        <header>
          Your header content (navigation) goes here
        </header>
    
        <div id="page">
          Your page content goes here
        </div>
    
        <footer>
          Your footer content goes here
        </footer>
      </body>
    </html>
    

    Where <header></header> is your page's navigation and <div id="page"></div> is your page's content.

    The <head></head> tag will not be displayed on your webpage. It works to declare information or include information.

    The <body></body> tag is what tells the browser what to display. The HTML within this will be processed and displayed. All of your structural HTML and content goes here. Its not used as a structural element, it is a declarative. Use <header>, <div>, <footer>, and even table for structure (though you shouldn't). There are also other elements you can use by reading up on them.