User Agent Style Sheets: Basics andSamples
Post from September 22, 2007 (↻ February 17, 2021), filed under Web Development. (Tweetthis?)This và many other posts are also available as a pretty, well-behaved ebook: On Web Development.Quý Khách đang xem: User agent stylesheet là gì
CSS takes care of the default formatting of documents through the concept of user agent style sheets, a cornerstone of the cascade. It means that a web browser doesn’t just present a line of text when it’s fed with an HTML document that has no styling information attached, but instead serves it using minimal formatting.
Bạn đang xem: User agent stylesheet là gì
Figure: HTML document with Firefox defaultstyling.
CSS1 introduces the idea by stating that “each User Agent (UA, often a ‘website browser’ or ‘web client’) will have a default style sheet that presents documents in a reasonable—but arguably mundane—manner.” CSS2 says that “conforming user agents must apply a mặc định style sheet (or behave as if they did)” và that “a user agent’s default style sheet should present the elements of the document language in ways that satisfy general presentation expectations for the document language.” CSS3 is of the same mind.
Since the CSS specifications leave it up lớn implementations whether khổng lồ use a “real” style sheet for mặc định display or not, it’s not surprising that you don’t find a default style sheet in every browser’s installation folder. Unlike Microsoft’s Internet Explorer as well as Opera, for example, Gecko browsers lượt thích Firefox & Netscape Navigator (“html.css”) but also Konqueror make it rather simple lớn comprehend their default styles.
Example User Agent StyleSheets
The following is a danh sách of mặc định style sheets I’ve compiled over recent years (except for Safari; thank you, Martin). Due to lớn the fact that Firebird, Firefox, and Co. are all based on the same layout engine, they’re quite similar, if not identical.
For comparison, note the exemplary default style sheets proposed by the W3C in the specifications of CSS1, CSS2, CSS2.1, and CSS2.2:
User Agent & Remix StyleSheets
The examples ayên khổng lồ provide some insight inlớn user agent style sheets. Knowledge of user agent style sheets should help get a better understanding of CSS as well as any display “phenomena.”
However, I encourage lớn use this knowledge for other things than building more or larger “reset” style sheets. Assuming use of additional style sheets other than just a reset, rephối style sheets are typically unnecessary. From my experience, the only occasionally helpful & then quite memorable remix is * margin: 0; padding: 0; . Rephối style sheets are going to be handled in other posts though, revealing why they’re, well, bad.
I’m Jens Oliver aviarus-21.com, & I’m a website developer (engineering manager) and author. I love trying things, sometimes including philosophy, art, và adventure. Here on aviarus-21.com I nói qua some of my views andexperiences.If you have questions or suggestions about what I write, please leave a bình luận (if available) or amessage.
On September 24, 2007, 8:37 CEST, Martin Hassman said:For Safari/Webkit stylesheets cannot be found in the installation (propably compiled into some library), but they are on the web source tracking system with their history
On September 24, 2007, 11:18 CEST, Jens Oliver aviarus-21.com said:Thanks Martin—I updated the post.
On September 25, 2007, 16:29 CEST, Barney said:This is a very nice piece, Jens. I’m glad someone can give this little study authoritatively because the recent craze over remix stylesheets, and inherently the notion that browser defaults are bad, is often very misguided: If you are going khổng lồ respecify everything, there is no need for the extra rule for every element; if you aren’t, you’re far better off with the user/developer’s consideration than nothing.
On September 26, 2007, 9:54 CEST, Daniel said:I absolutely don’t agree with you. The rephối with * margin: 0; padding: 0; is the worst method of resetting the browser’s default styles.Especially when working on size elements it make a lot of problems.
The better reset: Rephối Reloaded
On November 12, 2007, 19:50 CET, Lynne said:Interesting read… I just assumed that if the link to lớn the CSS was broken the browsers would default to plain HTML formatting. However, it certainly makes more sense khổng lồ have sầu a default css file.
On December 30, 2007, 23:34 CET, Lazar said:Thanks for this. It’s really useful info! Especially for CSS beginners lượt thích me.
On January 7, 2008, 15:53 CET, Anders said:Interesting read, but I am not able to find out where a textarea’s default fonts (courier) comes from. Anybody?
On February 14, 2008, 22:22 CET, ty said:Thanks for an excellent writeup.So what vị you start with as a mặc định then?I’ve sầu been using a remix of sorts, và am finding some of those defining things I never use in my markup, so that seems redundant to me.How lớn be sure borders, margins don’t create problems without resetting them or defining them khổng lồ be the same despite whatever UA styling could derail a layout?
Perhaps my most relevant book: CSS Optimization Basics (2018). Writing CSS is a craft. As craftspeople we strive sầu to write high quality CSS. In CSS Optimization Basics I lay out some of the most important aspects of such CSS. Available at Amazon, Google Play Books, andLeanpub.