CSS Portal

HTML min Attribute

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The HTML min attribute specifies the minimum value for an <input> element. It is used to set a lower bound on the values that users can enter or select, ensuring the input stays within a defined range. The applicability of the min attribute depends on the type of input. For example:

  • Date and time inputs: For <input> elements with type="date", type="month", type="week", type="time", type="datetime-local", the min attribute specifies the earliest date or time that a user can select.
  • Number and range inputs: For <input> elements with type="number" or type="range", it defines the minimum numeric value that can be entered.

This attribute is particularly useful for ensuring that user inputs meet certain requirements, such as age restrictions or setting up a feasible range for numerical data. If a user attempts to submit a value below the minimum, the form will not validate, prompting the user to adjust their input accordingly.

Here's an example usage for a date input, ensuring that the user cannot select a date before January 1, 2020:

<input type="date" name="start-date" min="2020-01-01">

And here's an example for a number input, setting the minimum allowable number to 10:

<input type="number" name="quantity" min="10">

It's important to note that while the min attribute can help guide user input, additional server-side validation should always be implemented to ensure data integrity and security, as client-side controls can be bypassed.

Syntax

<input min="number | datetime">

Values

  • numberThe minimum numeric value in an input field.
  • datetimeThe minimum datetime value in an input field.

Applies To

Example

<form action="formscript.php">
Enter a number between 1 and 10:
<input type="number" id="quantity" name="quantity" min="1" max="10">
<br>
<button type="submit">Submit</button>
</form>

Browser Support

The following information will show you the current browser support for the HTML min attribute. Hover over a browser icon to see the version that first introduced support for this HTML attribute.

This attribute is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 26th March 2024

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!