I’m not sure how to word this correctly, but say my website has 3 rows: header, nav bar, and content. We land immediately in the ‘home’ tab with some introductory content, then we want to change to the ‘photos’ tab. When we change, I would like the header and nav bar to stay and only change the content row to load the ‘photos’ content.
My first idea is to have a template HTML file for all these pages, then href to the relevant html file. But that means if I wanted to change the header, then I would have to change the header in each file.
Could anyone please point me to a resource which explains how to do this? (Preferably only html and css, if possible).
I could be wrong but I think there’s still no way to do this with just html. I think at some point there was a proposal to have native partials in html but I guess it went nowhere. I tried to do a quick search but couldn’t find anything.
You can use a static site generator. This will mean your input files have to include the generator’s template language in addition to your HTML and CSS, and the generator will convert them to regular HTML/CSS whenever you run it.
You may be thinking of XSLT stylesheets with XHTML; those are supported by browsers, but uncommon in practice.
@AtomsForHire, it sounds like you want a consistent header and nav bar between pages.
You can do this with PHP or server-side includes (SSI) on the web server if you’re renting a VPS or using a hosting provder like Dreamhost or Nearly Free Speech. You can also do this locally with static site generators like Jekyll, Hugo, Pelican, etc. If you’re writing in Markdown and generating HTML, pandoc also supports templates. My preferred solution is hxinclude from the W3C’s HTML-XML-utils package. It has a few other handy utilities, too.
Here’s the simplest way to do it with PHP: put everything at the top, starting with <html>, in header.php, and everything at the bottom all the way down to </html> in footer.php and then make a page like
<?php include($_SERVER[DOCUMENT_ROOT] . "/header.php");?>
ooh look at me i am a webpage
<?php include($_SERVER[DOCUMENT_ROOT] . "/footer.php");?>
Having a or tag in HTML would be a game changer. I can’t add anything useful to what’s already been posted and the great links they give but once upon a time it was possible in Netscape 4. Both the div and layer elements had src properties where another file could be inserted into the page.
W3Schools uses a JavaScript XML request that some other libraries use.
What I used to use was a multi-file search and replace Windows utility called BK ReplaceEm, which then changed its name to Replace Text, before disappearing. That worked very well but a bit of a pain when the site got larger and all the files had to be reuploaded.
As I self-host an Apache server, I use Server Side Includes which is easy . I think most web servers have the same functionality such as NGINX and IIS.