Open In App

How to Set input type date in dd-mm-yyyy format using HTML?

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In HTML, you can use the <input> element with the type date to allow users to pick a date. However, the format used for displaying the date may vary depending on the browser and the user’s locale settings. By default, the browser uses the ISO format (yyyy-mm-dd), which is not the same as dd-mm-yyyy. Unfortunately, HTML itself doesn’t provide a way to directly set the date format to dd-mm-yyyy using the <input type=”date”> element.

Note: The default values for the min and max attributes are min=”01-01-1920″ and max=”01-01-2120″.

Using the type=”date” Attribute

The type=”date” attribute generates a date picker in compliant browsers. The displayed date format, however, isn’t consistent across all browsers and might differ depending on the browser’s settings.

Syntax

<input type="date">

Example 1: Basic Date Input

In this example, we set the input type as date, allowing users to pick a date from a calendar. However, the format of the date may vary depending on the user’s browser.

HTML
<html>
<head>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>
<body>
    <h3>Setting Input Type Date in dd-mm-yyyy Format</h3>
    <label for="start">Enter the Date:</label>
    <!-- Date input field -->
    <input type="date" id="start" name="begin" value="" min="1997-01-01" max="2030-12-31">
</body>
</html>

Output:

input-type-date-in-dd-mm-yyyy-format-in-HTML

input type date in dd-mm-yyyy format using HTML Example Output

In this Example

  • min=”1997-01-01″ and max=”2030-12-31″ define the date range that users can choose from.
  • The format for the input field is displayed based on the browser’s locale and cannot be controlled directly with HTML alone.

Example 2: Date Picker with Range Attribute

In this example, we set a date picker where the range is defined using the min and max attributes, which restricts the user to selecting dates within this range. The date format is still determined by the browser and is typically in yyyy-mm-dd format.

HTML
<html>
<head>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>

<body>
    <h3>Setting Input Type Date in dd-mm-yyyy Format</h3>
    <label for="start">
        Enter the Date:
    </label>
    <!-- Date input field -->
    <input type="date" name="begin" value="" min="1997-01-01" max="2030-12-31">

</body>
</html>

Output:

input-type-date-in-dd-mm-yyyy-format-in-HTML

input type date in dd-mm-yyyy format using HTML Example Output

In this Example

  • min=”1997-01-01″: This restricts the user to selecting dates from January 1, 1997.
  • max=”2030-12-31″: This limits the user to selecting dates before December 31, 2030.
  • placeholder=”dd-mm-yyyy”: This is just a visual hint, but the date format will not enforce dd-mm-yyyy.


Similar Reads