HTML Debugging Guide
Learn common causes of blank previews, missing CSS, and null DOM errors—then fix them systematically.
Steps
- Reproduce the issue with the smallest snippet possible.
- Check the console for runtime errors.
- Verify selectors and IDs match the HTML.
- Disable external scripts temporarily.
- Compare iframe behavior with a downloaded standalone file.
Example
HTML
<button id="demo">Hello</button>
CSS
#demo { padding: 12px; }
JavaScript
// Broken: document.getElementById("missing").textContent = "OK";
const button = document.getElementById("demo");
if (button) button.textContent = "OK";
The commented line fails because no element has the ID missing. Uncomment it and run to reproduce the error. Restore the matching ID demo to fix it. A validator checks syntax; a null DOM lookup is a runtime error. For missing CSS, check the selector and inspect whether the rule applies to the element.
Tip
document.getElementById returns null when the element is missing or the script runs before the node exists in the preview document.