Why Is CSS So Weird?

Mozilla Developer
2 Oct 201915:07

Summary

TLDRこのビデオスクリプトは、CSSがウェブ上でのレイアウトに不可欠であること、そして人々がCSSに対して持つさまざまな意見を探ります。CSSは文書向けに設計されたという批判がある一方で、ウェブが進化しアプリケーションを構築する場となった現在でも、CSSはその役割を果たし続けています。ティム・バーナーズ=リーがウェブを発明した当初の目的と、CSSがどのようにしてウェブの成長に適応してきたかについて説明し、CSSが異なるデバイスや表示方法に対応するためにどのように設計されているかを解説します。最終的に、CSSの奇妙さは、ウェブが多様な環境で動作するための適応性と柔軟性を提供するためのものであり、これはウェブの根本的な特徴であると結論づけます。

Takeaways

  • 😀 CSS was created for documents, but has evolved for broader web applications
  • 👩‍💻 The web gives control of display to the user, not the designer
  • 🌐 CSS allows web content to adapt across contexts and devices
  • 🖥 Browsers parse and display CSS based on an algorithmic cascade
  • 📐 CSS works through flexible design suggestions, not rigid programming instructions
  • 😕 Losing visual control is a tradeoff for universal access
  • ⚖️ Graceful degradation is an intentional feature of web languages
  • 🎭 CSS relationships create contextual meaning, like theater stage directions
  • 🔧 Overflow in CSS avoids harming content over design constraints
  • 🌈 Accepting lack of control allows more accessible, flexible designs

Q & A

  • CSSがウェブ上で使用される主な目的は何ですか?

    -ウェブ上でのレイアウトやデザインを定義するために使用されます。

  • CSSについてよくある意見は何ですか?

    -CSSは壊れている、素晴らしい、またはその両方であるという意見がよくあります。

  • 「CSSは素晴らしいが、オーバーフローのデフォルトに何か問題があるのではないか」というミームは何を示唆していますか?

    -CSSの挙動が予期せぬ形であることを示唆しており、それが機能かバグかについての議論を呼んでいます。

  • CSSが文書向けであるとの主張に対する反論は何ですか?

    -ウェブ全体が当初文書向けに作られたが、技術の進化によりアプリケーションなど様々な用途に対応可能になったという反論があります。

  • CSSが「変わった」言語であるとされる理由は何ですか?

    -他のプログラミング言語やデザインプログラムとは異なる動作をするため、特異な言語と見なされます。

  • CSSの「カスケード」とは何ですか?

    -異なるスタイル情報源を組み合わせ、それらがどのように互いに上書きするかのルールセットです。

  • CSSを宣言型言語とする理由は何ですか?

    -特定の結果を再現するための手順を記述するのではなく、望ましい結果の意図を記述するからです。

  • CSSの設計思想において、なぜ「クライアント側に制御を残す」ことが重要なのですか?

    -ウェブが異なるデバイスでアクセス可能であること、そしてユーザーが最終的な表示を制御できるようにするためです。

  • CSSの「頑強性」とは何を意味しますか?

    -未知の要素や属性を無視し、後方互換性を保ちながらエラーを静かに処理する能力を指します。

  • CSSがプリントメディアとウェブメディアの違いをどのように扱っているかの例は何ですか?

    -プリントメディアではデザイナーが全てを制御できますが、ウェブではユーザーやクライアントデバイスが表示を制御するため、CSSでは適応性や頑強性が重視されます。

Outlines

00:00

🌐 WEBの誕生とCSSの必要性

ティム・バーナーズ=リーが1989年にWWWを開発した際、接続されたドキュメントを共有することを目的としていた。当初は科学論文を共有することが主眼だったが、ウェブはドキュメント共有の場として誕生した。CSSはその本来の目的とは異なるものの、ドキュメントをレイアウトするために必要不可欠なものとしてpositionsされている。

05:00

🌐 W3Cのミッションステートメント

W3Cはオープンスタンダードを推進し、誰もが利用できるウェブの実現をミッションとしている。これはティム・バーナーズ=リーの当初の理念を引き継いでいる。ウェブ上のコンテンツ制作者からコンシューマーへのパラダイムシフトが起きており、コンテンツの表示方法へのコントロールが低下していることが課題となっている。

10:01

🔀 CSSの必要性

CSSは意図を宣言的に記述する言語で、ブラウザが柔軟に解釈してレイアウトできるように設計されている。これはウェブが多様なデバイスで表示可能であることを実現するうえで重要な機能である。CSSはドキュメントからアプリケーションへの移行を視野に入れた言語なので、意図的にそう設計されていることを理解する必要がある。

Mindmap

Keywords

💡CSS

カスケードスタイルシート。ウェブ上のレイアウトとスタイルを制御するために使用される。

💡文書

最初のウェブサイトは文書を共有することに焦点を当てていた。

💡適応

CSSはコンテキストに適応する必要がある。ブラウザーがさまざまなデバイスでコンテンツを表示できるようにする。

💡制御

印刷されたページとは異なり、ウェブ上ではクリエイターが最終的なディスプレイを制御できない。

Highlights

CSS is intentionally designed to be device-agnostic and degrade gracefully across different interfaces

The cascade in CSS allows multiple style sources to combine into a single rendering, with the browser making final decisions

CSS is a declarative language focused on intent rather than steps to achieve a visual output

On the web, the client controls display rather than the content creator having full control

CSS provides graceful degradation and progressive enhancement out of the box due to its resilience

Context is very important for CSS due to diverse interfaces and interactions

The CSS presentation layer is designed to be optional and fall apart gracefully if needed

Allowing content overflow is the default in CSS to avoid losing data

Losing design control is a feature on the web, allowing universal access across devices

CSS works best when width/height aren't overdefined, using relative units instead

The web's adaptability to context means applications lose some design control

CSS helps design for an unknown canvas across devices and interfaces

Losing absolute design control is a limitation of print, not the web

The web gains universal access by giving up some design control

CSS is uniquely equipped to handle designing for unknown contexts

Transcripts

play00:00

(upbeat music)

play00:04

- If you're anything like me,

play00:05

you spend a lot of time making things for the web.

play00:09

And that often involves using CSS

play00:12

to lay things out on the web.

play00:14

Whether you're using that with a preprocessor

play00:17

or directly in raw text files

play00:21

or through JavaScript in some way,

play00:24

CSS is something that we all have to use on the web.

play00:27

And we hear quite often a lot of opinions about CSS.

play00:30

It's either broken or it's awesome

play00:32

or maybe sometimes both at once.

play00:35

This popular meme,

play00:36

CSS is awesome but seems to imply that maybe

play00:39

there's something wrong with this overflow default.

play00:42

And it's a little bit of a, is it a rabbit?

play00:45

Is it a duck?

play00:46

Depending on how you look at this,

play00:48

it's either a feature or a bug,

play00:49

but either way we have to express

play00:52

our opinion loudly on Twitter.

play00:53

And I hear often that the problem with CSS

play00:56

is that CSS is for documents.

play00:59

And now we're building applications,

play01:01

and applications are in such a different field

play01:04

that CSS will never make that transition.

play01:07

And that's partially true.

play01:09

When Tim Berners-Lee invented the web

play01:12

in 1989 and 1990 and made the first website,

play01:15

he was very clear that he was trying

play01:17

to make a web of connected documents,

play01:19

and specifically at that point scientific articles.

play01:23

He had this vision for making these articles

play01:26

available to scientists around the world for free.

play01:30

You can see here emulated the Line Mode Browser

play01:34

for older machines without graphic interfaces.

play01:37

And I have to use numbers to go to a link.

play01:39

Here it says the project is based

play01:41

on the philosophy that much academic information

play01:44

should be freely available to anyone.

play01:46

But it's not really fair to say

play01:48

that CSS was only for documents.

play01:50

It's the entire web that's only for documents at that point.

play01:53

And it's a little bit like saying

play01:54

that the Gutenberg press is only for bibles

play01:56

just because that was one of the first use cases.

play01:59

The web is a very young medium,

play02:02

at this point less than 30 years old,

play02:04

and we're still figuring it out as we go.

play02:07

But the underlying technology is developing quickly,

play02:10

both the devices and computers that we're working on,

play02:13

also the languages themselves, and also what we're building.

play02:17

And it's an open standard

play02:18

so we can all work on that together.

play02:21

And as the web grows, we make more and more web things,

play02:24

moving from documents and sites to applications,

play02:28

basically full desktop and mobile applications,

play02:32

entire businesses exist on the web.

play02:35

We're building all sorts of cool things

play02:37

and they're getting bigger and cooler

play02:39

and more difficult to build in lots of ways,

play02:42

and that raises the question

play02:44

what are we going to do now

play02:46

that everything is on the web?

play02:48

Do the same rules apply?

play02:49

Does CSS specifically work on the modern web?

play02:52

And really why is CSS so weird?

play02:55

'Cause it is weird.

play02:56

It doesn't work the way that a lot of other languages work,

play02:59

and it doesn't work the way

play03:01

that we're used to design programs working.

play03:03

It is a very strange language.

play03:05

And part of that goes back to these early documents.

play03:08

And this time I'm going to look at it in a modern browser.

play03:11

The same file still work even in our latest browsers.

play03:16

And some of the constraints that

play03:18

Tim Berners-Lee mentions here

play03:21

in this first website already,

play03:23

when designing the HTML document type,

play03:26

consideration was given to a certain simplicity

play03:29

in order to allow many browsers

play03:32

and hopefully many editors

play03:34

to be developed on many platforms.

play03:36

In order to make this platform agnostic,

play03:38

HTML is a very simple language intentionally.

play03:43

And the same is true of CSS a couple years later.

play03:45

But here, this implies no device-specific markup.

play03:48

That makes sense, we don't want anything

play03:50

that can only run on one machine or on another

play03:53

because that would defeat this global idea of the web.

play03:57

Or anything which requires control

play04:00

over fonts or colors for example.

play04:03

And what he's noticing here

play04:05

is that if we're going to allow multiple devices

play04:08

with different graphic abilities to display the same web,

play04:14

then we have to give up control

play04:16

of fonts and colors and display properties.

play04:19

So right from the beginning,

play04:21

there's a problem with design on the web.

play04:24

It's problematic to design in a way

play04:27

that's going to be device agnostic.

play04:30

In 1994 Tim Berners-Lee forms

play04:32

the World Wide Web Consortium

play04:34

with a number of businesses.

play04:36

The membership is quite large

play04:37

and made up of all sorts of organizations

play04:40

from easily recognizable tech companies

play04:43

to browser vendors to banks.

play04:47

Anybody that is interested in the future of the web

play04:50

can become a member of this organization

play04:53

and help guide the web into the future.

play04:56

More important here on the W3C website

play05:00

is this idea that it has a mission statement.

play05:02

The web has a mission statement and it's based very much

play05:06

on that initial document from Tim Berners-Lee.

play05:09

We have the open standards principles which mean

play05:12

that everything is going to be developed in the open

play05:14

and no one company isn't going to have control

play05:16

over the future of the web.

play05:18

But then we also have these ideas,

play05:19

this principles of the web.

play05:21

It's a web for everyone which includes

play05:24

both accessibility issues and internationalization.

play05:28

And it's a web on everything,

play05:30

it's a web of devices,

play05:31

it's a web that can be on mobile,

play05:33

it can be on watches,

play05:35

all sorts of different technologies.

play05:37

That mission carries on

play05:39

and some of the same design problems carry on with it.

play05:43

This is a radical shift in power

play05:45

from creators to consumers to audience.

play05:49

Audience now controls the display of my content

play05:55

which wasn't true on the printing press.

play05:58

If I'm designing a poster or a T-shirt

play06:00

or anything that's going to be printed,

play06:02

I can control every step of the process

play06:06

from the colors and the fonts

play06:08

to what I'm printing on

play06:09

and what type of printing I'm doing.

play06:11

And when I ship a final product,

play06:13

the audience that I send it to gets exactly what I designed

play06:17

and they see exactly what I intended for them to see.

play06:21

On the web that's just not the case.

play06:23

On the web the client controls the display.

play06:26

And by client I mean everything

play06:29

on the other end of the system.

play06:31

The people on the other end

play06:34

can choose their settings, their default settings,

play06:37

they can add styles to my site for their browser.

play06:41

Their device has some control

play06:43

over what it can handle and what it can do.

play06:45

The browser itself also affects the capabilities.

play06:48

There's all these pieces that have to get put together

play06:51

on the client side to display.

play06:54

And I don't know all those variables

play06:56

when I'm writing an application.

play06:59

In reality we're designing for an unknown infinite canvas,

play07:03

and we don't have all the variables.

play07:06

Rather than designing with this control

play07:09

over exactly what we should ship,

play07:12

we're designing for change

play07:15

and for movement and for adaptation.

play07:18

We know how to do this,

play07:19

this is not unfamiliar territory.

play07:22

We can make car seats that move forward and backward

play07:25

so that different people fit.

play07:27

Seat belts do the same thing.

play07:29

We can broadcast color TV

play07:31

and watch it on a black and white television

play07:34

because the technology understands

play07:36

how to degrade gracefully in these ways.

play07:39

Cascading style sheets are built around the same idea.

play07:43

They're first proposed in 1994

play07:45

and then the spec is written in 1996,

play07:48

but they don't actually appear fully

play07:51

in any browser until the year 2000.

play07:54

What cascading style sheets do,

play07:56

the reason for the cascade is to take

play07:58

all these different sources of information,

play08:01

all these different variables, and put them together.

play08:04

The cascade is a set of rules for how these different styles

play08:08

are going to fit together and override each other,

play08:11

and in the end the browser takes all of those variables,

play08:15

puts it all together and comes out

play08:17

with a single final rendering style.

play08:20

And only the browser can do that

play08:22

because only the browser has all that information.

play08:25

So as a designer I'm no longer controlling the output,

play08:28

I'm suggesting and that's why CSS is a declarative language.

play08:33

That means that rather than describing,

play08:36

as we might in JavaScript,

play08:37

the steps to take to recreate a specific outcome,

play08:40

I instead describe the intent of my outcome.

play08:44

What am I going for?

play08:46

What am I pushing towards?

play08:48

And I'm trying to give the browser

play08:49

as much meaningful information as possible,

play08:52

subtext and implications,

play08:55

so that the browser can make smart decisions

play08:57

about what to do with those styles.

play08:59

That's where things like Normal Flow,

play09:02

the way that block and inline elements flow together,

play09:05

and relative units allow us to create

play09:08

these relationships in a meaningful way

play09:10

so that the browser can make smart decisions.

play09:12

It's an intentionally resilient system

play09:15

and resilient language where everything fails silently,

play09:18

and we can actually see that here again on his site.

play09:22

The hypertext markup language,

play09:24

parsers should ignore tags which they do not understand,

play09:28

and ignore attributes which they don't understand

play09:30

of tags that they do.

play09:32

So even at the smallest level,

play09:34

browsers are supposed to understand

play09:36

everything they can and ignore everything else,

play09:39

and that's how we get this total

play09:40

backwards compatibility where the early website

play09:44

is still available on modern browsers

play09:46

because everything is resilient,

play09:47

everything is backwards compatible.

play09:49

It also has to be intentionally contextual for this to work.

play09:53

Everything depends on

play09:55

not only the size of the screen

play09:57

but the type of interface.

play09:59

How are you interacting with it?

play10:01

Is it a keyboard?

play10:02

Is it touch?

play10:02

And broadening out,

play10:03

is it a braille keyboard?

play10:05

Is it headphones?

play10:07

Are you listening to websites?

play10:08

There are so many different interfaces that the same styles

play10:12

just wouldn't make sense across interfaces.

play10:15

And so context is very important to CSS.

play10:18

And that's fundamentally different from most languages.

play10:21

In JavaScript we try to isolate functions,

play10:23

and in CSS isolation doesn't actually make much sense

play10:27

if we're looking at this

play10:29

in terms of the fundamental vision

play10:32

of device agnostic content.

play10:34

So really CSS is this presentation layer

play10:38

that we're okay losing.

play10:39

That's fundamental to the web

play10:41

that we can layer these styles on top

play10:44

but they have to be optional

play10:46

because some people are using the internet

play10:49

through systems where they won't see this presentation.

play10:52

And that gives us right away graceful degradation

play10:56

and progressive enhancement built in.

play10:58

The whole thing is supposed to fall apart in a graceful way.

play11:02

That's how the web is designed.

play11:04

So when we're looking at this meme,

play11:05

we've over-defined some things for how CSS works.

play11:09

CSS is going to work best when we don't define

play11:12

both height and width at the same time,

play11:15

or in this case define a font size that is so large

play11:19

that the font overflows the width that we've set.

play11:23

It generally works better if we use min-content

play11:29

or something that is going to respect the content

play11:32

that it's flowing around

play11:33

because the browser has to make these decisions for us.

play11:36

We don't have to get that visual overflow.

play11:38

There's many different settings that we can use.

play11:41

Overflow visible is just the default

play11:43

because CSS is designed to not lose content,

play11:47

to not cause harm.

play11:49

In order to not cause harm,

play11:50

we show what overflows by default.

play11:54

And we can see that that's different

play11:55

from a program like InDesign

play11:57

where here I had to use two separate boxes

play12:00

in order to get that same image.

play12:03

Because in InDesign when I overflow a box,

play12:07

and let's actually take that slower,

play12:10

things simply disappear completely.

play12:13

I don't think that that's a better system for the web.

play12:17

That doesn't seem like the sensible default either.

play12:21

But they're trying to solve different problems.

play12:22

InDesign knows that you'll come back in

play12:25

and make some adjustments,

play12:27

whereas in CSS the browser has to make

play12:29

the adjustments for you.

play12:31

As a playwright, this stands out to me

play12:33

as something that I do in another field.

play12:35

So when I write a script, I know that the actors

play12:39

are going to say the lines that I wrote,

play12:41

and they'll say them in the order that I wrote them,

play12:43

and I can even mark it up with who should say what.

play12:47

But when I write stage directions,

play12:49

I can say how I think the set should look

play12:52

and how I think the characters should look

play12:54

and how I think they should act.

play12:55

And I can say all these things

play12:57

but all of them are suggestions,

play12:59

and the production company

play13:00

is likely to make their own decisions

play13:02

and to throw out my stage directions

play13:04

and do something completely unique

play13:07

because they're working with different actors

play13:08

in different spaces under different constraints

play13:10

and for a different audience.

play13:12

And it makes sense that the performance

play13:14

has to be updated to fit a new context.

play13:17

Like theater, CSS is contextual,

play13:20

and we can make those suggestions,

play13:22

but we can't insist on the final design.

play13:24

CSS is intentionally different.

play13:26

It intentionally works this way.

play13:29

And to quote John Allsopp from the year 2000

play13:32

when CSS was first coming into browsers,

play13:35

he says, "Really we can think of this

play13:37

"as a bug of the system,

play13:38

"or we can think of control

play13:40

"as really a limitation of the printed page."

play13:44

It's a limitation of print

play13:45

that I can control everything in it,

play13:47

and if I hand my poster to somebody who can't see,

play13:52

they have no ability to read it.

play13:54

And it's a feature of the web

play13:56

that anybody can access it from any different device.

play14:00

That's actually a feature and that's something

play14:02

that we should embrace and figure out how to use.

play14:05

And it doesn't mean that the problem is solved entirely,

play14:07

but CSS is designed around that idea,

play14:11

and that's always going to be a difficult problem to solve,

play14:13

but one that we have to do in a smart way

play14:16

that keeps the control on the client side.

play14:19

Because the web adapts to context,

play14:21

so even the modern web,

play14:23

even the most powerful applications,

play14:25

desktop style applications on the modern web,

play14:28

when we put them on the web,

play14:30

the reason to do that is we get universal device support,

play14:36

but the trade-off is we lose control, and that's a feature.

play14:40

And CSS is there to help us design

play14:43

for that audaciously unknown canvas

play14:47

in a way that no programmatic language would be able to do.

play14:52

That's why CSS is so weird.

play14:54

(upbeat music)

Rate This

5.0 / 5 (0 votes)

Do you need a summary in English?