Cant HTML be used for client side event handling??? can someone please explain why!!

Dani AI

Generated

As and already hinted, you do not write procedural event handlers in raw HTML. Modern HTML and CSS do, however, provide several declarative, browser-handled interactions that cover a lot of common needs without adding JavaScript — useful for simple disclosure widgets, form validation, and basic visual interactivity.

A few practical, widely supported examples you can use today:

  • The <details> / <summary> pair creates a toggle the browser manages.
  • Native input types and attributes (type=email, required, pattern, min/max) surface built-in validation and UI.
  • Elements like <dialog>, <progress>/<meter>, anchors (mailto:, tel:) and CSS pseudo-classes (:hover, :focus, :target) provide interaction without scripts.

A tiny example that needs no JavaScript:

<details>
  <summary>More info</summary>
  <p>Hidden content shown by the browser, no JS required.</p>
</details>

When you need custom logic (rich state, coordinated components, complex keyboard handling), add unobtrusive JavaScript: keep markup semantic, attach handlers via addEventListener, and layer ARIA as needed so keyboard and assistive tech still work. For reference on built-in behaviors and constraints see the MDN pages for the details element and form validation.

Recommended Answers

All 2 Replies

HTML is a static markup language. It has no support for events, just layout.

pritaeas is right, HTML is just that. HyperText Markup Language. It allows you to semantically markup your content. Events are a browser and UI thing and are basically the realm of Javascript. That being said what are you doing that you need events for. JS is pretty common and you can probably use it to achieve your goals

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.