document property CSS Reference

Definition and Usage

The @document rule is an at-rule that restricts the style rules contained within it based on the URL of the document. It is designed primarily for user style sheets. A @document rule can specify one or more matching functions. If any of the functions apply to a URL, the rule will take effect on that URL.

The main use case is for user-defined stylesheets, though this at-rule can be used on author-defined stylesheets too.

The functions available are:

  • url(), which matches an exact URL
  • url-prefix(), which matches if the document URL starts with the value provided
  • domain(), which matches if the document URL is on the domain provided (or a subdomain of it)
  • regexp(), which matches if the document URL is matched by the regular expression provided. The expression must match the entire URL.


The values provided to the url(), url-prefix(), and domain() functions can optionally be enclosed by single or double quotes. The values provided to the regexp() function must be enclosed in quotes.

Escaped values provided to the regexp() function must additionally escaped from the CSS. For example, a . (period) matches any character in regular expressions. To match a literal period, you would first need to escape it using regular expression rules (to \.), then escape that string using CSS rules (to \\.).


@document url(,
  /* CSS rules here apply to:
     + The page "".
     + Any page whose URL begins with ""
     + Any page whose URL's host is "" or ends with
     + Any page whose URL starts with "https:" */
  /* make the above-mentioned pages really ugly */
  body { color: purple; background: yellow; }


Desktop browsers

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic supportNot supported1.5 (1.8) -mozNot supportedNot supportedNot supported
regexp()Not supported6.0 (6.0)Not supportedNot supportedNot supported

Mobile browsers

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
regexp()Not supportedNot supportedNANot supportedNot supportedNot supported

Relative articles