Where do Browser Styles Come From?

Mozilla Developer
11 Dec 201907:01

Summary

TLDRこのビデオスクリプトは、CSSリセットやNormalize.cssのようなツールの役割と、ブラウザが提供するデフォルトスタイル(ユーザーエージェントスタイル)について説明しています。デフォルトスタイルは、ページの可読性を確保するためにブラウザによって提供され、異なるブラウザ間で一貫性を保ちます。しかし、これらのスタイルはブラウザによって異なるため、リセットやノーマライザーを使用して更新することがあります。スクリプトでは、ブラウザデフォルトを確認する方法と、開発者ツールでブラウザスタイルを表示する方法についても紹介しています。

Takeaways

  • 🎨 CSSリセットやNormalize.cssのようなツールは、ブラウザ間でのデフォルトスタイルの一貫性を確保するために使用されます。
  • 🔍 ブラウザのデフォルトスタイルは、ユーザーエージェントスタイル(UAスタイル)とも呼ばれ、各ブラウザが提供するものです。
  • 📝 ブラウザは、ページを読みやすいように、特定のHTML要素にスタイルを提供します。
  • 🌐 ブラウザのデフォルトスタイルは、異なるブラウザ間で微妙に異なりますが、古いウェブサイトにも対応する必要があるため、変更されません。
  • 🛠️ CSSリセットやノルマライザは、ブラウザが提供するスタイルを更新するために使用されますが、全てのデフォルトスタイルを除去することはありません。
  • 🔎 ブラウザのデフォルトスタイルを確認するには、開発者ツールのインスペクターで「ブラウザスタイルを表示」を選択します。
  • 📊 「計算済み」パネルでブラウザスタイルを表示すると、要素に適用されている全てのCSSプロパティがわかります。
  • 🔗 Firefoxなどのオープンソースブラウザのユーザーエージェントスタイルシートは、公式ウェブサイトで公開されています。
  • 📚 Internet Explorerのパブリックスタイルシートはまだ見つかりませんが、Chromiumへの移行が進む中で、公開されることでしょう。
  • 💬 ブラウザのデフォルトスタイルを理解し、カスケードの中でどのように機能するかを視覚化することは、ウェブサイトのスタイリングに非常に役立ちます。

Q & A

  • CSSリセットとは何ですか?

    -CSSリセットは、異なるブラウザで一貫性を保ちながら、ページのデフォルトスタイルをリセットするためのツールです。例えば、Eric MeyerのCSSリセットやNormalize.cssがあります。

  • ブラウザデフォルトスタイルとは何ですか?

    -ブラウザデフォルトスタイル、またはユーザーエージェントスタイル(UAスタイル)は、ブラウザが提供する、ページを読みやすいようにするための標準スタイルのセットです。

  • ユーザーエージェントとは何を指しますか?

    -ユーザーエージェントは、ブラウザを指す技術用語です。

  • ブラウザデフォルトスタイルを無効にする方法はありますか?

    -ブラウザデフォルトスタイルを無効にするには、CSSリセットやノーマライザーを使用することができます。ただし、全てのデフォルトスタイルを除去することは一般的ではありません。

  • ブラウザデフォルトスタイルを確認する方法はありますか?

    -ブラウザの開発者ツールで、ブラウザスタイルを表示することで確認できます。開発者ツールの設定から「ブラウザスタイルを表示」を選択することで、デフォルトスタイルを確認できます。

  • 開発者ツールの「計算済み」パネルでブラウザスタイルを表示する方法は?

    -「計算済み」パネルで、ブラウザスタイルを表示するには、「ブラウザスタイル」を選択してオンにします。これにより、要素に適用されている全てのCSSプロパティが表示されます。

  • ブラウザデフォルトスタイルを直接閲覧するにはどうすればよいですか?

    -ブラウザデフォルトスタイルを直接閲覧するには、開発者ツールの「ルール」パネルから「html.css」をクリックするか、ブラウザのユーザーエージェントスタイルシートのリンクに直接アクセスします。

  • Firefoxのユーザーエージェントスタイルシートのリンクはどこで見つけることができますか?

    -Firefoxのユーザーエージェントスタイルシートのリンクは、開発者ツールの「html.css」をクリックすることで開くことができます。また、Mozillaのウェブサイトでも公開されています。

  • Chromiumブラウザのユーザーエージェントスタイルシートはどこで見つけることができますか?

    -Chromiumブラウザのユーザーエージェントスタイルシートは、公開されているため、オンラインでアクセスできます。

  • Internet Explorerのユーザーエージェントスタイルシートはどこで見つけることができますか?

    -Internet Explorerのユーザーエージェントスタイルシートは現在公開されていませんが、Chromiumに移行しているため、将来的には公開されることになります。

  • CSSのカスケードとブラウザデフォルトスタイルの関係は何ですか?

    -CSSのカスケードは、スタイルの優先順位を決定する仕組みです。ブラウザデフォルトスタイルは、カスケードの最下部に位置し、ユーザーが追加したスタイルによってオーバーライドされることがあります。

Outlines

00:00

🎨 CSSリセットとブラウザデフォルトスタイル

CSSリセットやNormalize.cssなどのツールを使用して、異なるブラウザ間で一貫性を保つためにデフォルトスタイルを統一する方法について説明されています。ブラウザが提供するデフォルトスタイル(ユーザーエージェントスタイル)は、ページの可読性を確保するために役立ちますが、異なるブラウザで微調整が必要な場合があります。リセットやノーマライザーはブラウザが提供するスタイルを更新するために使用されますが、すべてのブラウザデフォルトを削除することはありません。ブラウザデフォルトスタイルを確認する方法や、開発者ツールでブラウザスタイルを表示する方法についても触れられています。

05:01

🔍 ブラウザデフォルトスタイルの詳細な確認方法

ブラウザデフォルトスタイルを確認する方法について詳しく説明されています。開発者ツールでブラウザスタイルを表示する方法や、ユーザーエージェントスタイルシートへのリンクを提供する方法が紹介されています。また、Firefoxのユーザーエージェントスタイルシートの例を用いて、ブロックレベルの要素やテーブルのスタイルなど、ブラウザが提供するスタイルの詳細についても説明されています。他のオープンソースブラウザのユーザーエージェントスタイルシートもオンラインで公開されており、Internet ExplorerのスタイルシートもChromiumへの移行に伴い公開される予定です。

Mindmap

Keywords

💡CSS

CSS(カスケーディングスタイルシート)は、Webページのスタイルを定義するための言語です。このビデオでは、CSSを使用してブラウザのデフォルトスタイルをリセットまたはノーマライズする方法について説明されています。CSSを使用することで、ウェブページの外観をコントロールし、異なるブラウザ間での一貫性を確保できます。

💡リセット

リセットとは、ブラウザのデフォルトスタイルを初期化することを指します。これにより、ウェブページのスタイルをよりコントロールし、異なるブラウザで同じ外観を維持することができます。リセットは、CSSの基本的なスタイルを変更することで行われます。

💡ノーマライズ

ノーマライズは、ブラウザのデフォルトスタイルを一貫性のある状態に保つために、一部のスタイルをリセットするプロセスです。ノーマライズは、リセットと似ていますが、より微妙なスタイルの調整を行います。

💡ブラウザデフォルト

ブラウザデフォルトとは、ブラウザが自動的に適用するスタイルの設定です。これらのスタイルは、ユーザーエージェントスタイル(UAスタイル)と呼ばれ、ウェブページが読みやすいように設計されています。

💡ユーザーエージェントスタイル

ユーザーエージェントスタイル(UAスタイル)は、ブラウザが提供するデフォルトのCSSスタイルです。これらのスタイルは、Webページが読みやすいようにブラウザによって自動的に適用されます。

💡インスペクター

インスペクターは、ウェブ開発者ツールの一部で、HTML要素やCSSスタイルを視覚的に検査し、編集するためのツールです。このビデオでは、インスペクターを使用してブラウザデフォルトスタイルを表示する方法が説明されています。

💡コンパイルドパネル

コンパイルドパネルは、ウェブ開発者ツールの機能で、要素に適用されているすべてのCSSスタイルを表示します。このパネルを使用して、ブラウザデフォルトスタイルと開発者が適用したスタイルを比較できます。

💡ルールパネル

ルールパネルは、ウェブ開発者ツールの機能で、特定の要素に適用されているCSSルールを表示します。このパネルを使用して、ブラウザデフォルトスタイルを含めたすべてのスタイルルールを確認できます。

💡ユーザーエージェントスタイルシート

ユーザーエージェントスタイルシートは、ブラウザが提供するデフォルトのCSSスタイルを含むファイルです。これらのスタイルシートは、ブラウザのバージョンに応じて異なりますが、公開されているため、開発者が直接参照できます。

💡カスケード

カスケードは、CSSスタイルの優先順位を決定するプロセスです。ブラウザデフォルトスタイル、ユーザーのスタイル、そして開発者が指定したスタイルがカスケード順に適用され、最終的なスタイルが決定されます。

Highlights

CSS resets and normalization tools, like Eric Meyer's CSS reset and Normalize.css, are used to standardize default styles across different browsers.

Browsers provide a set of default styles, known as user agent styles or UA styles, to make web pages readable.

User agent is the technical term for a browser.

Browser defaults are consistent over time to support both old and new websites.

Resets or normalizers are used to update browser defaults without completely removing them.

Some browser defaults, like block display for paragraphs and inline display for links, are kept for usability.

Inspecting elements in a browser can reveal the impact of browser defaults on a site's styling.

Browser Inspector settings can be adjusted to show browser styles alongside custom styles.

The Computed panel in the Inspector can display all properties applied to an element, including browser defaults.

User agent style sheets can be accessed directly to view the default styles applied by the browser.

Firefox's user agent style sheet is publicly available and can be viewed in the browser or on the Mozilla website.

Other open-source browsers like Chromium and WebKit also have publicly available user agent styles.

Internet Explorer's user agent style sheets are not publicly available but will likely be as they transition to Chromium.

Understanding and visualizing browser defaults in the cascade is useful for web development and styling.

The transcript provides insights into how browser defaults can be managed and utilized in web design.

The speaker encourages viewers to engage with the content by leaving comments and exploring web styling.

Transcripts

play00:00

(digital beeps)

play00:03

- If you've written very much CSS,

play00:05

you've likely run into a reset

play00:08

like Eric Meyer's CSS reset here

play00:11

or a normalizer like Normalize.css.

play00:15

There's all sorts of resets and normalization tools

play00:18

out there, and they're a little bit

play00:19

like preparing the canvas as a painter,

play00:22

trying to get our defaults to a good place

play00:25

where they're consistent across different browsers.

play00:28

Now, if you've ever looked at a website without styles,

play00:30

and we can do that by going to View, Page Styles, No Style,

play00:35

you can see that the browser provides this set

play00:38

of default styles for us.

play00:40

And we sometimes refer to these as browser defaults

play00:43

or user agent styles.

play00:45

User agent is a term that just refers to the browser.

play00:48

It's the technical term for the browser.

play00:50

So sometimes we'll call these user agent styles

play00:54

or UA styles, UA style sheets.

play00:57

If you hear those terms, what we're talking about

play00:59

is the browser defaults.

play01:01

Every browser provides this set of default styles

play01:05

that make the page readable.

play01:07

And of we look at the same page with those removed,

play01:10

what we're seeing is the specification defaults

play01:13

for each property, so display, inline, font weight, normal.

play01:18

So we can see here, it looks like just one long block

play01:21

of text, not very readable and not very useful.

play01:24

Those defaults make sense in sort of an abstract,

play01:27

but once we get to specific HTML elements,

play01:32

the browser provides those styles

play01:34

that give us bullet points on lists

play01:37

and a little bit of padding there

play01:39

and borders around our search box

play01:42

and a button style and different sizes of heading,

play01:46

space between paragraphs, and some things are blocked,

play01:49

and some things are inline.

play01:50

We get link styling, various types of link styling.

play01:53

These are really useful defaults,

play01:55

but they're a little bit different from browser to browser,

play01:58

and some of them come out of the fact

play02:00

that browsers can't really change

play02:02

their defaults very option.

play02:03

They have to support old websites as well as new websites.

play02:07

So mostly these browser defaults don't change

play02:10

over the course of time,

play02:12

and so sometimes we're using a reset or a normalizer

play02:15

to update what the browser is giving us.

play02:18

But we don't generally remove all of the browser defaults.

play02:21

It's useful to have paragraphs and lists be display block

play02:25

and links be display inline and have underlines.

play02:29

So there's various of those that we're going to leave in place

play02:32

even though we build on top of them.

play02:33

So I want to show you how we can see the browser defaults

play02:37

and what impact they're having on our site.

play02:40

So I'm going to start by inspecting this navigation.

play02:43

We can see that I've got a list here,

play02:45

and I've set margin to zero, padding to zero,

play02:50

list-style, none,

play02:51

but I'm not seeing here any of the defaults

play02:54

that the browser would normally provide,

play02:56

and that's because they're turned off

play02:58

in the Inspector by default.

play03:00

So what I'm going to do is go to this three dots,

play03:02

this dropdown menu, go to Settings,

play03:05

and if I scroll down to Inspector,

play03:08

I can see Show Browser Styles,

play03:10

and I'm going to turn that on and go back to my Inspector.

play03:14

And now we can see my margin, my padding, my list style,

play03:18

and if we scroll down just a little bit,

play03:20

we see user agent html.css,

play03:24

and we can see that there's a counter reset there.

play03:28

List-style-type:disc, I've overridden that,

play03:32

and there's a few more things

play03:33

that the user agent style sheets provide.

play03:37

The same is true if I select the body element here.

play03:41

I have a display grid and a margin of zero,

play03:44

and we can see here the user agent style

play03:46

that that's overriding.

play03:48

So that's a display of block and a margin of eight pixels.

play03:52

We can actually click one of these to filter

play03:54

and see just everywhere that display is being set

play03:57

on the body.

play03:58

So that's a quick way to find what we're looking for.

play04:00

We can also see browser styles in the Computed panel.

play04:03

If we go here to Computed,

play04:05

by default we see only the styles that I've applied directly

play04:09

to the body, but I can select this Browser Styles,

play04:12

turn that on, and now I'm seeing every single property

play04:16

that's applied to this element.

play04:18

That's every property in CSS that might be relevant here.

play04:22

And we can see that most of them are just the defaults,

play04:26

and if we scroll, we might find some

play04:29

that have this little triangle,

play04:31

and that triangle means

play04:32

that something has been set explicitly.

play04:35

And in this case, I set the border box to screen.

play04:38

We can filter this, as well.

play04:40

So I'll filter that down to margins,

play04:43

and here, looking at the margin-bottom,

play04:45

we can see that I've set it to zero pixels,

play04:48

and the browser also set it to eight pixels.

play04:51

We can see browser or user agent default styles

play04:55

both in the Computed panel and in the Rules panel

play04:58

if we turn them on.

play04:59

They're not turned on by default.

play05:01

If you're like me and you want to go deeper,

play05:02

you want to see every single style

play05:04

that the browser is applying to your entire page,

play05:08

the quick way to get there is we can actually just click

play05:10

on this where it says html.css,

play05:13

either here or in the Rules panel.

play05:16

If we click on that, it's going to open this file,

play05:19

which you can also go to directly.

play05:21

I'll post the link below.

play05:22

And this is the user agent style sheet itself.

play05:25

This is Firefox user agent style sheet.

play05:28

Starts with a lot of bidirectional styles.

play05:31

We get to the block section

play05:33

where we set all these block level elements

play05:36

to display block, including the body,

play05:39

which also gets that margin of eight pixels,

play05:41

paragraphs, block quotes, figures, et cetera,

play05:45

and there's a lot doing on in here.

play05:47

We can see use of selectors that aren't very familiar yet

play05:50

but hopefully will be.

play05:52

Here's all the styles for tables, et cetera, et cetera.

play05:55

That's the link for getting to the user agent styles

play05:59

in Firefox itself

play06:01

in whatever version of Firefox you're using.

play06:03

If you're not actually in Firefox,

play06:05

that source code is public.

play06:08

So you can go to this link,

play06:10

and you'll see that same style sheet here

play06:14

on the Mozilla website.

play06:17

The same is true for other opensource browsers.

play06:20

Chromium browsers have their user agent styles

play06:24

publicly online, and the same is true for WebKit.

play06:27

WebKit is the code behind Safari.

play06:30

I haven't been able to find public style sheets

play06:33

for Internet Explorer, but as they're moving over

play06:36

to Chromium, those will become available soon.

play06:38

But whether you're looking at these style sheets directly

play06:40

or turning them on in the Inspector

play06:43

and being able to visualize how they fit in the cascade

play06:46

with your other styles, that's all very useful as we work.

play06:50

So hopefully that's helpful.

play06:51

I'd love to hear your thoughts.

play06:52

Leave comments below, and have fun styling the web.

play06:56

(upbeat digital music)

Rate This

5.0 / 5 (0 votes)

Related Tags
CSSリセットノーマライザーブラウザデフォルトユーザーエージェントスタイルウェブデザインスタイルカスケードウェブ開発クロスブラウザリファクタリングウェブアクセス
Do you need a summary in English?