Jump to content

HTML Code Layout


slj90

Recommended Posts

First the things which (hopefully) everybody agrees on:

  • Put all your PHP code before the HTML markup. Do not mix PHP and HTML, or you'll end up with an unreadable mess of spaghetti code.
  • Put all your JavaScript and CSS into external files. Avoid inline scripts and styles under all circumstances, because those again lead to spaghetti code and prevent the use of effective security tools like Content Security Policy.

Where exactly your script elements should be placed is somewhat controversial. Some people say that putting them right before the closing <body> tag will yield the best performance, some say they belong into the head element (possibly with an async or defer attribute for performance). Personally, I always put them into the head, because I think scripts are meta data.

Link to comment
https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1489541
Share on other sites

Here is basic HTML5 layout for you:
 

<!-- PHP code here -->
<!doctype html>
    <head>
        <meta charset="utf-8">
        <title>The Default Template</title>
        <!-- CSS, favicons etc goes here -->
    </head>
    <body>
        <header>
            
        </header>
        <section>
            
        </section>
        <footer>
            
        </footer>
    <!-- Place your javascript here -->
    </body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/290769-html-code-layout/#findComment-1490173
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.