What you're doing wrong:
The HTML spec doesn't support the range of weekdays and hours you're trying to represent. Your markup is not strictly valid HTML, however you could say it is valid HTML + Schema.org (although there is no explicit standard for this).
The time
element is for a specific date, time, and/or timezone data. It can also be used for a duration (the runtime of a movie, as a real-world example, which could look like 2h 11m 33s
). There is no valid value outlined in the spec that supports a range of days and times.
The Semantics section of the HTML spec describes the usage of time
and valid values for the datetime
attribute. Here are a few examples of acceptable values:
Valid date string: 2011-11-18
Valid local date and time string: 2011-11-18T14:54
Valid week string: 2011-W47
Valid duration string: PT4H18M3S
Valid time-zone offset string: -08:00
Among many others, none of which are useful or appropriate for your specific use case.
What you can do:
You could try using <data>
instead of <time>
, such as:
<div itemscope itemtype="https://schema.org/LocalBusiness">
<p>Office Hours:</p>
<p><data itemprop="openingHours" value="Mo-Fr 09:00-19:00">Monday-Friday: 9:00 am to 7:00 pm</data></p>
<p><data itemprop="openingHours" value="Sa 10:00-17:00">Saturdays: 10:00 am to 5:00 pm</data></p>
<p><data itemprop="openingHours" value="Su 11:00-16:00">Sundays: 11:00 am to 4:00 pm</data></p>
</div>
Which will validate, however it's skirting the rules for time-based data (the spec wants you to use <time>
) and you've now sacrificed semantics for superfluous validation.
Also note the itemscope and itemtype in the containing <div>
.
My general opinion:
I would personally stick with the example that Schema.org outlines using <time>
with the datetime
attribute. But the above example in theory should work just fine.
This is a good illustration of why I try not to sweat over perfect validation. Validation is a useful debugging tool and quality check, and is important for teaching good markup practices. It's also important to know what valid HTML looks like and using the validator is useful to learn the "rules" of HTML — part of that being so that you know when it's acceptable to bend those rules to work for your specific use case.
Basically: don't sweat it. The benefit of using Schema.org outweighs the cost of these few lines of invalid markup.
Office Hours:
-
...`