Javascript Reference - HTML DOM Input Time autofocus Property

The autofocus property sets or gets whether a time field can auto focus when the page loads.

Browser Support

autofocus Yes No No Yes Yes


Return the autofocus property.

var v = timeObject.autofocus 

Set the autofocus property.


Property Values

Value Description
true|false Set whether a time field can auto focus when the page loads
  • true - The time field gets focus
  • false - Default. The time field does not get focus

Return Value

A Boolean type value, true if the time field automatically gets focus when the page loads, otherwise false.


The following code shows how to get if a time field can auto focus upon page load.

<!DOCTYPE html>
<!--from  w  w w  . j  ava 2s  .  c  om-->
<input type="time" id="myTime" autofocus>
<button onclick="myFunction()">test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myTime").autofocus;
    document.getElementById("demo").innerHTML = x;


The code above is rendered as follows: