0

Say I have template structure that I want to implement on every page, like a navigation bar (A series of HTML tags and some CSS that will not change on any page).

Right now, I just had an empty page on my site titled "Template.html" and whenever I have to add a page to my site, I simply copy that page and work off of the template. But is there a way to just throw all this prewritten html in a special type of file and then relate it to a tag, like a CSS stylesheet?

It would be a gamechanger. Just one simple tag that references a file with HTML code and implements it in the page where it is referenced.

  • HTML natively doesn't have anything like that but this is really what libraries like react are for. Reusable components. – Matt Jul 02 '21 at 22:59
  • 2
    Does this answer your question? [Include another HTML file in a HTML file](https://stackoverflow.com/questions/8988855/include-another-html-file-in-a-html-file) – scriptor6 Jul 02 '21 at 23:00
  • @scriptor6 no I don't think so, because that deals with jQuery. It could be useful for my purpose, but right now I'm just trying to know if the existence of what I described in my original post is real. –  Jul 02 '21 at 23:02
  • 1
    @GSDV Does this help you? https://www.html5rocks.com/en/tutorials/webcomponents/imports/ – scriptor6 Jul 02 '21 at 23:05
  • @GSDV I'm sure there are libraries that can get the job done very simply, but they all in the end require a server since the only way to retrieve the html from a path is by sending an AJAX request. Would you like an answer with JS? – Spectric Jul 02 '21 at 23:09
  • for this purpose we have backend language that allow you to do such logic and generate the final HTML page. Don't try to do this at frontend level because this what is meant for. – Temani Afif Jul 02 '21 at 23:20

1 Answers1

0

An iframe is kind of like that. But generally speaking, no, HTML can't splice in elements from multiple sources by itself.

Neal Burns
  • 839
  • 4
  • 5