🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to JavaScript Notes
Topic #156

HTML First Features

HTML has many built-in features that can replace small JavaScript solutions.

Using native HTML makes pages simpler, faster, and easier to understand.

In HTML-first development, you should always ask: Can the browser already do this?

The details Element

The <details> element creates content that users can open and close.

The visible heading is written with the <summary> element.

Example

<details>

  <summary>More information</summary>

  <p>This text is hidden until the user opens it.</p>

</details>

Note: This works without any JavaScript.


HTML Form Validation

HTML can validate form fields before a form is submitted.

You can use attributes like required, minlength, maxlength, and pattern.

Example

<form action="/register" method="post">

<label for="username">Username:</label>

<input type="text" id="username" name="username" required minlength="3">

<label for="email">Email:</label>

<input type="email" id="email" name="email" required>

<button type="submit">Register</button>

</form>

Note: The browser checks the fields automatically.


Input Types

HTML includes input types for common data.

These input types can show better keyboards on mobile devices and provide built-in validation.

  • type="email"
  • type="number"
  • type="date"
  • type="url"
  • type="search"

Example

<label for="birthday">Birthday:</label>

<input type="date" id="birthday" name="birthday">

The datalist Element

The <datalist> element gives users a list of suggested values.

The user can choose a suggestion or type another value.

Example

<label for="browser">Choose a browser:</label>

<input list="browsers" id="browser" name="browser">

<datalist id="browsers">

  <option value="Chrome">

  <option value="Firefox">

  <option value="Safari">

  <option value="Edge">

</datalist>

The dialog Element

The <dialog> element can be used for dialog boxes and popups.

Opening and closing dialogs usually needs a small amount of JavaScript, but the dialog behavior is built into the browser.

Example

<dialog open>

  <p>This is an open dialog window.</p>

</dialog>

Lazy Loading Images

Images can be lazy loaded with the loading attribute.

This can improve performance by loading images only when they are needed.

Modern browsers support a loading="lazy" attribute for <img> and <iframe> elements. This tells the browser to defer loading the resource until the user scrolls near it.

Example

<!-- The browser handles the timing here -->

<img src="image.jpg" alt="A mountain" loading="lazy">

Note: Use native HTML first. Add JavaScript only when native HTML cannot solve the problem.

Want to go beyond the notes?

Join CodingNow 2.0's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

HTML First Features – FAQs

Quick answers about learning HTML First Features in JavaScript.

This free note from CodingNow 2.0 explains HTML First Features in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on CodingNow 2.0, including HTML First Features, is 100% free with no signup required.
With focused practice, most students grasp HTML First Features in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now