Documentation

Student-friendly HTML, CSS, and JavaScript reference with examples

Sections

createElement

Creates a new HTML element (doesn’t add it to the page yet).

const newDiv = document.createElement('div');
const newButton = document.createElement('button');
const newParagraph = document.createElement('p');

// Set properties
newDiv.textContent = 'Hello!';
newDiv.classList.add('my-class');

// Add to page
document.body.appendChild(newDiv);