Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • HTML Tutorial
  • HTML Exercises
  • HTML Tags
  • HTML Attributes
  • Global Attributes
  • Event Attributes
  • HTML Interview Questions
  • HTML DOM
  • DOM Audio/Video
  • HTML 5
  • HTML Examples
  • Color Picker
  • A to Z Guide
  • HTML Formatter
Open In App
Next Article:
How to set float input type in HTML5 ?
Next article icon

How to set Placeholder Value for Input Type Date in HTML?

Last Updated : 17 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

To set a placeholder value for the input type date in HTML5, use the placeholder attribute. The placeholder attribute doesn’t work well with input type “date.” Use onfocus="(this.type='date')" for a custom placeholder, enabling a date selection dropdown.

Using Onfocus

The On-focus approach changes the input type from text to date when the field gains focus, allowing users to see and use the date picker. This technique enables the use of a custom placeholder, providing format guidance before the date picker is activated.

Syntax:

onfocus="(this.type='date')"

Example: To demonstrate setting placeholder values for input type date.

html
<!DOCTYPE html> <html>  <head>     <title>         Placeholder value for         input type="Date"     </title> </head>  <body style="text-align:center;">      <h1 style="color:green;">GeeksforGeeks</h1>      <h4>Placeholder value for input type="Date"</h4>      <!-- using onfocus="(this.type='date')" -->     Starting Date:     <input type="text"             placeholder="MM/DD/YYYY" onfocus="(this.type='date')">      <!-- Not using onfocus="(this.type='date')" -->     Ending Date:     <input type="date" placeholder="MM/DD/YYYY"> </body>  </html> 

Output: 

date

Output

Using Onblur

The On-blur approach reverts the input type back to text when the field loses focus. This ensures that after the date is selected, the custom placeholder is displayed again, maintaining the intended format guidance for the user.

Example: To demonstrate loosing focus on the date and the date field as it changes back to a text field. 

html
<!DOCTYPE html> <html>  <head>     <title>         Placeholder value for input type="Date"     </title> </head>  <body style="text-align:center;">      <h1 style="color:green;">GeeksforGeeks</h1>      <h4>Placeholder value for input type="Date"</h4>      <!-- using onfocus="(this.type='date')" -->     Starting Date:     <input type="text"             placeholder="MM/DD/YYYY"            onfocus="(this.type='date')"            onblur="(this.type='text')">      <!-- Not using onfocus="(this.type='date')" -->     Ending Date:     <input type="text" placeholder="MM/DD/YYYY"> </body>  </html> 

Output: 

video2222

  • As we can see, we can modify the placeholder text as needed. On one click, we get the standard date input field, and we can enter the date:
  • After entering the date, it looks as follows:
  • Upon losing focus, it changes back to a text field due to the onblur event we have introduced:

Setting a placeholder value for an `input` element with `type=”date”` in HTML5 allows developers to provide users with a hint or example of the date format expected. This feature is particularly useful for enhancing user experience by guiding them on how to input dates correctly without relying solely on labels or additional instructions.

HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps. You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.



Next Article
How to set float input type in HTML5 ?

A

ArkaSeth
Improve
Article Tags :
  • HTML
  • Web Technologies
  • JavaScript-Misc
  • JavaScript-Questions

Similar Reads

  • How to Set input type date in dd-mm-yyyy format using HTML?
    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
    2 min read
  • How to set float input type in HTML5 ?
    HTML5 is the latest version of Hypertext Markup Language (HTML), the standard language for creating web pages and web applications. With HTML5, new input types were introduced to make web form creation easier and more accessible. These input types include text, password, checkbox, radio, submit, res
    3 min read
  • How to use placeholder attribute in HTML ?
    We know that the placeholder attribute is used to define a hint of what value has to be entered on the input and textarea field. This attribute is used for a better understanding of form structure. It contains a string value that represents the short hint that describes the expected value of an inpu
    1 min read
  • How to Change input type="date" Format in HTML ?
    The <input> element with type="date" is used to allow the user to choose a date. By default, the date format displayed in the input field is determined by the user's browser and operating system settings. However, it is possible to change the format of the date displayed in the input field usi
    4 min read
  • HTML | DOM Input Date value Property
    The Input Date value property is used for setting or returning the value of the value attribute of a date field. The Input Date value attribute can be used for specifying a date for the date field.Syntax: For returning the value property: inputdateObject.valueFor setting the value property: inputdat
    2 min read
  • HTML DOM Input Tel placeholder Property
    The input tel placeholder property in HTML DOM is used to set or return the value of the placeholder attribute of an input tel field. The placeholder attribute specifies the short hint that describes the expected value of an input field. The short hint is displayed in the field before the user enter
    2 min read
  • How to align Placeholder Text in HTML ?
    The placeholder attribute specifies a short hint that describes the expected value of an input field/text area. The short hint is displayed in the field before the user enters a value. In most of the browsers, placeholder texts are usually aligned on the left. The selector uses the text-align proper
    2 min read
  • HTML | DOM Input URL placeholder Property
    The DOM Input URL placeholder Property is used to set or return the value of the Placeholder attribute of a URL Field.The placeholder attribute specifies a short hint as a text in the input field that describes the expected value. Syntax: It is used to return the placeholder property. urlObject.plac
    2 min read
  • HTML | DOM Input Datetime value Property
    The Input Datetime value property is used for setting or returning the value of the value attribute of a datetime field. The Input Datetime value attribute can be used for specifying a date and time for the datetime field. Syntax: For returning the value property:datetimeObject.valueFor setting the
    2 min read
  • HTML | DOM Input Date type Property
    The Input Date type property is used for returning the type of form element the date field is. The Input Date type property returns a string that represents the type of form element the date field is. Syntax: inputdateObject.type Return Values: It returns a string value that represents the type of f
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences