1

In many programming languages, there is some type of 'include' command/directive/statement which helps developer make the source code, more 'modular' so there is no need to include everything in one single file.

Why there is no such facility in HTML?

Mahdi
  • 1,871
  • 2
  • 24
  • 41
  • 2
    HTML is not a programming language but a markup language. Although SGML features external entities, browsers don’t support them. – Gumbo Sep 30 '14 at 05:40
  • There used to be this at a time: http://en.wikipedia.org/wiki/Server_Side_Includes – techfoobar Sep 30 '14 at 05:40
  • you could use php to achieve what you want; `` – Azrael Sep 30 '14 at 05:41
  • 1
    I don't think there's going to be a fact-based answer to this question unless you can find a reference from someone involved in the early HTML specification process several decades ago. Includes exist for JS files and for CSS files, but not for chunks of HTML. The world has moved to include pieces of HTML server-side with server-side includes or templates which is probably a better place for it to happen anyway (fewer network requests). Plus, there are iframes too for some types of uses. – jfriend00 Sep 30 '14 at 05:41
  • This is would be a good reading http://www.w3.org/TR/WD-html40-970708/struct/includes.html – Sameera Thilakasiri Sep 30 '14 at 05:42
  • 2
    There are such things as HTML imports. http://www.html5rocks.com/en/tutorials/webcomponents/imports/ – rink.attendant.6 Sep 30 '14 at 05:43
  • 1
    This question is both opinion-based and off-topic (it is looking for a “theoretical” reason, not a solution to a practical problem). Regarding the practical question “How do I include an HTML file in an HTML file”, there are several versions of it at SO. – Jukka K. Korpela Sep 30 '14 at 06:01
  • XSLT supports this if I'm not mistaken but I never used it...I think Blizzard Entertainment did this on the Diablo III website once and they even made me happy when they served it as application/xhtml+xml. I don't program text, I program code. ;-) – John Oct 02 '14 at 02:14

2 Answers2

2

HTML Imports do in fact exist, but are currently still in development and it will probably take a while until they are supported by all major browsers.

Just like including CSS and favicons, the link element is used to import HTML fragments which you can then use (i.e. clone) using JavaScript:

<link rel="import" href="/path/to/imports/stuff.html">

It's been supported since Chrome 36 according to Can I Use

You can read more about HTML Imports at HTML Imports: #include for the web and also follow the specification at the W3C.

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
1

Try This Link, May Help You, Import Pages...

http://www.html5rocks.com/en/tutorials/webcomponents/imports/

HTML Imports, part of the Web Components cast, is a way to include HTML documents in other HTML documents. You're not limited to markup either. An import can also include CSS, JavaScript, or anything else an .html file can contain. In other words, this makes imports a fantastic tool for loading related HTML/CSS/JS.

Include an import on your page by declaring a :

<head>
  <link rel="import" href="/path/to/imports/stuff.html">
</head>

The URL of an import is called an import location. To load content from another domain, the import location needs to be CORS-enabled:

<!-- Resources on other origins must be CORS-enabled. -->
<link rel="import" href="http://example.com/elements.html">
Edwin Thomas
  • 1,186
  • 2
  • 18
  • 31