Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Imports</title>
<script src="use.js"></script>
</head>
<body>
<use-web-components></use-web-components>
</body>
class UseWebComponents extends HTMLElement {
connectedCallback(){
this.innerHTML = `
<style>
h1 {
background-color: dimgray;
color: darkgray;
}
</style>
<h1>Use Web Components!</h1>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Imports</title>
<link rel="import" href="use.html" id="use" />
</head>
<body>
<use-web-components></use-web-components>
</body>
<template>
<style>
h1 {
background-color: dimgray;
color: darkgray;
}
</style>
<h1>Use Web Components!</h1>
</template>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML Imports</title>
<link rel="import" href="hello.html" id="hello" />
</head>
<body>
<!DOCTYPE html>
<html>
<body>
<h1>Hello Web Components!</h1>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>HTML Templates</title>
</head>
<body>
<template id="task">
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Shadow DOM</title>
<style>
input {
border-color: red;
margin: 10px;
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/document-register-element/1.5.0/document-register-element.js"></script>
<script type="text/javascript">
class HelloInputCustomElement extends HTMLInputElement {
connectedCallback() {
this.setAttribute('value', 'Hello');
<!DOCTYPE html>
<html>
<head>
<title>Custom Elements</title>
<script type="text/javascript">
class HelloCustomElement extends HTMLElement {
sayHello() {
console.log('Hello!');
}
}