W3cubDocs

/Web APIs

CSSNumericValue: type() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The type() method of the CSSNumericValue interface returns the type of CSSNumericValue, one of angle, flex, frequency, length, resolution, percent, percentHint, or time.

Syntax

type()

Parameters

None.

Return value

A CSSNumericType dictionary, which contains the following properties:

  • length
  • angle
  • time
  • frequency
  • resolution
  • flex
  • percent
  • percentHint

For each property except percentHint, the value is an integer representing the power of that unit. For example, a numeric value of calc(1px * 1em) will return { length: 2 }.

The percentHint property is a string that indicates the type of value that the percent is applied to. The string value is the same as the type properties: "length", "angle", "time", "frequency", "resolution", "flex", or "percent". It indicates that the type actually holds a percentage, but that percentage will eventually resolve to the hinted base type, and so has been replaced with it in the type.

Exceptions

None.

Examples

let mathSum = CSS.px("23")
  .sub(CSS.percent("4"))
  .sub(CSS.cm("3"))
  .sub(CSS.in("9"));
// Returns an object with the structure: {length: 1, percentHint: "length"}
let cssNumericType = mathSum.type();

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
type 66 79 No 53 16.4 66 No 47 16.4 9.0 66 16.4

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/CSSNumericValue/type