Add HTML to Page with JS, PHP, or SSI Includes
The reason to use .shtml files to include HTML on a page is that it works as long as your server allows it. The reasons not to use this method are: some free hosts do not allow it, and you have to upload the files to test them. But here's how you do it:
Create an HTML include file, such as 1bunchastuff.html:
<p>Here is the text in the 1bunchastuff.html include file. It has no head, body, or html tags. Just the html code.</p>
That's the whole file—do NOT use head, body, or html tags. Now here's how to get your shtml file to let you include HTML on a page using 1bunchastuff.html: Put
<!--#include virtual="1bunchastuff.html" --> in the body section of the HTML code of your shtml file.
Try it: ssi.shtml
The reason to use .php files to include HTML on a page is that it works as long as your server has PHP—which nearly all do. The reasons not to use this method are: just in case your server has no PHP, and you have to upload the files to test them. But here's how you do it: Put <?php include("1bunchastuff.html"); ?> in the body section of the HTML code of your php file. The HTML file is the include that gets included.
Includes are great for making files that you add to all pages on your site, like navigation or side bar. Then when you wish to change the navigation or side bar on all pages, simply edit the include file and all of your site's pages will reflect this change.