- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - datetime Attribute
The HTML datetime attribute is used to indicate the date and time associated with the element. It is used to specify the date and time when the text has been inserted or deleted.
The datetime attribute is used with the <del>, <ins>, and <time> tags. The value of the datetime attribute must be in a valid format with an optional time string.If the value can't be parsed as a date with an optional time string, the element is not having an associated timestamp.
Syntax
Following is the syntax of the HTML datetime attribute −
<tag datetime = "value"></tag>
Where value can be any date and time as the following format −
Year-month-day or 2023-07-11 or 2023-07-11T15:17:00
Example
In the following example, we are using the HTML ‘datetime’ attribute within the <del> tag to indicate the date and time associated with this element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <del datetime="2023-07-11T14:26:00">Text within the 'del' tag has been deleted.</del> </body> </html>
On running the above code, it will generate an output consisting of the text displayed on the webpage.
Example
Considering the another scenario, where we are going to use the datetime attribute along with the ins tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <ins datetime="2023-07-11T14:42:04">Text inserted within the 'ins' element.</ins> </body> </html>
When we run the above code, it will generate an output consisting of the text displayed on the webpage.
Example
Let's look at the following example, where we are going to use the datetime attribute along with the time tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML 'datetime' attribute</title> </head> <body> <!--HTML 'datetime' attribute--> <p>Example of the HTML 'datetime' attribute</p> <h3>'datetime' attribute with 'time' element</h3> <p>The concert is on <time datetime="2023-07-15T15:02:00">15 July</time> </p> <p>Current time is: <time datetime="2023-07-11T15:03:00" id='demo'></time> </p> <script> var d = new Date(); var h = d.getHours(); var m = d.getMinutes(); var s = d.getSeconds(); var res = document.getElementById('demo'); res.innerHTML = h + " : " + m + " : " + s; </script> </body> </html>
On executing the above script, the output window will pop up displaying the text on the webpage along with date and time.
To Continue Learning Please Login
Login with Google