Dynamic HTML

Coding interactive or animated websites

This article contains instructions or advice. Wikipedia is not a guidebook; please help rewrite the content to make it more encyclopedic or move it to Wikiversity, Wikibooks, or Wikivoyage. (January 2025)

|

HTML

HTML and variants

* Dynamic HTML
* HTML5
* XHTML
* Basic
* Mobile Profile

HTML elements and attributes

* HTML element
* article
* audio
* blink
* canvas
* div and span
* marquee
* meta
* video
* HTML attribute
* alt attribute
* HTML frame

Editing

* HTML editor
* Text editor

Character encodings and language

* Character encodings
* Character entity references (amed characters)
* Unicode
* Language code

Document and browser models

* Document Object Model
* Browser Object Model
* Style sheets
* CSS
* Font family
* Web colors

Client-side scripting and APIs

* JavaScript
* WebCL
* HTMX

Graphics and Web3D technology

* Web3D
* WebGL
* WebGPU
* WebXR
* W3C
* Validator
* WHATWG
* Quirks mode
* Web storage
* Rendering engine

Comparisons

* Document markup languages
* Comparison of browser engines

* v
* t
* e

Dynamic HTML, or DHTML, is a term which was used by some browser vendors to describe the combination of HTML, style sheets and client-side scripts (JavaScript, VBScript, or any other supported scripts) that enabled the creation of interactive and animated documents.[1][2] The application of DHTML was introduced by Microsoft with the release of Internet Explorer 4 in 1997.[3][unreliable source?]

DHTML (Dynamic HTML) allows scripting languages, such as JavaScript, to modify variables and elements in a web page's structure, which in turn affect the look, behavior, and functionality of otherwise "static" HTML content after the page has been fully loaded and during the viewing process. Thus the dynamic characteristic of DHTML is the way it functions while a page is viewed, not in its ability to generate a unique page with each page load.

By contrast, a dynamic web page is a broader concept, covering any web page generated differently for each user, load occurrence, or specific variable values. This includes pages created by client-side scripting and ones created by server-side scripting (such as PHP, Python, JSP or ASP.NET) where the web server generates content before sending it to the client.

DHTML is the predecessor of Ajax and DHTML pages are still request/reload-based. Under the DHTML model, there may not be any interaction between the client and server after the page is loaded; all processing happens on the client side. By contrast, Ajax extends features of DHTML to allow the page to initiate network requests (or 'subrequest') to the server even after page load to perform additional actions. For example, if there are multiple tabs on a page, the pure DHTML approach would load the contents of all tabs and then dynamically display only the one that is active, while AJAX could load each tab only when it is really needed.

## Uses

[edit]

DHTML allows authors to add effects to their pages that are otherwise difficult to achieve, by changing the Document Object Model (DOM) and page style. The combination of HTML, CSS, and JavaScript offers ways to:

* Animate text and images in their document.
* Embed a ticker or other dynamic display that automatically refreshes its content with the latest news, stock quotes, or other data.
* Use a form to capture user input, and then process, verify and respond to that data without having to send data back to the server.
* Include rollover buttons or drop-down menus.

A less common use is to create browser-based action games. Although a number of games were created using DHTML during the late 1990s and early 2000s,[4] differences between browsers made this difficult: many techniques had to be implemented in code to enable the games to work on multiple platforms. Browsers have since then converged toward web standards, which has made the design of DHTML games more viable. Those games can be played on all major browsers and in desktop and device applications that support embedded browser contexts.

The term "DHTML" has fallen out of use in recent years as it was associated with practices and conventions that tended to not work well between various web browsers.[5]

DHTML support with extensive DOM access was introduced with Internet Explorer 4.0. Although there was a basic dynamic system with Netscape Navigator 4.0, not all HTML elements were represented in the DOM. When DHTML-style techniques became widespread, varying degrees of support among web browsers for the technologies involved made them difficult to develop and debug. Development became easier when Internet Explorer 5.0+, Mozilla Firefox 2.0+, and Opera 7.0+ adopted a shared DOM inherited from ECMAScript.

Later, JavaScript libraries such as jQuery abstracted away many of the day-to-day difficulties in cross-browser DOM manipulation, though better standards compliance among browsers has reduced the need for this.

## Structure of a web page

[edit]

See also: DOM events

Typically a web page using DHTML is set up in the following way:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>DHTML example</title>
</head>
<body bgcolor="red">
<script>
function init() {
let myObj = document.getElementById("navigation");
// ... manipulate myObj

window.onload = init;
</script>
<!--
Often the code is stored in an external file; this is done
by linking the file that contains the JavaScript.
This is helpful when several pages use the same script:
-->
<script src="my-javascript.js"></script>
</body>
</html>

## Example: Displaying an additional block of text

[edit]

The following code illustrates an often-used function. An additional part of a web page will only be displayed if the user requests it.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Using a DOM function</title>
<style>
a { background-color: #eee; }
a:hover { background: #ff0; }
#toggleMe { background: #cfc; display: none; margin: 30px 0; padding: 1em; }
</style>
</head>
<body>
<h1>Using a DOM function</h1>

<h2><a id="showhide" href="#">Show paragraph</a></h2>

<p id="toggle-me">This is the paragraph that is only displayed on request.</p>

<p>The general flow of the document continues.</p>

<script>
function changeDisplayState(displayElement, textElement) {
if (displayElement.style.display === "none" || displayElement.style.display === "") {
displayElement.style.display = "block";
textElement.innerHTML = "Hide paragraph";
} else {
displayElement.style.display = "none";
textElement.innerHTML = "Show paragraph";

let displayElement = document.getElementById("toggle-me");
let textElement = document.getElementById("showhide");
textElement.addEventListener("click", function (event) {
event.preventDefault();
changeDisplayState(displayElement, textElement);
});
</script>
</body>
</html>

## Document Object Model

[edit]

Main article: Document Object Model

DHTML is not a technology in and of itself; rather, it is the product of three related and complementary technologies: HTML, Cascading Style Sheets (CSS), and JavaScript. To allow scripts and components to access features of HTML and CSS, the contents of the document are represented as objects in a programming model known as the Document Object Model (DOM).

The DOM API is the foundation of DHTML, providing a structured interface that allows access and manipulation of virtually anything in the document. The HTML elements in the document are available as a hierarchical tree of individual objects, making it possible to examine and modify an element and its attributes by reading and setting properties and by calling methods. The text between elements is also available through DOM properties and methods.

The DOM also provides access to user actions such as pressing a key and clicking the mouse. It is possible to intercept and process these and other events by creating event handler functions and routines. The event handler receives control each time a given event occurs and can carry out any appropriate action, including using the DOM to change the document.

## Dynamic styles

[edit]

Dynamic styles are a key feature of DHTML. By using CSS, one can quickly change the appearance and formatting of elements in a document without adding or removing elements. This helps keep documents small and the scripts that manipulate the document fast.

The object model provides programmatic access to styles. This means you can change inline styles on individual elements and change style rules using simple JavaScript programming.

Inline styles are CSS style assignments that have been applied to an element using the style attribute. You can examine and set these styles by retrieving the style object for an individual element. For example, to highlight the text in a heading when the user moves the mouse pointer over it, you can use the style object to enlarge the font and change its color, as shown in the following simple example.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Dynamic Styles</title>
<style>
ul { display: none; }
</style>
</head>

<body>
<h1 id="first-header">Welcome to Dynamic HTML</h1>

<p><a id="clickable-link" href="#">Dynamic styles are a key feature of DHTML.</a></p>

<ul id="unordered-list">
<li>Change the color, size, and typeface of text</li>
<li>Show and hide text</li>
<li>And much, much more</li>
</ul>

<p>We've only just begun!</p>

<script>
function showMe() {
document.getElementById("first-header").style.color = "#990000";
document.getElementById("unordered-list").style.display = "block";

document.getElementById("clickable-link").addEventListener("click", function (event) {
event.preventDefault();
showMe();
});
</script>
</body>
</html>

## See also

[edit]

* Dynamic web page

## References

[edit]

1. ^ "Document Object Model FAQ". W3C. October 22, 2003. Retrieved 2022-02-16.
2. ^ "Web Style Sheets". W3C. 22 July 1999. Retrieved 7 April 2018.
3. ^ Pedamkar, Priya (2020-07-19). "DHTML | A Quick Glance of DHTML with Components, Features, Need". EDUCBA. Retrieved 2022-10-13.
4. ^ Downes, Stephen (Aug 18, 1999). "Fun and Games With DHTML". Stephen's Web. Retrieved 2022-08-27.
5. ^ Ferguson, Russ; Heilmann, Christian (2013). Beginning JavaScript with DOM Scripting and Ajax (PDF). Berkeley, CA: Apress. pp. 49–68\. doi:10.1007/978-1-4302-5093-7. ISBN 978-1-4302-5092-0. S2CID 20526670. Retrieved May 30, 2022.

## External links

[edit]

JavaScript/DHTML

* QuirksMode, a comprehensive site with test examples and instructions on how to write DHTML code that runs on several browsers.
* Introductory DHTML Tutorial

* v
* t
* e

Web interfaces

Server-side

Protocols|

* HTTP
* v2
* v3
* Encryption
* WebDAV
* CGI
* SCGI
* FCGI
* AJP
* WSRP
* WebSocket

Server APIs|

* C NSAPI
* C ASAPI
* C ISAPI
* COM ASP
* Jakarta Servlet
* container
* CLI OWIN
* ASP.NET Handler
* Python WSGI
* Python ASGI
* Ruby Rack
* JavaScript JSGI
* Perl PSGI
* Portlet
* container

Apache modules|

* mod_include
* mod_jk
* mod_lisp
* mod_mono
* mod_parrot
* mod_perl
* mod_php
* mod_proxy
* mod_python
* mod_wsgi
* mod_ruby
* Phusion Passenger

Topics|

* Web service vs. Web resource
* WOA vs. ROA
* Open API
* Webhook
* Application server
* comparison
* Scripting

Client-side

Browser APIs|

* C NPAPI
* LiveConnect
* XPConnect
* C NPRuntime
* C PPAPI
* NaCl
* ActiveX
* BHO
* XBAP

Web APIs|

| WHATWG|

* Audio
* Canvas
* DOM
* SSE
* Video
* WebSockets
* Web messaging
* Web storage
* Web worker
* XMLHttpRequest

|

W3C|

* DOM events
* EME
* File
* Geolocation
* IndexedDB
* MSE
* SVG
* WebAssembly
* WebAuthn
* WebGPU
* WebRTC
* WebXR

Khronos|

* WebCL
* WebGL

Others|

* Gears
* Web SQL Database (formerly W3C)
* WebUSB

Topics|

* Ajax and Remote scripting vs. DHTML
* Browser extension
* Cross-site scripting and CORS
* Hydration
* Mashup
* Persistent data
* Web IDL
* Scripting

Related topics

* Frontend and backend
* Microservices
* REST
* GraphQL
* Push technology
* Solution stack
* Web page
* Static
* Dynamic
* Web standards
* Web API security
* Web application
* Rich
* Single-page
* Progressive
* Web framework

* v
* t
* e

ECMAScript

Dialects|

* ActionScript
* Haxe
* Caja
* JavaScript
* engines
* asm.js
* JScript
* JScript .NET
* QtScript
* TypeScript
* WMLScript

Engines
(list)|

* Carakan
* Futhark
* InScript
* JavaScriptCore
* JScript
* KJS
* Linear B
* QtScript
* Rhino
* SpiderMonkey
* TraceMonkey
* JägerMonkey
* Tamarin
* V8
* ChakraCore
* Chakra
* JScript .NET
* Nashorn

Frameworks|

| Client-side|

* Dojo
* Echo
* Ext JS
* Google Web Toolkit
* jQuery
* Lively Kernel
* midori
* MochiKit
* MooTools
* Prototype
* Pyjs
* qooxdoo
*   * SproutCore
* Spry
* Wakanda Framework

|

Server-side|

* Node.js
* Deno
* Bun
* Jaxer
* AppJet
* WakandaDB

Multiple|

* Cappuccino

Libraries|

* Backbone.js
* SWFObject
* Underscore.js

People|

* Brendan Eich
* Douglas Crockford
* John Resig
* Scott Isaacs

Other|

* DHTML
* Ecma International
* JSDoc
* JSGI
* JSHint
* JSLint
* JSON
* JSSS
* Sputnik
* SunSpider
* Asynchronous module definition
* CommonJS

Lists: JavaScript libraries • Ajax frameworks • Server-side JavaScript
Comparison: JavaScript web frameworks

Authority control databases

National|

* United States
* France
* BnF data
* Czech Republic
* Spain
* Israel

Other|

* Yale LUX

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template