Path: blob/main/files/en-us/web/css/@document/index.md
6510 views
------{{CSSRef}}{{Deprecated_header}}{{Non-standard_header}}
The @document CSS at-rule restricts the style rules contained within it based on the URL of the document. It is designed primarily for user-defined style sheets, though it can be used on author-defined style sheets, too.
Syntax
An @document rule can specify one or more matching functions. If any of the functions apply to a given URL, the rule will take effect on that URL. The functions available are:
url(): Matches an exact URL.
url-prefix(): Matches if the document URL starts with the value provided.
domain(): Matches if the document URL is on the domain provided (or a subdomain of it).
media-document(): Matches the media according to the string in parameter, one of
video,image,pluginorall.
regexp(){{Deprecated_Inline}} {{Non-standard_Inline}}: 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(), domain(), and media-document() functions can be optionally 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 be 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 is currently only supported in Firefox; if you wanted to replicate using such functionality in your own non-Firefox browser, you could try using this polyfill by @An-Error94, which uses a combination of a user script, data-* attributes, and attribute selectors.
Note: There is a -moz-prefixed version of this property —
@-moz-document. This has been limited to use only in user and UA sheets in Firefox 59 in Nightly and Beta — an experiment designed to mitigate potential CSS injection attacks (See Firefox bug 1035091).
Formal syntax
Examples
Specifying document for CSS rule
Specifications
Initially in Level 3, @document was postponed to Level 4, but then subsequently removed.
Browser compatibility
{{Compat}}
See also
Per-site user style sheet rules on the www-style mailing list.