Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS

JS Tutorial

JS Syntax

JS Operators

JS If Conditions

JS Loops

JS Strings

JS Numbers

JS Functions

JS Objects

JS Scope

JS Dates

JS Temporal  New

JS Arrays

JS Sets

JS Maps

JS Iterations

JS Math

JS RegExp

JS Data Types

JS Errors

JS Debugging

JS Style Guide

JS Reference

JS Projects  New

JS Versions

JS HTML DOM

JS HTML Events

JS HTML First

JS Advanced

JS Functions

JS Objects

JS Classes

JS Asynchronous

JS Modules

JS Meta & Proxy

JS Typed Arrays

JS DOM Navigation

JS Windows

JS Web API

JS AJAX

JS JSON

JS jQuery

JS Graphics

JS Examples

JS Reference


Native HTML 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>
Try it Yourself »

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>
Try it Yourself »

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">
Try it Yourself »

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>
Try it Yourself »

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>
Try it Yourself »

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">
Try it Yourself »

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


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->