or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

browser-apis.mdbrowser-window.mdcss-styling.mdcustom-elements.mddom-core.mdevent-system.mdfetch-http.mdform-file.mdhtml-elements.mdindex.mdmedia-av.md
tile.json

html-elements.mddocs/

HTML Elements

Complete implementation of all HTML elements with their specific properties and methods. Covers all standard HTML5 elements with accurate property implementations and behaviors.

Capabilities

Base HTML Element

HTMLElement Class

Base class for all HTML elements providing common functionality.

/**
 * Base class for all HTML elements
 */
class HTMLElement extends Element {
  /** Element style declarations */
  readonly style: CSSStyleDeclaration;
  
  /** Access key for keyboard navigation */
  accessKey: string;
  
  /** Auto-capitalization behavior */
  autocapitalize: string;
  
  /** Content editable flag */
  contentEditable: string;
  
  /** Text direction */
  dir: string;
  
  /** Drag and drop behavior */
  draggable: boolean;
  
  /** Element hidden state */
  hidden: boolean;
  
  /** Inner text content */
  innerText: string;
  
  /** Language code */
  lang: string;
  
  /** Spell check flag */
  spellcheck: boolean;
  
  /** Tab index for keyboard navigation */
  tabIndex: number;
  
  /** Element title (tooltip) */
  title: string;
  
  /** Translation behavior */
  translate: boolean;
  
  /** Focus element */
  focus(): void;
  
  /** Blur element */
  blur(): void;
  
  /** Click element */
  click(): void;
  
  /** Scroll element into view */
  scrollIntoView(options?: ScrollIntoViewOptions): void;
  
  // Event handler properties
  onclick: ((event: MouseEvent) => void) | null;
  ondblclick: ((event: MouseEvent) => void) | null;
  onmousedown: ((event: MouseEvent) => void) | null;
  onmouseup: ((event: MouseEvent) => void) | null;
  onmouseover: ((event: MouseEvent) => void) | null;
  onmouseout: ((event: MouseEvent) => void) | null;
  onmousemove: ((event: MouseEvent) => void) | null;
  onkeydown: ((event: KeyboardEvent) => void) | null;
  onkeyup: ((event: KeyboardEvent) => void) | null;
  onkeypress: ((event: KeyboardEvent) => void) | null;
  onfocus: ((event: FocusEvent) => void) | null;
  onblur: ((event: FocusEvent) => void) | null;
  onchange: ((event: Event) => void) | null;
  oninput: ((event: InputEvent) => void) | null;
  onsubmit: ((event: SubmitEvent) => void) | null;
  onload: ((event: Event) => void) | null;
  onerror: ((event: ErrorEvent) => void) | null;
}

interface ScrollIntoViewOptions {
  behavior?: 'auto' | 'smooth';
  block?: 'start' | 'center' | 'end' | 'nearest';
  inline?: 'start' | 'center' | 'end' | 'nearest';
}

Form Elements

HTMLFormElement Class

Form element for collecting user input.

/**
 * Form element for collecting user input
 */
class HTMLFormElement extends HTMLElement {
  /** Form action URL */
  action: string;
  
  /** Form encoding type */
  enctype: string;
  
  /** Form method (GET/POST) */
  method: string;
  
  /** Form name */
  name: string;
  
  /** No validation flag */
  noValidate: boolean;
  
  /** Form target */
  target: string;
  
  /** Form controls collection */
  readonly elements: HTMLFormControlsCollection;
  
  /** Form length (number of controls) */
  readonly length: number;
  
  /** Submit form */
  submit(): void;
  
  /** Reset form */
  reset(): void;
  
  /** Check form validity */
  checkValidity(): boolean;
  
  /** Report form validity */
  reportValidity(): boolean;
  
  /** Request submit (with validation) */
  requestSubmit(submitter?: HTMLElement): void;
}

/**
 * Collection of form controls
 */
class HTMLFormControlsCollection extends HTMLCollection {
  /** Get named item by name or id */
  namedItem(name: string): Element | null;
}

HTMLInputElement Class

Input element for various types of user input.

/**
 * Input element for various types of user input
 */
class HTMLInputElement extends HTMLElement {
  /** Input type */
  type: string;
  
  /** Input value */
  value: string;
  
  /** Input name */
  name: string;
  
  /** Input placeholder text */
  placeholder: string;
  
  /** Required field flag */
  required: boolean;
  
  /** Disabled state */
  disabled: boolean;
  
  /** Read-only state */
  readOnly: boolean;
  
  /** Auto-complete behavior */
  autocomplete: string;
  
  /** Auto-focus flag */
  autofocus: boolean;
  
  /** Checked state (for radio/checkbox) */
  checked: boolean;
  
  /** Default checked state */
  defaultChecked: boolean;
  
  /** Default value */
  defaultValue: string;
  
  /** Files list (for file inputs) */
  readonly files: FileList | null;
  
  /** Form owner */
  readonly form: HTMLFormElement | null;
  
  /** Validity state */
  readonly validity: ValidityState;
  
  /** Validation message */
  readonly validationMessage: string;
  
  /** Will validate flag */
  readonly willValidate: boolean;
  
  /** Maximum length */
  maxLength: number;
  
  /** Minimum length */
  minLength: number;
  
  /** Pattern for validation */
  pattern: string;
  
  /** Size attribute */
  size: number;
  
  /** Step for numeric inputs */
  step: string;
  
  /** Minimum value */
  min: string;
  
  /** Maximum value */
  max: string;
  
  /** Multiple selection flag */
  multiple: boolean;
  
  /** Accept attribute (for file inputs) */
  accept: string;
  
  /** Select input text */
  select(): void;
  
  /** Set selection range */
  setSelectionRange(start: number, end: number, direction?: string): void;
  
  /** Set custom validity */
  setCustomValidity(message: string): void;
  
  /** Check validity */
  checkValidity(): boolean;
  
  /** Report validity */
  reportValidity(): boolean;
  
  /** Step up value */
  stepUp(n?: number): void;
  
  /** Step down value */
  stepDown(n?: number): void;
}

/**
 * File list for file inputs
 */
class FileList {
  /** Number of files */
  readonly length: number;
  
  /** Get file by index */
  item(index: number): File | null;
  
  /** Array-like access */
  [index: number]: File;
}

HTMLTextAreaElement Class

Multi-line text input element.

/**
 * Multi-line text input element
 */
class HTMLTextAreaElement extends HTMLElement {
  /** Text content value */
  value: string;
  
  /** Element name */
  name: string;
  
  /** Placeholder text */
  placeholder: string;
  
  /** Required field flag */
  required: boolean;
  
  /** Disabled state */
  disabled: boolean;
  
  /** Read-only state */
  readOnly: boolean;
  
  /** Auto-focus flag */
  autofocus: boolean;
  
  /** Number of columns */
  cols: number;
  
  /** Number of rows */
  rows: number;
  
  /** Text wrapping behavior */
  wrap: string;
  
  /** Maximum length */
  maxLength: number;
  
  /** Minimum length */
  minLength: number;
  
  /** Form owner */
  readonly form: HTMLFormElement | null;
  
  /** Text length */
  readonly textLength: number;
  
  /** Selection start */
  selectionStart: number;
  
  /** Selection end */
  selectionEnd: number;
  
  /** Selection direction */
  selectionDirection: string;
  
  /** Select all text */
  select(): void;
  
  /** Set selection range */
  setSelectionRange(start: number, end: number, direction?: string): void;
  
  /** Set range text */
  setRangeText(replacement: string, start?: number, end?: number, selectionMode?: string): void;
}

HTMLSelectElement Class

Selection dropdown element.

/**
 * Selection dropdown element
 */
class HTMLSelectElement extends HTMLElement {
  /** Element name */
  name: string;
  
  /** Multiple selection flag */
  multiple: boolean;
  
  /** Required field flag */
  required: boolean;
  
  /** Disabled state */
  disabled: boolean;
  
  /** Auto-focus flag */
  autofocus: boolean;
  
  /** Size (visible options) */
  size: number;
  
  /** Form owner */
  readonly form: HTMLFormElement | null;
  
  /** Options collection */
  readonly options: HTMLOptionsCollection;
  
  /** Selected index */
  selectedIndex: number;
  
  /** Selected options */
  readonly selectedOptions: HTMLCollection;
  
  /** Current value */
  value: string;
  
  /** Number of options */
  readonly length: number;
  
  /** Add option */
  add(element: HTMLOptionElement, before?: HTMLElement | number): void;
  
  /** Remove option */
  remove(index: number): void;
  
  /** Check validity */
  checkValidity(): boolean;
}

HTMLOptionElement Class

Option element for select controls.

/**
 * Option element for select controls
 */
class HTMLOptionElement extends HTMLElement {
  /** Option value */
  value: string;
  
  /** Option text */
  text: string;
  
  /** Option label */
  label: string;
  
  /** Selected state */
  selected: boolean;
  
  /** Default selected state */
  defaultSelected: boolean;
  
  /** Disabled state */
  disabled: boolean;
  
  /** Form owner */
  readonly form: HTMLFormElement | null;
  
  /** Option index */
  readonly index: number;
}

HTMLButtonElement Class

Button element for user interaction.

/**
 * Button element for user interaction
 */
class HTMLButtonElement extends HTMLElement {
  /** Button type */
  type: string;
  
  /** Button name */
  name: string;
  
  /** Button value */
  value: string;
  
  /** Disabled state */
  disabled: boolean;
  
  /** Auto-focus flag */
  autofocus: boolean;
  
  /** Form owner */
  readonly form: HTMLFormElement | null;
  
  /** Form action URL */
  formAction: string;
  
  /** Form encoding type */
  formEnctype: string;
  
  /** Form method */
  formMethod: string;
  
  /** Form no-validate flag */
  formNoValidate: boolean;
  
  /** Form target */
  formTarget: string;
}

Media Elements

HTMLMediaElement Class

Base class for audio and video elements.

/**
 * Base class for audio and video elements
 */
class HTMLMediaElement extends HTMLElement {
  /** Media source URL */
  src: string;
  
  /** Current time position */
  currentTime: number;
  
  /** Media duration */
  readonly duration: number;
  
  /** Playback ended flag */
  readonly ended: boolean;
  
  /** Media error */
  readonly error: MediaError | null;
  
  /** Network state */
  readonly networkState: number;
  
  /** Paused state */
  readonly paused: boolean;
  
  /** Ready state */
  readonly readyState: number;
  
  /** Seeking state */
  readonly seeking: boolean;
  
  /** Auto-play flag */
  autoplay: boolean;
  
  /** Controls visible flag */
  controls: boolean;
  
  /** Loop playback flag */
  loop: boolean;
  
  /** Muted state */
  muted: boolean;
  
  /** Playback rate */
  playbackRate: number;
  
  /** Preload behavior */
  preload: string;
  
  /** Volume level (0-1) */
  volume: number;
  
  /** Play media */
  play(): Promise<void>;
  
  /** Pause media */
  pause(): void;
  
  /** Load media */
  load(): void;
  
  /** Can play type check */
  canPlayType(type: string): string;
}

HTMLVideoElement Class

Video element for video playback.

/**
 * Video element for video playback
 */
class HTMLVideoElement extends HTMLMediaElement {
  /** Video width */
  width: number;
  
  /** Video height */
  height: number;
  
  /** Poster image URL */
  poster: string;
  
  /** Video width (intrinsic) */
  readonly videoWidth: number;
  
  /** Video height (intrinsic) */
  readonly videoHeight: number;
}

HTMLAudioElement Class

Audio element for audio playback.

/**
 * Audio element for audio playback
 */
class HTMLAudioElement extends HTMLMediaElement {
  // Inherits all HTMLMediaElement properties and methods
}

Link and Navigation Elements

HTMLAnchorElement Class

Anchor element for links and navigation.

/**
 * Anchor element for links and navigation
 */
class HTMLAnchorElement extends HTMLElement {
  /** Link URL */
  href: string;
  
  /** Link target */
  target: string;
  
  /** Link relationship */
  rel: string;
  
  /** Download filename */
  download: string;
  
  /** URL hash */
  hash: string;
  
  /** URL host */
  host: string;
  
  /** URL hostname */
  hostname: string;
  
  /** URL pathname */
  pathname: string;
  
  /** URL port */
  port: string;
  
  /** URL protocol */
  protocol: string;
  
  /** URL search parameters */
  search: string;
  
  /** Link text */
  text: string;
}

HTMLLinkElement Class

Link element for external resources.

/**
 * Link element for external resources
 */
class HTMLLinkElement extends HTMLElement {
  /** Resource URL */
  href: string;
  
  /** Link relationship */
  rel: string;
  
  /** Media query */
  media: string;
  
  /** MIME type */
  type: string;
  
  /** Resource sizes */
  sizes: string;
  
  /** Cross-origin behavior */
  crossOrigin: string | null;
  
  /** Resource integrity */
  integrity: string;
  
  /** Referrer policy */
  referrerPolicy: string;
  
  /** Style sheet (if rel=stylesheet) */
  readonly sheet: CSSStyleSheet | null;
}

Image and Media

HTMLImageElement Class

Image element for displaying images.

/**
 * Image element for displaying images
 */
class HTMLImageElement extends HTMLElement {
  /** Image source URL */
  src: string;
  
  /** Alternative text */
  alt: string;
  
  /** Image width */
  width: number;
  
  /** Image height */
  height: number;
  
  /** Cross-origin behavior */
  crossOrigin: string | null;
  
  /** Loading behavior */
  loading: string;
  
  /** Sizes attribute */
  sizes: string;
  
  /** Source set */
  srcset: string;
  
  /** Use map reference */
  useMap: string;
  
  /** Natural width */
  readonly naturalWidth: number;
  
  /** Natural height */
  readonly naturalHeight: number;
  
  /** Complete loading flag */
  readonly complete: boolean;
  
  /** Decode image */
  decode(): Promise<void>;
}

/**
 * Image constructor function
 */
class Image extends HTMLImageElement {
  constructor(width?: number, height?: number);
}

HTMLCanvasElement Class

Canvas element for graphics rendering.

/**
 * Canvas element for graphics rendering
 */
class HTMLCanvasElement extends HTMLElement {
  /** Canvas width */
  width: number;
  
  /** Canvas height */
  height: number;
  
  /** Get rendering context */
  getContext(contextId: string, options?: any): RenderingContext | null;
  
  /** Convert to data URL */
  toDataURL(type?: string, quality?: number): string;
  
  /** Convert to blob */
  toBlob(callback: (blob: Blob | null) => void, type?: string, quality?: number): void;
}

Table Elements

HTMLTableElement Class

Table element for tabular data.

/**
 * Table element for tabular data
 */
class HTMLTableElement extends HTMLElement {
  /** Table caption */
  caption: HTMLTableCaptionElement | null;
  
  /** Table head section */
  tHead: HTMLTableSectionElement | null;
  
  /** Table foot section */
  tFoot: HTMLTableSectionElement | null;
  
  /** Table body sections */
  readonly tBodies: HTMLCollection;
  
  /** Table rows */
  readonly rows: HTMLCollection;
  
  /** Create caption */
  createCaption(): HTMLTableCaptionElement;
  
  /** Delete caption */
  deleteCaption(): void;
  
  /** Create table head */
  createTHead(): HTMLTableSectionElement;
  
  /** Delete table head */
  deleteTHead(): void;
  
  /** Create table foot */
  createTFoot(): HTMLTableSectionElement;
  
  /** Delete table foot */
  deleteTFoot(): void;
  
  /** Insert row */
  insertRow(index?: number): HTMLTableRowElement;
  
  /** Delete row */
  deleteRow(index: number): void;
}

HTMLTableRowElement Class

Table row element.

/**
 * Table row element
 */
class HTMLTableRowElement extends HTMLElement {
  /** Row cells */
  readonly cells: HTMLCollection;
  
  /** Row index */
  readonly rowIndex: number;
  
  /** Section row index */
  readonly sectionRowIndex: number;
  
  /** Insert cell */
  insertCell(index?: number): HTMLTableCellElement;
  
  /** Delete cell */
  deleteCell(index: number): void;
}

HTMLTableCellElement Class

Table cell element (td/th).

/**
 * Table cell element (td/th)
 */
class HTMLTableCellElement extends HTMLElement {
  /** Column span */
  colSpan: number;
  
  /** Row span */
  rowSpan: number;
  
  /** Headers reference */
  headers: string;
  
  /** Scope attribute */
  scope: string;
  
  /** Abbreviated text */
  abbr: string;
  
  /** Cell index */
  readonly cellIndex: number;
}

Other Common Elements

HTMLDivElement Class

Generic container element.

/**
 * Generic container element
 */
class HTMLDivElement extends HTMLElement {
  // Inherits all HTMLElement properties and methods
}

HTMLSpanElement Class

Generic inline element.

/**
 * Generic inline element
 */
class HTMLSpanElement extends HTMLElement {
  // Inherits all HTMLElement properties and methods
}

HTMLParagraphElement Class

Paragraph element.

/**
 * Paragraph element
 */
class HTMLParagraphElement extends HTMLElement {
  // Inherits all HTMLElement properties and methods
}

HTMLHeadingElement Class

Heading elements (h1-h6).

/**
 * Heading elements (h1-h6)
 */
class HTMLHeadingElement extends HTMLElement {
  // Inherits all HTMLElement properties and methods
}

Usage Examples

Form Handling

import { Window } from "happy-dom";

const window = new Window();
const document = window.document;

// Create form
const form = document.createElement('form');
form.action = '/submit';
form.method = 'POST';

// Create input
const input = document.createElement('input');
input.type = 'text';
input.name = 'username';
input.required = true;

// Create button
const button = document.createElement('button');
button.type = 'submit';
button.textContent = 'Submit';

// Assemble form
form.appendChild(input);
form.appendChild(button);
document.body.appendChild(form);

// Handle events
form.addEventListener('submit', (event) => {
  event.preventDefault();
  console.log('Form submitted with:', input.value);
});

Media Elements

import { Window } from "happy-dom";

const window = new Window();
const document = window.document;

// Create video element
const video = document.createElement('video');
video.src = 'video.mp4';
video.controls = true;
video.autoplay = false;

// Handle events
video.addEventListener('loadeddata', () => {
  console.log('Video loaded:', video.duration);
});

video.addEventListener('play', () => {
  console.log('Video started playing');
});

// Control playback
await video.play();
video.pause();