How can I create a custom HTML element that can be styled with CSS and have specific behaviors, such as click events, proper semantics, and accessibility? Are there any best practices for defining specific behaviors for custom HTML elements using event listeners? What are some examples of custom HTML elements that have been successfully implemented on websites
<!DOCTYPE html>
<html>
<head>
<title>Custom HTML Element Example</title>
<style>
.custom-element {
background-color: #ccc;
padding: 10px;
cursor: pointer;
}
</style>
</head>
<body>
<custom-element >Click me</custom-element>
<script>
class CustomElement extends HTMLElement {
constructor() {
super();
this.addEventListener('click', () => {
alert('You clicked the custom element!');
});
}
}
window.customElements.define('custom-element', CustomElement);
</script>
</body>
</html>
element is not keyboard accessible