InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Web components and Polymer

  • HTML import
  • polymer installation
  • HTML5 shadow dom
  • custom tag
 
  • Home
  • > Tutorials
  • > Web Development
  • > Web components

HTML import

on Feb 25, 2016

HTML import is part of web component framework and its specification is in Draft stage. HTML import can be used to import another html document in current document. Currently only Chrome and Opera support it.

Here is sample code using HTML import

<h2>Imported stuff</h2>
<div id="container"></div>
<link id="import1" rel="import" href="/api/html-import-hello-world.html">

<script>
var linkElement = document.querySelector('#import1');
var importedDoc = linkElement.import;
var content = importedDoc.querySelector('#content');
document.querySelector('#container').appendChild(content.cloneNode(true));
</script>
refresh done
try it online

Few points to note

  1. Imported document does not get inserted in current document’s html on its own. It has to be handled using Javascript.
  2. We are using linkElement.import to get imported document object.
  3. To get dom element inside importedDoc, we are using importedDoc.querySelector(). After that we can clone these to insert in current page DOM.

Specification and Browser compatibility

SpecificationStatusCategories
HTML ImportsW3C Working DraftDOM, HTML5
Desktop
ChromeFirefoxIEEdgeSafariOpera
Yes 36+ NoNoNoNoYes 23+
Mobile
Android ChromeAndroid FirefoxiOS SafariIE MobileOpera Mobile
Yes 47+ NoNoNoYes 33+
source: caniuse.com

Suggested posts:

  1. Python value in array (list) check
  2. How to do svn log of entire repository
  3. Running php eval on code with tags
  4. CSS general sibling selector
  5. PHP – print array in one line
  6. CSS calc function for numeric values
  7. Make an element draggable using Vanilla Javascript
  8. jQuery how to load a url into an element
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged HTML, Tutorials, Web components
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress