Grow your CSS skills. Land your dream job.

Changing the Default Base Step for HTML5 Date Inputs

  • # February 6, 2013 at 8:53 am

    Hello All,

    I was messing around with the new HTML5 input elements, in particular the [date element](http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#date-state-(type=date) “”). I constructed the element like so:

    The default base for date elements is the epoch or 1970-01-01 in this case. However, most browsers will change the default base either to the max or the min element if they are valid date strings.

    This is where it gets tricky, because the spec doesn’t specify when max or min should be used, at least that I can find.

    In the latest version of Opera, the above field could have a valid value of “1970-01-02″, because Opera changes the default step to 1970-01-04 and 1970-01-02 is -2 days away, which is an even modulo of the step (-2 % 2 == 0). In Chrome it is **NOT** a valid date, because the default base remains “1970-01-01″ and that leaves us +3 days away, which is an odd modulo of the step (3 % 2 == 1).

    Which browser is in the right? I’m leaning towards Opera. It seems to be that the max attribute should be used unless a min attribute is provided, in which that should be used as the default step. If neither are present, use 1970-01-01.

    Any ideas or thoughts? I’ve added this to the spec [bug tracker](https://www.w3.org/Bugs/Public/show_bug.cgi?id=20880 “Bug Tracker”)
    so hopefully they’ll be able to provide some clarity.

    # February 6, 2013 at 2:27 pm

    Answered my own question, looks like Chrome is the one in the right: [Step Attribute](http://www.whatwg.org/specs/web-apps/current-work/multipage/common-input-element-attributes.html#attr-input-step “”)

    Only the min attribute can change the default step, not the max.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".