1. 2.3Common microsyntaxes
      1. 2.3.1Common parser idioms
      2. 2.3.2Boolean attributes
      3. 2.3.3Keywords and enumerated attributes
      4. 2.3.4Numbers
        1. 2.3.4.1Signed integers
        2. 2.3.4.2Non-negative integers
        3. 2.3.4.3Floating-point numbers
        4. 2.3.4.4Percentages and lengths
        5. 2.3.4.5Nonzero percentages and lengths
        6. 2.3.4.6Lists of floating-point numbers
        7. 2.3.4.7Lists of dimensions
      5. 2.3.5Dates and times
        1. 2.3.5.1Months
        2. 2.3.5.2Dates
        3. 2.3.5.3Yearless dates
        4. 2.3.5.4Times
        5. 2.3.5.5Local dates and times
        6. 2.3.5.6Time zones
        7. 2.3.5.7Global dates and times
        8. 2.3.5.8Weeks
        9. 2.3.5.9Durations
        10. 2.3.5.10Vaguer moments in time
      6. 2.3.6Colors
      7. 2.3.7Space-separated tokens
      8. 2.3.8Comma-separated tokens
      9. 2.3.9References
      10. 2.3.10Media queries
      11. 2.3.11Unique internal values

2.3Common microsyntaxes

There are various places in HTML that accept particular data types, such as dates or numbers. This section describes what the conformance criteria for content in those formats is, and how to parse them.

Implementers are strongly urged to carefully examine any third-party libraries they might consider using to implement the parsing of syntaxes described below. For example, date libraries are likely to implement error handling behavior that differs from what is required in this specification, since error-handling behavior is often not defined in specifications that describe date syntaxes similar to those used in this specification, and thus implementations tend to vary greatly in how they handle errors.

2.3.1Common parser idioms

Some of the micro-parsers described below follow the pattern of having aninput variable that holds the string being parsed, and having apositionvariable pointing at the next character to parse ininput.

2.3.2Boolean attributes

A number of attributes areboolean attributes.The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitivematch for the attribute's canonical name, with no leading or trailing whitespace.

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

Here is an example of a checkbox that is checked and disabled. Thecheckedanddisabled attributes are the boolean attributes.

<label><inputtype=checkboxcheckedname=cheesedisabled>Cheese</label>

This could be equivalently written as this:

<label><inputtype=checkboxchecked=checkedname=cheesedisabled=disabled>Cheese</label>

You can also mix styles; the following is still equivalent:

<label><inputtype='checkbox'checkedname=cheesedisabled="">Cheese</label>

2.3.3Keywords and enumerated attributes

Some attributes, calledenumerated attributes,take on a finite set of states. The state for such an attribute is derived by combining the attribute's value, a set of keyword/state mappings given in the specification of each attribute, and two possible special states that can also be given in the specification of the attribute. These special states are theinvalid value defaultand themissing value default.

Multiple keywords can map to the same state.

The empty string can be a valid keyword. Note that themissing value defaultapplies only when the attribute ismissing,not when it is present with an empty string value.

To determine the state of an attribute, use the following steps:

  1. If the attribute is not specified:

    1. If the attribute has amissing value default state defined, then return thatmissing value default state.

    2. Otherwise, return no state.

  2. If the attribute's value is anASCII case-insensitivematch for one of the keywords defined for the attribute, then return the state represented by that keyword.

  3. If the attribute has aninvalid value defaultstate defined, then return thatinvalid value default state.

  4. Return no state.

For authoring conformance purposes, if an enumerated attribute is specified, the attribute's value must be anASCII case-insensitivematch for one of the conforming keywords for that attribute, with no leading or trailing whitespace.

Forreflectionpurposes, states which have any keywords mapping to them are said to have acanonical keyword.This is determined as follows:

2.3.4Numbers

2.3.4.1Signed integers

A string is avalid integerif it consists of one or moreASCII digits, optionally prefixed with a U+002D HYPHEN-MINUS character (-).

Avalid integerwithout a U+002D HYPHEN-MINUS (-) prefix represents the number that is represented in base ten by that string of digits. Avalid integer witha U+002D HYPHEN-MINUS (-) prefix represents the number represented in base ten by the string of digits that follows the U+002D HYPHEN-MINUS, subtracted from zero.

Therules for parsing integersare as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either an integer or an error.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Letsignhave the value "positive".

  4. Skip ASCII whitespacewithininputgiven position.

  5. Ifpositionis past the end ofinput,return an error.

  6. If the character indicated byposition(the first character) is a U+002D HYPHEN-MINUS character (-):

    1. Letsignbe "negative".
    2. Advancepositionto the next character.
    3. Ifpositionis past the end ofinput,return an error.

    Otherwise, if the character indicated byposition(the first character) is a U+002B PLUS SIGN character (+):

    1. Advancepositionto the next character. (The "+"is ignored, but it is not conforming.)
    2. Ifpositionis past the end ofinput,return an error.
  7. If the character indicated bypositionis not anASCII digit,then return an error.

  8. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition,and interpret the resulting sequence as a base-ten integer. Letvaluebe that integer.

  9. Ifsignis "positive", returnvalue,otherwise return the result of subtractingvaluefrom zero.

2.3.4.2Non-negative integers

A string is avalid non-negative integerif it consists of one or moreASCII digits.

Avalid non-negative integerrepresents the number that is represented in base ten by that string of digits.

Therules for parsing non-negative integersare as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either zero, a positive integer, or an error.

  1. Letinputbe the string being parsed.

  2. Letvaluebe the result of parsinginputusing the rules for parsing integers.

  3. Ifvalueis an error, return an error.

  4. Ifvalueis less than zero, return an error.

  5. Returnvalue.

2.3.4.3Floating-point numbers

A string is avalid floating-point numberif it consists of:

  1. Optionally, a U+002D HYPHEN-MINUS character (-).

  2. One or both of the following, in the given order:

    1. A series of one or moreASCII digits.

    2. Both of the following, in the given order:

      1. A single U+002E FULL STOP character (.).

      2. A series of one or moreASCII digits.

  3. Optionally:

    1. Either a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E).

    2. Optionally, a U+002D HYPHEN-MINUS character (-) or U+002B PLUS SIGN character (+).

    3. A series of one or moreASCII digits.

Avalid floating-point numberrepresents the number obtained by multiplying the significand by ten raised to the power of the exponent, where the significand is the first number, interpreted as base ten (including the decimal point and the number after the decimal point, if any, and interpreting the significand as a negative number if the whole string starts with a U+002D HYPHEN-MINUS character (-) and the number is not zero), and where the exponent is the number after the E, if any (interpreted as a negative number if there is a U+002D HYPHEN-MINUS character (-) between the E and the number and the number is not zero, or else ignoring a U+002B PLUS SIGN character (+) between the E and the number if there is one). If there is no E, then the exponent is treated as zero.

The Infinity and Not-a-Number (NaN) values are notvalid floating-point numbers.

Thevalid floating-point numberconcept is typically only used to restrict what is allowed for authors, while the user agent requirements use therules for parsing floating-point number valuesbelow (e.g., themaxattribute of theprogresselement). However, in some cases the user agent requirements include checking if a string is avalid floating-point number(e.g., thevalue sanitization algorithmfor theNumberstate of theinputelement, or the parse a srcset attributealgorithm).

Thebest representation of the numbernas a floating-point numberis the string obtained from runningToString(n). The abstract operation ToStringis not uniquely determined. When there are multiple possible strings that could be obtained fromToStringfor a particular value, the user agent must always return the same string for that value (though it may differ from the value used by other user agents).

Therules for parsing floating-point number valuesare as given in the following algorithm. This algorithm must be aborted at the first step that returns something. This algorithm will return either a number or an error.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Letvaluehave the value 1.

  4. Letdivisorhave the value 1.

  5. Letexponenthave the value 1.

  6. Skip ASCII whitespacewithininputgiven position.

  7. Ifpositionis past the end ofinput,return an error.

  8. If the character indicated bypositionis a U+002D HYPHEN-MINUS character (-):

    1. Changevalueanddivisorto −1.
    2. Advancepositionto the next character.
    3. Ifpositionis past the end ofinput,return an error.

    Otherwise, if the character indicated byposition(the first character) is a U+002B PLUS SIGN character (+):

    1. Advancepositionto the next character. (The "+" is ignored, but it is not conforming.)
    2. Ifpositionis past the end ofinput,return an error.
  9. If the character indicated bypositionis a U+002E FULL STOP (.), and that is not the last character ininput,and the character after the character indicated by positionis anASCII digit,then set valueto zero and jump to the step labeledfraction.

  10. If the character indicated bypositionis not anASCII digit,then return an error.

  11. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition,and interpret the resulting sequence as a base-ten integer. Multiplyvalueby that integer.

  12. Ifpositionis past the end ofinput,jump to the step labeled conversion.
  13. Fraction:If the character indicated bypositionis a U+002E FULL STOP (.), run these substeps:

    1. Advancepositionto the next character.

    2. Ifpositionis past the end ofinput,or if the character indicated bypositionis not anASCII digit, U+0065 LATIN SMALL LETTER E (e), or U+0045 LATIN CAPITAL LETTER E (E), then jump to the step labeledconversion.

    3. If the character indicated bypositionis a U+0065 LATIN SMALL LETTER E character (e) or a U+0045 LATIN CAPITAL LETTER E character (E), skip the remainder of these substeps.

    4. Fraction loop:Multiplydivisorby ten.

    5. Add the value of the character indicated byposition,interpreted as a base-ten digit (0..9) and divided bydivisor,tovalue.
    6. Advancepositionto the next character.

    7. Ifpositionis past the end ofinput,then jump to the step labeledconversion.

    8. If the character indicated bypositionis anASCII digit,jump back to the step labeledfraction loopin these substeps.

  14. If the character indicated bypositionis U+0065 (e) or a U+0045 (E), then:

    1. Advancepositionto the next character.

    2. Ifpositionis past the end ofinput,then jump to the step labeledconversion.

    3. If the character indicated bypositionis a U+002D HYPHEN-MINUS character (-):

      1. Changeexponentto −1.
      2. Advancepositionto the next character.
      3. Ifpositionis past the end ofinput,then jump to the step labeledconversion.

      Otherwise, if the character indicated bypositionis a U+002B PLUS SIGN character (+):

      1. Advancepositionto the next character.
      2. Ifpositionis past the end ofinput,then jump to the step labeledconversion.

    4. If the character indicated bypositionis not anASCII digit,then jump to the step labeledconversion.

    5. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition,and interpret the resulting sequence as a base-ten integer. Multiplyexponentby that integer.

    6. Multiplyvalueby ten raised to theexponentth power.

  15. Conversion:LetSbe the set of finite IEEE 754 double-precision floating-point values except −0, but with two special values added: 21024and −21024.

  16. Letrounded-valuebe the number inSthat is closest to value,selecting the number with an even significand if there are two equally close values. (The two special values 21024and −21024 are considered to have even significands for this purpose.)

  17. Ifrounded-valueis 21024or −21024,return an error.

  18. Returnrounded-value.

2.3.4.4Percentages and lengths

Therules for parsing dimension valuesare as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a number greater than or equal to 0.0, or failure; if a number is returned, then it is further categorized as either a percentage or a length.

  1. Letinputbe the string being parsed.

  2. Letpositionbe aposition variableforinput, initially pointing at the start ofinput.

  3. Skip ASCII whitespacewithininputgiven position.

  4. Ifpositionis past the end ofinputor the code point at positionwithininputis not anASCII digit,then return failure.

  5. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition,and interpret the resulting sequence as a base-ten integer. Letvaluebe that number.

  6. Ifpositionis past the end ofinput,then returnvalue as a length.

  7. If the code point atpositionwithininputis U+002E (.), then:

    1. Advancepositionby 1.

    2. Ifpositionis past the end ofinputor the code point at positionwithininputis not anASCII digit,then return thecurrent dimension valuewithvalue, input,andposition.

    3. Letdivisorhave the value 1.

    4. While true:

      1. Multiplydivisorby ten.

      2. Add the value of the code point atpositionwithininput, interpreted as a base-ten digit (0..9) and divided bydivisor,to value.

      3. Advancepositionby 1.

      4. Ifpositionis past the end ofinput,then return valueas a length.

      5. If the code point atpositionwithininputis not anASCII digit,thenbreak.

  8. Return thecurrent dimension valuewithvalue,input, andposition.

Thecurrent dimension value,givenvalue,input,and position,is determined as follows:

  1. Ifpositionis past the end ofinput,then returnvalue as a length.

  2. If the code point atpositionwithininputis U+0025 (%), then returnvalueas a percentage.

  3. Returnvalueas a length.

2.3.4.5Nonzero percentages and lengths

Therules for parsing nonzero dimension valuesare as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either a number greater than 0.0, or an error; if a number is returned, then it is further categorized as either a percentage or a length.

  1. Letinputbe the string being parsed.

  2. Letvaluebe the result of parsinginputusing therules for parsing dimension values.

  3. Ifvalueis an error, return an error.

  4. Ifvalueis zero, return an error.

  5. Ifvalueis a percentage, returnvalueas a percentage.

  6. Returnvalueas a length.

2.3.4.6Lists of floating-point numbers

Avalid list of floating-point numbersis a number ofvalid floating-point numbersseparated by U+002C COMMA characters, with no other characters (e.g. noASCII whitespace). In addition, there might be restrictions on the number of floating-point numbers that can be given, or on the range of values allowed.

Therules for parsing a list of floating-point numbersare as follows:

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Letnumbersbe an initially empty list of floating-point numbers. This list will be the result of this algorithm.

  4. Collect a sequence of code pointsthat areASCII whitespace, U+002C COMMA, or U+003B SEMICOLON characters frominputgivenposition. This skips past any leading delimiters.

  5. Whilepositionis not past the end ofinput:

    1. Collect a sequence of code pointsthat are notASCII whitespace,U+002C COMMA, U+003B SEMICOLON,ASCII digits,U+002E FULL STOP, or U+002D HYPHEN-MINUS characters frominputgivenposition.This skips past leading garbage.

    2. Collect a sequence of code pointsthat are notASCII whitespace,U+002C COMMA, or U+003B SEMICOLON characters frominputgiven position,and letunparsed numberbe the result.

    3. Letnumberbe the result of parsingunparsed numberusing the rules for parsing floating-point number values.

    4. Ifnumberis an error, setnumberto zero.

    5. Appendnumbertonumbers.

    6. Collect a sequence of code pointsthat areASCII whitespace, U+002C COMMA, or U+003B SEMICOLON characters frominputgivenposition. This skips past the delimiter.

  6. Returnnumbers.

2.3.4.7Lists of dimensions

Therules for parsing a list of dimensionsare as follows. These rules return a list of zero or more pairs consisting of a number and a unit, the unit being one ofpercentage, relative,andabsolute.

  1. Letraw inputbe the string being parsed.

  2. If the last character inraw inputis a U+002C COMMA character (,), then remove that character fromraw input.

  3. Split the stringraw inputon commas.Letraw tokensbe the resulting list of tokens.

  4. Letresultbe an empty list of number/unit pairs.

  5. For each token inraw tokens,run the following substeps:

    1. Letinputbe the token.

    2. Letpositionbe a pointer intoinput, initially pointing at the start of the string.

    3. Letvaluebe the number 0.

    4. Letunitbeabsolute.

    5. Ifpositionis past the end ofinput,setunittorelativeand jump to the last substep.

    6. If the character atpositionis anASCII digit,collect a sequence of code pointsthat areASCII digitsfrominputgivenposition,interpret the resulting sequence as an integer in base ten, and incrementvalueby that integer.

    7. If the character atpositionis U+002E (.), then:

      1. Collect a sequence of code pointsconsisting ofASCII whitespaceandASCII digitsfrominputgiven position.Letsbe the resulting sequence.

      2. Remove allASCII whitespaceins.

      3. Ifsis not the empty string, then:

        1. Letlengthbe the number of characters ins(after the spaces were removed).

        2. Letfractionbe the result of interpretingsas a base-ten integer, and then dividing that number by10length.

        3. Incrementvaluebyfraction.

    8. Skip ASCII whitespacewithininputgiven position.

    9. If the character atpositionis a U+0025 PERCENT SIGN character (%), then setunittopercentage.

      Otherwise, if the character atpositionis a U+002A ASTERISK character (*), then setunittorelative.

    10. Add an entry toresultconsisting of the number given byvalueand the unit given byunit.

  6. Return the listresult.

2.3.5Dates and times

In the algorithms below, thenumber of days in monthmonthof year yearis:31ifmonthis 1, 3, 5, 7, 8, 10, or 12;30ifmonthis 4, 6, 9, or 11;29ifmonthis 2 andyearis a number divisible by 400, or ifyearis a number divisible by 4 but not by 100; and28otherwise. This takes into account leap years in the Gregorian calendar.[GREGORIAN]

WhenASCII digitsare used in the date and time syntaxes defined in this section, they express numbers in base ten.

While the formats described here are intended to be subsets of the corresponding ISO8601 formats, this specification defines parsing rules in much more detail than ISO8601. Implementers are therefore encouraged to carefully examine any date parsing libraries before using them to implement the parsing rules described below; ISO8601 libraries might not parse dates and times in exactly the same manner.[ISO8601]

Where this specification refers to theproleptic Gregorian calendar,it means the modern Gregorian calendar, extrapolated backwards to year 1. A date in theproleptic Gregorian calendar,sometimes explicitly referred to as aproleptic-Gregorian date,is one that is described using that calendar even if that calendar was not in use at the time (or place) in question.[GREGORIAN]

The use of the Gregorian calendar as the wire format in this specification is an arbitrary choice resulting from the cultural biases of those involved in the decision. See also the section discussingdate, time, and number formatsin forms (for authors),implementation notes regarding localization of form controls,and thetimeelement.

2.3.5.1Months

Amonthconsists of a specificproleptic-Gregorian datewith no time-zone information and no date information beyond a year and a month. [GREGORIAN]

A string is avalid month stringrepresenting a yearyearand monthmonthif it consists of the following components in the given order:

  1. Four or moreASCII digits,representingyear,whereyear> 0
  2. A U+002D HYPHEN-MINUS character (-)
  3. TwoASCII digits,representing the monthmonth,in the range 1 ≤month≤ 12

The rules toparse a month stringare as follows. This will return either a year and month, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a month componentto obtainyearandmonth.If this returns nothing, then fail.

  4. Ifpositionisnotbeyond the end ofinput,then fail.

  5. Returnyearandmonth.

The rules toparse a month component,given aninputstring and aposition,are as follows. This will return either a year and a month, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not at least four characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theyear.

  2. Ifyearis not a number greater than zero, then fail.

  3. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+002D HYPHEN-MINUS character, then fail. Otherwise, movepositionforwards one character.

  4. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be themonth.

  5. Ifmonthis not a number in the range 1 ≤month≤ 12, then fail.

  6. Returnyearandmonth.

2.3.5.2Dates

Adateconsists of a specificproleptic-Gregorian datewith no time-zone information, consisting of a year, a month, and a day. [GREGORIAN]

A string is avalid date stringrepresenting a yearyear,month month,and daydayif it consists of the following components in the given order:

  1. Avalid month string,representingyearandmonth
  2. A U+002D HYPHEN-MINUS character (-)
  3. TwoASCII digits,representingday,in the range 1 ≤daymaxdaywheremaxdayis thenumber of days in the monthmonthand yearyear

The rules toparse a date stringare as follows. This will return either a date, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a date componentto obtainyear,month,andday.If this returns nothing, then fail.

  4. Ifpositionisnotbeyond the end ofinput,then fail.

  5. Letdatebe the date with yearyear,monthmonth,and dayday.

  6. Returndate.

The rules toparse a date component,given aninputstring and a position,are as follows. This will return either a year, a month, and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Parse a month componentto obtainyearandmonth.If this returns nothing, then fail.

  2. Letmaxdaybe thenumber of days in monthmonthof yearyear.

  3. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+002D HYPHEN-MINUS character, then fail. Otherwise, movepositionforwards one character.

  4. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theday.

  5. Ifdayis not a number in the range 1 ≤daymaxday,then fail.

  6. Returnyear,month,andday.

2.3.5.3Yearless dates

Ayearless dateconsists of a Gregorian month and a day within that month, but with no associated year.[GREGORIAN]

A string is avalid yearless date stringrepresenting a monthmonthand a daydayif it consists of the following components in the given order:

  1. Optionally, two U+002D HYPHEN-MINUS characters (-)
  2. TwoASCII digits,representing the monthmonth,in the range 1 ≤month≤ 12
  3. A U+002D HYPHEN-MINUS character (-)
  4. TwoASCII digits,representingday,in the range 1 ≤daymaxdaywheremaxdayis thenumber of daysin the monthmonthand any arbitrary leap year (e.g. 4 or 2000)

In other words, if themonthis "02", meaning February, then the day can be 29, as if the year was a leap year.

The rules toparse a yearless date stringare as follows. This will return either a month and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a yearless date componentto obtainmonthandday.If this returns nothing, then fail.

  4. Ifpositionisnotbeyond the end ofinput,then fail.

  5. Returnmonthandday.

The rules toparse a yearless date component,given aninput string and aposition,are as follows. This will return either a month and a day, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code pointsthat are U+002D HYPHEN-MINUS characters (-) frominputgivenposition.If the collected sequence is not exactly zero or two characters long, then fail.

  2. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be themonth.

  3. Ifmonthis not a number in the range 1 ≤month≤ 12, then fail.

  4. Letmaxdaybe thenumber of daysin monthmonthof any arbitrary leap year (e.g. 4 or 2000).

  5. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+002D HYPHEN-MINUS character, then fail. Otherwise, movepositionforwards one character.

  6. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theday.

  7. Ifdayis not a number in the range 1 ≤daymaxday,then fail.

  8. Returnmonthandday.

2.3.5.4Times

Atimeconsists of a specific time with no time-zone information, consisting of an hour, a minute, a second, and a fraction of a second.

A string is avalid time stringrepresenting an hourhour,a minuteminute,and a secondsecondif it consists of the following components in the given order:

  1. TwoASCII digits,representinghour,in the range 0 ≤hour≤ 23
  2. A U+003A COLON character (:)
  3. TwoASCII digits,representingminute,in the range 0 ≤minute≤ 59
  4. Ifsecondis nonzero, or optionally ifsecondis zero:
    1. A U+003A COLON character (:)
    2. TwoASCII digits,representing the integer part ofsecond, in the range 0 ≤s≤ 59
    3. Ifsecondis not an integer, or optionally ifsecondis an integer:
      1. A U+002E FULL STOP character (.)
      2. One, two, or threeASCII digits,representing the fractional part ofsecond

Thesecondcomponent cannot be 60 or 61; leap seconds cannot be represented.

The rules toparse a time stringare as follows. This will return either a time, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a time componentto obtainhour,minute,andsecond.If this returns nothing, then fail.

  4. Ifpositionisnotbeyond the end ofinput,then fail.

  5. Lettimebe the time with hourhour,minuteminute,and secondsecond.

  6. Returntime.

The rules toparse a time component,given aninputstring and a position,are as follows. This will return either an hour, a minute, and a second, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be thehour.

  2. Ifhouris not a number in the range 0 ≤hour≤ 23, then fail.
  3. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+003A COLON character, then fail. Otherwise, movepositionforwards one character.

  4. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theminute.

  5. Ifminuteis not a number in the range 0 ≤minute≤ 59, then fail.
  6. Letsecondbe 0.

  7. Ifpositionis not beyond the end ofinputand the character at positionis U+003A (:), then:

    1. Advancepositionto the next character ininput.

    2. Ifpositionis beyond the end ofinput,or at the last character ininput,or if the nexttwocharacters ininputstarting atpositionare not bothASCII digits,then fail.

    3. Collect a sequence of code pointsthat are eitherASCII digits or U+002E FULL STOP characters frominputgivenposition.If the collected sequence is three characters long, or if it is longer than three characters long and the third character is not a U+002E FULL STOP character, or if it has more than one U+002E FULL STOP character, then fail. Otherwise, interpret the resulting sequence as a base-ten number (possibly with a fractional part). Setsecondto that number.

    4. Ifsecondis not a number in the range 0 ≤second< 60, then fail.

  8. Returnhour,minute,andsecond.

2.3.5.5Local dates and times

Alocal date and timeconsists of a specific proleptic-Gregorian date,consisting of a year, a month, and a day, and a time, consisting of an hour, a minute, a second, and a fraction of a second, but expressed without a time zone.[GREGORIAN]

A string is avalid local date and time stringrepresenting a date and time if it consists of the following components in the given order:

  1. Avalid date stringrepresenting the date
  2. A U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character
  3. Avalid time stringrepresenting the time

A string is avalid normalized local date and time stringrepresenting a date and time if it consists of the following components in the given order:

  1. Avalid date stringrepresenting the date
  2. A U+0054 LATIN CAPITAL LETTER T character (T)
  3. Avalid time stringrepresenting the time, expressed as the shortest possible string for the given time (e.g. omitting the seconds component entirely if the given time is zero seconds past the minute)

The rules toparse a local date and time stringare as follows. This will return either a date and time, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a date componentto obtainyear,month,andday.If this returns nothing, then fail.

  4. Ifpositionis beyond the end ofinputor if the character atpositionis neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then fail. Otherwise, moveposition forwards one character.

  5. Parse a time componentto obtainhour,minute,andsecond.If this returns nothing, then fail.

  6. Ifpositionisnotbeyond the end ofinput,then fail.

  7. Letdatebe the date with yearyear,monthmonth,and dayday.

  8. Lettimebe the time with hourhour,minuteminute,and secondsecond.

  9. Returndateandtime.

2.3.5.6Time zones

Atime-zone offsetconsists of a signed number of hours and minutes.

A string is avalid time-zone offset stringrepresenting a time-zone offset if it consists of either:

This format allows for time-zone offsets from -23:59 to +23:59. Right now, in practice, the range of offsets of actual time zones is -12:00 to +14:00, and the minutes component of offsets of actual time zones is always either 00, 30, or 45. There is no guarantee that this will remain so forever, however, since time zones are used as political footballs and are thus subject to very whimsical policy decisions.

See also the usage notes and examples in theglobal date and timesection below for details on using time-zone offsets with historical times that predate the formation of formal time zones.

The rules toparse a time-zone offset stringare as follows. This will return either a time-zone offset, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a time-zone offset componentto obtaintimezonehoursandtimezoneminutes.If this returns nothing, then fail.

  4. Ifpositionisnotbeyond the end ofinput,then fail.

  5. Return the time-zone offset that istimezonehours hours andtimezoneminutesminutes from UTC.

The rules toparse a time-zone offset component,given aninput string and aposition,are as follows. This will return either time-zone hours and time-zone minutes, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. If the character atpositionis a U+005A LATIN CAPITAL LETTER Z character (Z), then:

    1. Lettimezonehoursbe 0.

    2. Lettimezoneminutesbe 0.

    3. Advancepositionto the next character ininput.

    Otherwise, if the character atpositionis either a U+002B PLUS SIGN (+) or a U+002D HYPHEN-MINUS (-), then:

    1. If the character atpositionis a U+002B PLUS SIGN (+), letsignbe "positive". Otherwise, it's a U+002D HYPHEN-MINUS (-); letsignbe "negative".

    2. Advancepositionto the next character ininput.

    3. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.Letsbe the collected sequence.

    4. Ifsis exactly two characters long, then:

      1. Interpretsas a base-ten integer. Let that number be thetimezonehours.

      2. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+003A COLON character, then fail. Otherwise, movepositionforwards one character.

      3. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be thetimezoneminutes.

      Ifsis exactly four characters long, then:

      1. Interpret the first two characters ofsas a base-ten integer. Let that number be thetimezonehours.

      2. Interpret the last two characters ofsas a base-ten integer. Let that number be thetimezoneminutes.

      Otherwise, fail.

    5. Iftimezonehoursis not a number in the range 0 ≤timezonehours≤ 23, then fail.
    6. Ifsignis "negative", then negatetimezonehours.
    7. Iftimezoneminutesis not a number in the range 0 ≤timezoneminutes≤ 59, then fail.
    8. Ifsignis "negative", then negatetimezoneminutes.

    Otherwise, fail.

  2. Returntimezonehoursandtimezoneminutes.

2.3.5.7Global dates and times

Aglobal date and timeconsists of a specific proleptic-Gregorian date,consisting of a year, a month, and a day, and a time, consisting of an hour, a minute, a second, and a fraction of a second, expressed with a time-zone offset, consisting of a signed number of hours and minutes.[GREGORIAN]

A string is avalid global date and time stringrepresenting a date, time, and a time-zone offset if it consists of the following components in the given order:

  1. Avalid date stringrepresenting the date
  2. A U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character
  3. Avalid time stringrepresenting the time
  4. Avalid time-zone offset stringrepresenting the time-zone offset

Times in dates before the formation of UTC in the mid-twentieth century must be expressed and interpreted in terms of UT1 (contemporary Earth solar time at the 0° longitude), not UTC (the approximation of UT1 that ticks in SI seconds). Time before the formation of time zones must be expressed and interpreted as UT1 times with explicit time zones that approximate the contemporary difference between the appropriate local time and the time observed at the location of Greenwich, London.

The following are some examples of dates written asvalid global date and time strings.

"0037-12-13 00:00Z"
Midnight in areas using London time on the birthday of Nero (the Roman Emperor). See below for further discussion on which date this actually corresponds to.
"1979-10-14T12:00:00.001-04:00"
One millisecond after noon on October 14th 1979, in the time zone in use on the east coast of the USA during daylight saving time.
"8592-01-01T02:09+02:09"
Midnight UTC on the 1st of January, 8592. The time zone associated with that time is two hours and nine minutes ahead of UTC, which is not currently a real time zone, but is nonetheless allowed.

Several things are notable about these dates:

The rules toparse a global date and time stringare as follows. This will return either a time in UTC, with associated time-zone offset information for round-tripping or display purposes, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Parse a date componentto obtainyear,month,andday.If this returns nothing, then fail.

  4. Ifpositionis beyond the end ofinputor if the character atpositionis neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then fail. Otherwise, moveposition forwards one character.

  5. Parse a time componentto obtainhour,minute,andsecond.If this returns nothing, then fail.

  6. Ifpositionis beyond the end ofinput,then fail.

  7. Parse a time-zone offset componentto obtaintimezonehoursandtimezoneminutes.If this returns nothing, then fail.

  8. Ifpositionisnotbeyond the end ofinput,then fail.

  9. Lettimebe the moment in time at yearyear,month month,dayday,hourshour,minute minute,secondsecond,subtractingtimezonehourshours andtimezoneminutesminutes. That moment in time is a moment in the UTC time zone.

  10. Lettimezonebetimezonehours hours andtimezoneminutesminutes from UTC.

  11. Returntimeandtimezone.

2.3.5.8Weeks

Aweekconsists of a week-year number and a week number representing a seven-day period starting on a Monday. Each week-year in this calendaring system has either 52 or 53 such seven-day periods, as defined below. The seven-day period starting on the Gregorian date Monday December 29th 1969 (1969-12-29) is defined as week number 1 in week-year 1970. Consecutive weeks are numbered sequentially. The week before the number 1 week in a week-year is the last week in the previous week-year, and vice versa.[GREGORIAN]

A week-year with a numberyearhas 53 weeks if it corresponds to either a yearyearin theproleptic Gregorian calendarthat has a Thursday as its first day (January 1st), or a yearyearin theproleptic Gregorian calendarthat has a Wednesday as its first day (January 1st) and whereyearis a number divisible by 400, or a number divisible by 4 but not by 100. All other week-years have 52 weeks.

Theweek number of the last dayof a week-year with 53 weeks is 53; the week number of the last day of a week-year with 52 weeks is 52.

The week-year number of a particular day can be different than the number of the year that contains that day in theproleptic Gregorian calendar.The first week in a week-yearyis the week that contains the first Thursday of the Gregorian year y.

For modern purposes, aweekas defined here is equivalent to ISO weeks as defined in ISO 8601.[ISO8601]

A string is avalid week stringrepresenting a week-yearyear and weekweekif it consists of the following components in the given order:

  1. Four or moreASCII digits,representingyear,whereyear> 0
  2. A U+002D HYPHEN-MINUS character (-)
  3. A U+0057 LATIN CAPITAL LETTER W character (W)
  4. TwoASCII digits,representing the weekweek,in the range 1 ≤weekmaxweek,wheremaxweekis theweek number of the last dayof week-yearyear

The rules toparse a week stringare as follows. This will return either a week-year number and week number, or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not at least four characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theyear.

  4. Ifyearis not a number greater than zero, then fail.

  5. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+002D HYPHEN-MINUS character, then fail. Otherwise, movepositionforwards one character.

  6. Ifpositionis beyond the end ofinputor if the character atpositionis not a U+0057 LATIN CAPITAL LETTER W character (W), then fail. Otherwise, movepositionforwards one character.

  7. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.If the collected sequence is not exactly two characters long, then fail. Otherwise, interpret the resulting sequence as a base-ten integer. Let that number be theweek.

  8. Letmaxweekbe theweek number of the last dayof year year.

  9. Ifweekis not a number in the range 1 ≤weekmaxweek,then fail.

  10. Ifpositionisnotbeyond the end ofinput,then fail.

  11. Return the week-year numberyearand the week numberweek.

2.3.5.9Durations

Adurationconsists of a number of seconds.

Since months and seconds are not comparable (a month is not a precise number of seconds, but is instead a period whose exact length depends on the precise day from which it is measured) adurationas defined in this specification cannot include months (or years, which are equivalent to twelve months). Only durations that describe a specific number of seconds can be described.

A string is avalid duration stringrepresenting adurationtif it consists of either of the following:

The rules toparse a duration stringare as follows. This will return either adurationor nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Letmonths,seconds,andcomponent countall be zero.

  4. LetM-disambiguatorbeminutes.

    This flag's other value ismonths.It is used to disambiguate the "M" unit in ISO8601 durations, which use the same unit for months and minutes. Months are not allowed, but are parsed for future compatibility and to avoid misinterpreting ISO8601 durations that would be valid in other contexts.

  5. Skip ASCII whitespacewithininputgiven position.

  6. Ifpositionis past the end ofinput,then fail.

  7. If the character ininputpointed to bypositionis a U+0050 LATIN CAPITAL LETTER P character, then advancepositionto the next character, set M-disambiguatortomonths,andskip ASCII whitespacewithin inputgivenposition.

  8. While true:

    1. Letunitsbe undefined. It will be assigned one of the following values:years,months,weeks,days,hours,minutes, andseconds.

    2. Letnext characterbe undefined. It is used to process characters from theinput.

    3. Ifpositionis past the end ofinput,then break.

    4. If the character ininputpointed to bypositionis a U+0054 LATIN CAPITAL LETTER T character, then advancepositionto the next character, set M-disambiguatortominutes,skip ASCII whitespacewithin inputgivenposition,andcontinue.

    5. Setnext characterto the character ininput pointed to byposition.

    6. Ifnext characteris a U+002E FULL STOP character (.), then letNequal zero. (Do not advanceposition.That is taken care of below.)

      Otherwise, ifnext characteris anASCII digit,thencollect a sequence of code pointsthat areASCII digitsfrominputgivenposition,interpret the resulting sequence as a base-ten integer, and letNbe that number.

      Otherwise,next characteris not part of a number; fail.

    7. Ifpositionis past the end ofinput,then fail.

    8. Setnext characterto the character ininput pointed to byposition,and this time advanceposition to the next character. (Ifnext characterwas a U+002E FULL STOP character (.) before, it will still be that character this time.)

    9. Ifnext characteris U+002E (.), then:

      1. Collect a sequence of code pointsthat areASCII digitsfrom inputgivenposition.Letsbe the resulting sequence.

      2. Ifsis the empty string, then fail.

      3. Letlengthbe the number of characters ins.

      4. Letfractionbe the result of interpretings as a base-ten integer, and then dividing that number by10length.

      5. IncrementNbyfraction.

      6. Skip ASCII whitespacewithininputgiven position.

      7. Ifpositionis past the end ofinput,then fail.

      8. Setnext characterto the character ininput pointed to byposition,and advancepositionto the next character.

      9. Ifnext characteris neither a U+0053 LATIN CAPITAL LETTER S character nor a U+0073 LATIN SMALL LETTER S character, then fail.

      10. Setunitstoseconds.

      Otherwise:

      1. Ifnext characterisASCII whitespace,thenskip ASCII whitespacewithininputgivenposition,setnext characterto the character ininputpointed to byposition,and advancepositionto the next character.

      2. Ifnext characteris a U+0059 LATIN CAPITAL LETTER Y character, or a U+0079 LATIN SMALL LETTER Y character, setunitstoyearsand set M-disambiguatortomonths.

        Ifnext characteris a U+004D LATIN CAPITAL LETTER M character or a U+006D LATIN SMALL LETTER M character, andM-disambiguatoris months,then setunitstomonths.

        Ifnext characteris a U+0057 LATIN CAPITAL LETTER W character or a U+0077 LATIN SMALL LETTER W character, setunitstoweeksand set M-disambiguatortominutes.

        Ifnext characteris a U+0044 LATIN CAPITAL LETTER D character or a U+0064 LATIN SMALL LETTER D character, setunitstodaysand set M-disambiguatortominutes.

        Ifnext characteris a U+0048 LATIN CAPITAL LETTER H character or a U+0068 LATIN SMALL LETTER H character, setunitstohoursand set M-disambiguatortominutes.

        Ifnext characteris a U+004D LATIN CAPITAL LETTER M character or a U+006D LATIN SMALL LETTER M character, andM-disambiguatoris minutes,then setunitstominutes.

        Ifnext characteris a U+0053 LATIN CAPITAL LETTER S character or a U+0073 LATIN SMALL LETTER S character, setunitstosecondsand setM-disambiguatortominutes.

        Otherwise, ifnext characteris none of the above characters, then fail.

    10. Incrementcomponent count.

    11. Letmultiplierbe 1.

    12. Ifunitsisyears,multiplymultiplierby 12 and setunitstomonths.

    13. Ifunitsismonths,add the product ofNand multipliertomonths.

      Otherwise:

      1. Ifunitsisweeks,multiplymultiplier by 7 and setunitstodays.

      2. Ifunitsisdays,multiplymultiplier by 24 and setunitstohours.

      3. Ifunitsishours,multiplymultiplier by 60 and setunitstominutes.

      4. Ifunitsisminutes,multiplymultiplierby 60 and setunitstoseconds.

      5. Forcibly,unitsis nowseconds.Add the product ofNandmultipliertoseconds.

    14. Skip ASCII whitespacewithininputgiven position.

  9. Ifcomponent countis zero, fail.

  10. Ifmonthsis not zero, fail.

  11. Return thedurationconsisting ofsecondsseconds.

2.3.5.10Vaguer moments in time

A string is avalid date string with optional timeif it is also one of the following:


The rules toparse a date or time stringare as follows. The algorithm will return either adate,atime,aglobal date and time,or nothing. If at any point the algorithm says that it "fails", this means that it is aborted at that point and returns nothing.

  1. Letinputbe the string being parsed.

  2. Letpositionbe a pointer intoinput,initially pointing at the start of the string.

  3. Setstart positionto the same position asposition.

  4. Set thedate presentandtime presentflags to true.

  5. Parse a date componentto obtainyear,month,andday.If this fails, then set thedate presentflag to false.

  6. Ifdate presentis true, andpositionis not beyond the end ofinput,and the character atpositionis either a U+0054 LATIN CAPITAL LETTER T character (T) or a U+0020 SPACE character, then advance positionto the next character ininput.

    Otherwise, ifdate presentis true, and eitherpositionis beyond the end ofinputor the character atpositionis neither a U+0054 LATIN CAPITAL LETTER T character (T) nor a U+0020 SPACE character, then settime presentto false.

    Otherwise, ifdate presentis false, setposition back to the same position asstart position.

  7. If thetime presentflag is true, thenparse a time componentto obtainhour,minute,andsecond.If this returns nothing, then fail.

  8. If thedate presentandtime presentflags are both true, butpositionis beyond the end ofinput,then fail.

  9. If thedate presentandtime presentflags are both true,parse a time-zone offset componentto obtaintimezonehoursandtimezoneminutes.If this returns nothing, then fail.

  10. Ifpositionisnotbeyond the end ofinput,then fail.

  11. If thedate presentflag is true and thetime present flag is false, then letdatebe the date with yearyear, monthmonth,and dayday,and returndate.

    Otherwise, if thetime presentflag is true and thedate presentflag is false, then lettimebe the time with hourhour,minuteminute,and secondsecond, and returntime.

    Otherwise, lettimebe the moment in time at yearyear,monthmonth,dayday,hourshour,minuteminute,secondsecond, subtractingtimezonehourshours andtimezoneminutesminutes, that moment in time being a moment in the UTC time zone; lettimezonebetimezonehourshours andtimezoneminutes minutes from UTC; and returntimeandtimezone.

2.3.6Colors

Asimple colorconsists of three 8-bit numbers in the range 0 to 255, inclusive, representing the red, green, and blue components of the color respectively, in the'srgb'color space.

A string is avalid simple colorif it is exactly seven characters long, and the first character is a U+0023 NUMBER SIGN character (#), and the remaining six characters are allASCII hex digits,with the first two digits representing the red component, the middle two digits representing the green component, and the last two digits representing the blue component, in hexadecimal.

A string is avalid lowercase simple colorif it is avalid simple colorand doesn't use any characters in the range U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL LETTER F.

Therules for parsing simple color valuesare as given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either asimple coloror an error.

  1. Letinputbe the string being parsed.

  2. Ifinputis not exactly seven characters long, then return an error.

  3. If the first character ininputis not a U+0023 NUMBER SIGN character (#), then return an error.

  4. If the last six characters ofinputare not allASCII hex digits,then return an error.

  5. Letresultbe asimple color.

  6. Interpret the second and third characters as a hexadecimal number and let the result be the red component ofresult.

  7. Interpret the fourth and fifth characters as a hexadecimal number and let the result be the green component ofresult.

  8. Interpret the sixth and seventh characters as a hexadecimal number and let the result be the blue component ofresult.

  9. Returnresult.

Therules for serializing simple color valuesgiven asimple colorare as given in the following algorithm:

  1. Letresultbe a string consisting of a single U+0023 NUMBER SIGN character (#).

  2. Convert the red, green, and blue components in turn to two-digit hexadecimal numbers using ASCII lower hex digits,zero-padding if necessary, and append these numbers toresult,in the order red, green, blue.

  3. Returnresult,which will be avalid lowercase simple color.


Some obsolete legacy attributes parse colors in a more complicated manner, using the rules for parsing a legacy color value,which are given in the following algorithm. When invoked, the steps must be followed in the order given, aborting at the first step that returns a value. This algorithm will return either asimple coloror an error.

  1. Letinputbe the string being parsed.

  2. Ifinputis the empty string, then return an error.

  3. Strip leading and trailing ASCII whitespacefrominput.

  4. Ifinputis anASCII case-insensitivematch for the string "transparent",then return an error.

  5. Ifinputis anASCII case-insensitivematch for one of the named colors,then return thesimple color corresponding to that keyword.[CSSCOLOR]

    CSS2 System Colorsare not recognized.

  6. Ifinput'scode point lengthis four, and the first character in inputis U+0023 (#), and the last three characters ofinputare all ASCII hex digits,then:

    1. Letresultbe asimple color.

    2. Interpret the second character ofinputas a hexadecimal digit; let the red component ofresultbe the resulting number multiplied by 17.

    3. Interpret the third character ofinputas a hexadecimal digit; let the green component ofresultbe the resulting number multiplied by 17.

    4. Interpret the fourth character ofinputas a hexadecimal digit; let the blue component ofresultbe the resulting number multiplied by 17.

    5. Returnresult.

  7. Replace anycode pointsgreater than U+FFFF in input(i.e., any characters that are not in the basic multilingual plane) with the two-character string "00".

  8. Ifinput'scode point lengthis greater than 128, truncate input,leaving only the first 128 characters.

  9. If the first character ininputis a U+0023 NUMBER SIGN character (#), remove it.

  10. Replace any character ininputthat is not anASCII hex digitwith the character U+0030 DIGIT ZERO (0).

  11. Whileinput'scode point lengthis zero or not a multiple of three, append a U+0030 DIGIT ZERO (0) character toinput.

  12. Splitinputinto three strings of equalcode point length,to obtain three components. Letlengthbe thecode point lengththat all of those components have (one third thecode point lengthofinput).

  13. Iflengthis greater than 8, then remove the leadinglength-8characters in each component, and letlengthbe 8.

  14. Whilelengthis greater than two and the first character in each component is a U+0030 DIGIT ZERO (0) character, remove that character and reducelengthby one.

  15. Iflengthisstillgreater than two, truncate each component, leaving only the first two characters in each.

  16. Letresultbe asimple color.

  17. Interpret the first component as a hexadecimal number; let the red component ofresultbe the resulting number.

  18. Interpret the second component as a hexadecimal number; let the green component ofresultbe the resulting number.

  19. Interpret the third component as a hexadecimal number; let the blue component ofresultbe the resulting number.

  20. Returnresult.


The2D graphics contexthas a separate color syntax that also handles opacity.

2.3.7Space-separated tokens

Aset of space-separated tokensis a string containing zero or more words (known as tokens) separated by one or moreASCII whitespace,where words consist of any string of one or more characters, none of which areASCII whitespace.

A string containing aset of space-separated tokensmay have leading or trailing ASCII whitespace.

Anunordered set of unique space-separated tokensis aset of space-separated tokenswhere none of the tokens are duplicated.

Anordered set of unique space-separated tokensis aset of space-separated tokenswhere none of the tokens are duplicated but where the order of the tokens is meaningful.

Sets of space-separated tokenssometimes have a defined set of allowed values. When a set of allowed values is defined, the tokens must all be from that list of allowed values; other values are non-conforming. If no such set of allowed values is provided, then all values are conforming.

How tokens in aset of space-separated tokensare to be compared (e.g. case-sensitively or not) is defined on a per-set basis.

2.3.8Comma-separated tokens

Aset of comma-separated tokensis a string containing zero or more tokens each separated from the next by a single U+002C COMMA character (,), where tokens consist of any string of zero or more characters, neither beginning nor ending withASCII whitespace,nor containing any U+002C COMMA characters (,), and optionally surrounded byASCII whitespace.

For instance, the string "a,b,,d d"consists of four tokens:" a "," b ", the empty string, and" d d ". Leading and trailing whitespace around each token doesn't count as part of the token, and the empty string can be a token.

Sets of comma-separated tokenssometimes have further restrictions on what consists a valid token. When such restrictions are defined, the tokens must all fit within those restrictions; other values are non-conforming. If no such restrictions are specified, then all values are conforming.

2.3.9References

Avalid hash-name referenceto an element of typetypeis a string consisting of a U+0023 NUMBER SIGN character (#) followed by a string which exactly matches the value of thenameattribute of an element with typetypein the sametree.

Therules for parsing a hash-name referenceto an element of typetype, given a context nodescope,are as follows:

  1. If the string being parsed does not contain a U+0023 NUMBER SIGN character, or if the first such character in the string is the last character in the string, then return null.

  2. Letsbe the string from the character immediately after the first U+0023 NUMBER SIGN character in the string being parsed up to the end of that string.

  3. Return the first element of typetypeinscope'stree,in tree order,that has anidornameattribute whose value iss,or null if there is no such element.

    Althoughidattributes are accounted for when parsing, they are not used in determining whether a value is avalidhash-name reference.That is, a hash-name reference that refers to an element based onidis a conformance error (unless that element also has anameattribute with the same value).

2.3.10Media queries

A string is avalid media query listif it matches the<media-query-list>production ofMedia Queries. [MQ]

A stringmatches the environmentof the user if it is the empty string, a string consisting of onlyASCII whitespace,or is a media query list that matches the user's environment according to the definitions given inMedia Queries.[MQ]

2.3.11Unique internal values

Aunique internal valueis a value that is serializable, comparable by value, and never exposed to script.

To create anew unique internal value,return aunique internal value that has never previously been returned by this algorithm.