{"id":201268,"date":"2015-05-12T08:14:37","date_gmt":"2015-05-12T15:14:37","guid":{"rendered":"http:\/\/css-tricks.com\/?p=201268"},"modified":"2024-05-21T13:43:44","modified_gmt":"2024-05-21T20:43:44","slug":"the-at-rules-of-css","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/the-at-rules-of-css\/","title":{"rendered":"The At-Rules of CSS"},"content":{"rendered":"\n
The Regular rules follow a regular syntax:<\/p>\n\n\n\n This rule defines the character set used by the browser. It comes in handy if the stylesheet contains non-ASCII characters<\/a> (e.g. UTF-8<\/a>). Note that a character set that is placed on the HTTP header<\/a> will override any This rule is inserted at the very top of the file and instructs the stylesheet to request and include an external CSS file as if the contents of that file were right where that line is.<\/p>\n\n\n\n With the popularity of CSS preprocessors that support @import, it should be noted that they work differently than native CSS This rule is particularly useful for applying CSS to XML HTML (XHTML) so that XHTML elements can be used as selectors in the CSS.<\/p>\n\n\n\n Nested rules contain a subset of additional statements, some of which might be conditional to a specific situation.<\/p>\n\n\n\n This rule specifies conditions for styles that apply to a specific page. For example, we can provide a URL and then customize the styles for that particular page. Those styles will be ignored on other pages.<\/p>\n\n\n\n The browser support for This rule allows us to load custom fonts on a webpage. There are varying levels of support<\/a> for custom fonts, but this rule accepts statements that create and serve those fonts.<\/p>\n\n\n\nat-rule<\/code> is a statement that provides CSS with instructions to perform or how to behave. Each statement begins with an @<\/code> followed directly by one of several available keywords that acts as the identifier for what CSS should do. This is the common syntax, though each at-rule<\/code> is a variation of it.<\/p>\n\n\n\n\n\n\nRegular Rules<\/h3>\n\n\n
@[KEYWORD] (RULE);<\/code><\/pre>\n\n\n@charset<\/code><\/h4>\n\n\n@charset<\/code> rule.<\/p>\n\n\n\n@charset \"UTF-8\";<\/code><\/pre>\n\n\n@import<\/code><\/h4>\n\n\n@import 'global.css';<\/code><\/pre>\n\n\n\n@import<\/code> is a separate HTTP request for that file.<\/p>\n\n\n@namespace<\/code><\/h4>\n\n\n\/* Namespace for XHTML *\/\n@namespace url(http:\/\/www.w3.org\/1999\/xhtml);\n\n\/* Namespace for SVG embedded in XHTML *\/\n@namespace svg url(http:\/\/www.w3.org\/2000\/svg);<\/code><\/pre>\n\n\nNested Rules<\/h3>\n\n\n
@[KEYWORD] {\n \/* Nested Statements *\/\n}<\/code><\/pre>\n\n\n@document<\/code><\/h4>\n\n\n@document \n \/* Rules for a specific page *\/\n url(https:\/\/css-tricks.com\/),\n \n \/* Rules for pages with a URL that begin with... *\/\n url-prefix(https:\/\/css-tricks.com\/snippets\/),\n \n \/* Rules for any page hosted on a domain *\/\n domain(css-tricks.com),\n\n \/* Rules for all secure pages *\/\n regexp(\"https:.*\")\n{\n \n \/* Start styling *\/\n body { font-family: Comic Sans; }\n\n}<\/code><\/pre>\n\n\n\n@document<\/code> is pretty weak <\/a>at the time of this writing:<\/p>\n\n\n\nChrome<\/th> Safari<\/th> Firefox<\/th> Opera<\/th> IE<\/th> Android<\/th> iOS<\/th><\/tr><\/thead> No<\/td> No<\/td> Limited<\/td> No<\/td> No<\/td> No<\/td> No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n @font-face<\/code><\/h4>\n\n\n@font-face {\n font-family: 'MyWebFont';\n src: url('myfont.woff2') format('woff2'),\n url('myfont.woff') format('woff');\n}<\/code><\/pre>\n\n\n\n\n Learn more about @font-face <\/summary>\n \n\n \t\t\n