codegurukool.com · Free coding tutorials & online compiler

Home › JavaScript Tutorial › JS HTML first

JS HTML first

Use HTML features before JavaScript.

Many tasks need no script: details for toggles, dialog, popover, required validation and CSS :target. Add JavaScript only for what HTML cannot do.

Commands in this lesson

required

Definition: Attribute that forces a field to be filled before submit.

Syntax:

<input required>

Example:

<form><input required><button>Send</button></form>

Example code

<details><summary>Open me</summary>Hidden content, no JavaScript.</details>
<br><button popovertarget='p'>Popover</button>
<div id='p' popover style='padding:12px'>Also no JavaScript</div>

Run this code in the online editor

← JS JSONPJS project: counter →