« resources

Company Workshop

Cascading Styles

The origins of HTML and CSS

workshops.oddbird.net/rf24/cascade/

Cmd/Ctr-K for Controls

Introductions…

  • Name & pronouns
  • Location
  • Brief relation to CSS (feeling, experience, role, etc)

Two Days Together

  1. CSS Mental Model
    cascading, declarative, and contextual
  2. CSS Architecture
    naming conventions & progressive enhancement

Takeaway A CSS Mindset

  • You don’t need to memorize everything
  • Understand the mental model
  • Understand what’s possible
  • Q&A at end of each day
  • Also ok pause and discuss!

Cascading Styles

Let’s do this…

  • Any questions before we start?
  • We’re here to talk about…

CHSS

Cascading HTML style sheets -- a proposal, Håkon W Lie, 10 Oct 1994
Håkon Lie, Cascading HTML style sheets – a proposal [w3.org]
  • CHSS
  • Håkon Lie, 1994
  • email, still archived online
Historical Style Sheet proposals
Historical Style Sheet proposals [w3.org]
  • not the only
  • not the first
  • solves a major problem for the new platform

Technology Is Political

  • not technical
  • but philosophical
  • political, like all decisions we make
  • designing a new platform or interface
The first world wide website in the WWW Hypermedia Browser/Editor, on the neXt desktop -- an exercise in global availability
  • Team at CERN
  • first web browser
  • Hypermedia WWW Browser and Editor
  • NeXt machine
  • graphic interface
Old IBM desktop with a text-only green on black display

You can’t make a web that’s world-wide, by saying it works on my machine, and everyone else is an edge-case.

The second browser, a text-only terminal with numbered links for keyboard control
Line Mode Browser, developed by Nicola Pellow
  • Nicola Pellow
  • Line Mode browser
  • text-only
  • no install
  • any device with an internet connection

Web for all. Web on everything.

— W3C Mission Statement

  • Mission statement of W3C
A zillion different devices of all sizes
Over the shoulder, a person wearing headphones, using a braille display attached to a laptop
  • includes a range of assistive technologies
  • like this braille display
  • or ‘screen readers’ which read what’s on the screen
Various home 'smart' speakers
  • also devices without any screen involved
Indiana Jones covered in cobwebs, looking frustrated.
  • The web is getting everywhere
  • And it’s kinda gross

Web for all. Web on everything.

— W3C Mission Statement

  • If we really want this to work
  • Everywhere for everyone
World Wide Web
World Wide Web Project [info.cern.ch]
  • leads to difficult constraints
  • documented on the original website
  • also still available
Resilient HTML [present, debug]
  • browsers ignore code they don’t understand

[DEMO]

  • individual attributes
  • entire HTML tags

Protect the Content

across devices, and over time

a web prime directive…
  • the code is optional
  • the content is essential
  • whatever else happens
  • browsers should protect the content
  • that’s why…
World Wide Web
World Wide Web Project [info.cern.ch]
  • we can still see
  • first website on modern browsers
Workshop page on oddbird.net displayed as black and white text on the WWW browser emulator
worldwideweb30.com c/o Remy Sharp [worldwideweb30.com]
  • modern website, on the first browser
  • (this is an emulator you can play with)
  • No css
  • No images
  • all the text is there

It is required that HTML be a common language between all platforms

— WWW Project, HTML constraints

  • for graphic design
  • limitation is more dramatic
  • to be a common language anywhere…

…This implies no device-specific markup, or anything which requires control over fonts or colors.

— WWW Project, HTML constraints

Web Design Will Never Happen

Viola WWW browser demonstrating early stylesheets
  • problem isn’t styles
  • early browsers internal stylesheets
The second browser, a text-only terminal with numbered links for keyboard control
Line Mode Browser, developed by Nicola Pellow
  • Even text-only browser
  • headings, paragraphs, etc
  • But the styles are different per browser
  • not per website
InDesign book-cover layout
  • not the way print works
  • define everything…
  • page size (static, forever)
  • export to PDF, jpg,
  • send it to the printer
Published book
Published book with badly super-imposed hand-pointer cursor and scribbled word click!
Published book
  • It just sits there
  • The same was true for other digital formats at the time…

PostScript, 1982 Page Description Language

The source code for PDFs
  • PostScript around almost a decade
  • page description language
  • Like print
  • describes a static page
  • how big is it? where does each thing go?
  • We set fonts, colors, etc.
  • We have complete control, but…

The fact we can control a paper page is really a limitation of that medium.

— John Allsopp, A Dao of Web Design

  • That control comes at a cost
  • The page, print or PDF, is a static medium
  • can’t adapt to context or preferences
  • a limitation of the medium

Web Styles Must Be Responsive

a radical shift!
  • web is different
  • for everyone, on everything
  • sites aren’t static pages
  • what we ship is not always what our audience sees
  • styles must adapt to situations…

@media min-width

Viewport dimensions
  • Not just the width of the viewport

@media prefers-reduced-motion

User needs & preferences
  • user needs & preferences

@media hover

Device interfaces
  • device interfaces

@supports container-type: inline-size

Browser capabilities over time
  • changing capabilities over time
  • Content that’s always changing

Web Design Seems Impossible

  • Under those constraints
  • Unknown content, unknown display, unknown overrides
  • web design (reasonably) seemed impossible, but…

HTML totally eliminates any visual creativity that a document’s designer might have.

— Roy Smith, www-talk “Re: Adobe’s PDF”

  • No one was happy with that outcome
  • When every site looks the same
  • That’s boring for both authors and users
  • People want visual creativity
Mosaic browser
Mosaic, 1993
  • Turning point, 1993
  • Mosaic added image tag to HTML
  • (Before web standards)
  • web styles suddenly possible
  • put everything in an image, and it never changes!
A pixelated broken-image icon, showing a photo torn at one corner
  • or it doesn’t show up at all
  • and we lose everything that makes HTML special
  • Can’t protect structured content in an image…
  • If it doesn’t load, it’s lost

The web would have become a giant fax machine where pictures of text would be passed along.

— Håkon Lie, 2014 interview

  • A real risk to the platform
Historical Style Sheet proposals
Historical Style Sheet proposals [w3.org]
  • 1993-1994
  • a rush of different proposals

…Allow the author to attach style hints.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • author style hints

Styles are suggestions or hints about behavior, not rules

— Robert Raisch, Request for comments: STYLESHEETS

  • Not rules, but hints and suggestions.
  • (phrase shows up over and over)

Provide hints that the browser may or may not use.

— Håkon Lie, Cascading HTML style sheets – a proposal

A set of HINTS or SUGGESTIONS to the renderer which might be used

— Robert Raisch, Request for comments: STYLESHEETS

  • Sometimes all-caps
  • [slide]

Provide authors and publishers with stylistic influence without resorting to page description languages.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • In Håkon’s proposal…
  • authors and publishers have
  • stylistic influence
  • without resorting to page description languages
  • without giving us full control
  • Because we’re not alone in this…
We're Not Alone (in big block letters, in space)
  • We’re part of an ecosystem
  • Our decisions impact other people
  • So we don’t get final say
Same We're Not Alone, with browser logos on top
  • We’re collaborating with browsers
  • (instructed to ignore us)
Same We're Not Alone, with browser logos and a guy in construction clothes carrying a laptop
  • Also the people who interact with our sites
  • (super cute in their handy tool belts)
  • On their chosen devices
  • (with varying capabilities)
  • And we’re also collaborating with…
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • aliens 👽
  • Maybe, who knows?
  • We should collaborate with them…
ET and the kids flying their bicycles across the sunset
  • just trying to get home.

The CHSS proposal is explicitly designed around this collaboration

This proposal tries to soften the tension between the author and the reader.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • Designed to soften the tension

The user/browser specifies initial preferences and hands the remaining influence over to the document [authors].

— Håkon Lie, Cascading HTML style sheets – a proposal

  • By allowing everyone to contribute styles
  • In an orderly fashion
  • Using the same language!
  • First the browser and user,
  • and then the document
css…
/* a 'declaration' */
property: value;
  • Each of us writing
  • our style hints as declarations,
  • a property and a value
css…
/* a 'declaration' */
color: blue;
css…
/* a 'declaration' */
color: blue 64%;
  • In the initial proposal
  • We could also add a percentage to every declaration
  • How much we care
  • Here we’re handing over exactly 36% of the influence
  • To our collaborators
css…
/* a 'declaration' */
color: blue !important;
  • That idea was simplified later
  • Into a binary
  • Every declaration has either 0% or 100% importance
  • But we’ll come back to that
css…
/* a 'declaration' */
color: blue;
css…
/* a 'block' */
{
  background: white;
  color: mediumVioletRed;
}
  • group them into blocks
html…
<!-- 'inline' (or 'element attached') styles -->
<p style="
  background: white;
  color: mediumVioletRed;
"></p>
  • attach directly to elements in HTML.
html…
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
  • but that can get repetitive
  • if we want to re-use the same styles on multiple elements
  • ideally, create design systems

…A simple mapping between HTML elements and presentation hints.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • CSS helps by providing “a simple mapping…”
css…
/* a selector, with attached declarations… */
/* a 'style rule' (or 'rule set') */
p {
  background: white;
  color: mediumVioletRed;
}
  • Selectors
  • Which we can attach to declaration blocks,
  • forming rule-sets.
  • Each selector maps our rule set…
html…
<p>This is a short paragraph</p>
css…
p {}
  • … to elements in the document.
  • (this is the majority of the CSS we write)
  • Then we can…
html…
<!-- a 'style sheet' -->
<link rel="stylesheet" href="styles.css">
css…
/* another 'style sheet' */
@import url('styles.css');
  • Combine our rule sets into style sheets,
  • and import them from our document,
  • or other style sheets.
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • Not just us as document authors…
  • Anyone involved can contribute style sheets
  • The users interacting with our document,
  • and the user agent (or browser) they use.

An ordered list (cascade) of style sheets.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • Then all these style sheets get merged…
  • Into an ordered list (or ‘cascade’) of styles
  • that should be applied to the same document.
  • Of course, this leads to conflicts!…
html…
<button type="submit" id="send" class="action">
css…
button          { background: gray; }
.action         { background: darkBlue; }
[type=“submit”] { background: darkGreen;
                  background: var(--submit, black); }
#send           { background: maroon; }
💥 Conflicts!
  • We have any number of declarations
  • coming from different sources
  • likely applying different values
  • to the same properties, on the same elements!
  • What are we going to do?
  • Stack all these background colors on top of each other?
  • Create a rainbow gradient?

#484d63

  • Mix them together into a sludge?
  • This was the original idea,
css…
/* a 'declaration' */
color: blue 64%;
  • Remember those importance percentages?
  • We could use them for mixing!
  • But the results aren’t great
  • And it’s not clear how you would ‘mix’ something like a font
A comic-sans papyrus mashup font specimen with upper/lower latin characters and punctuation, on textured parchment with a drawing of Anubis laying face-up on snoopy's dog house, and a small tagline claiming the most beutifulest font ever created. ever. full special character set included (not shown here)
Comic Papyrus by Ben Harman
  • Although I wish we had tried harder on that one

For Browsers Every CSS Property
On Every HTML Element,
Must Have a Single Value

  • Browsers must resolve conflicts somehow
  • Before they can render the page
  • Every CSS property
  • on every HTML element
  • must have a single value

595 Distinct Properties*

* including Editor’s Draft proposals

w3c List of CSS Properties
  • All 595 distinct properties
  • (or at least the long-hands from that list)

Every <button> Needs One Background-Color
& One Text Color
& One Padding-Left
& One Margin-Inline-End
& …

  • Every button needs
  • one text color,
  • one padding-left,
  • one margin-inline-end, etc.

The Cascade (Process) Resolves Conflicts

  • what we call ‘the cascade’ now
  • is a browser process
  • merging all the stylesheets, rules, and declarations
  • (‘cascading’ them together)
  • and resolving conflicts
  • That process ensures
  • we don’t have extra values

Inheritance… Fills in Missing Values

  • And then inheritance helps clean up
  • By filling in some of the missing values
  • We’re not going to set all 500 some every time
  1. Filtering
  2. Cascading (includes specificity)
  3. Defaulting (includes inheritance)
  4. Resolving
  5. Formatting
  6. Constraining
Value Processing
  • Both ‘cascading’ and ‘inheritance’
  • Part of a process called value resolution
  • A series of steps for converting declarations into a rendered site
screenshot
[Cascading & Inheritance]
  • They’re important parts of the process
  • The spec that defines all of this is called
  • ‘Cascading & Inheritance’

Input… A “Cascade” of Style Sheets

  • We start the process with a cascade of style sheets
  • (from authors, users, and browsers)
  1. Filtering (declared values)
  2. Cascading (cascaded value)
  3. Defaulting (specified value)
  4. Resolving (computed value)
  5. Formatting (used value)
  6. Constraining (actual value)
  • Each step gets us closer to the actual value
  • Applied when rendering an element

Cascade & Inheritance Internal Browser Algorithms

  • On the one hand,
  • This is all internal logic, right?
  • Just an algorithm that browsers use…
Tina Turner as Aunty Entity in the Mad Max Thunderdome, with the law 'Two styles enter, one style leaves' in bold text
Necessary Browser Algorithms
  • to thunder-dome our declarations
  • Two styles enter, one style leaves…
The Crab Nebula photo: Webb Space Telescope
Description of Web Reality
  • Almost like the laws of physics…
  • A way of describing the universe around us,
  • The way the world works.
  • That’s all true, but also…
Yoda reaching out to control the force, surrounded by jungle swamp
Expressive Authoring Tools
  • tools provided to us, intentionally
  • part of the language,
  • designed for us to communicate…
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • all of us,
  • not just as authors,
  • but also as users…

Express… Purpose & Priority

  • Allowing us to…
  • Provide more detail
  • About the purpose and priority
  • Of our hints and suggestions.
  • Makes the collaboration possible
  1. Filtering (list of declared values)
  2. Cascading

  3. Defaulting
  4. Resolving
  5. Formatting
  6. Constraining
  • We’ll skip filtering for now
  • That involves parsing all the CSS
  • And narrowing down a list of all the declared values
  • That are relevant for styling an element
  • Now we know what conflicts exists

2. Cascading… Resolve any Conflicts
between Declared Values

  • And we can resolve any conflicts between them
  • By cascading the declared values together
Mechanical coin sorter on a table, with a ramp at the top and a small-to-large series of slots
  • Cascade works like a coin sorter
  • Measuring the priority of each declaration
  • See which ones go farthest
Mechanical coin sorter duplicated multiple times in semi-transparent overlays
  • We do this over and over
  • Until we have a single coin
  • Each time comparing different aspects
  • Not just size, but shape, width, metal, whatever
Same coin sorter, with all slots crossed off except for the largest one with coins in it, and an arrow pointing at those coins that says 'move on'
  • At each step
  • the coins that made it the farthest move on
  • Everything else is discarded…
  • We can ignore all but the final column with coins
  • Ok, but not coins -
css…
/* a 'declaration' */
property: value;
  • We’re talking about declarations.
  • So what are the things we can measure and compare?
    • &
  • (any thoughts)?
  • There are 7 steps now in the cascade
  • And the first step has two parts
The Cascade (as a funnel) [present, debug]
  1. Who requested it? (origin)
  2. How much do they care? (importance)
  3. Does it come from the shadow DOM? (context)
  4. Is it an inline style? (element attached)
  5. What layer is it in? (cascade layers)
  6. How specific is the selector? (specificity!)
  7. How close is the scope root? (proximity, new)
  8. Which value was declared last? (order, single)

🗺️ Origins… Who Requested The Style?

  • From the top
  • What’s the origin of the declaration?
  • Who requested it?

❗Importance… How Much Do They Care?

  • How much do they care?
  • Did they mark this style as important?
  • These are directly related, part of the same step

❗Important Styles Always Win

  • We could split these
  • With importance out in front
  • Important styles will always win
  • Over normal styles
  • But if we stop there, we’re missing the point
Darth Vader
choking a rebel soldier
as storm troopers watch
  • This isn’t a magic trump card
  • For stomping around and killing our enemies
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • This is about collaboration

This proposal tries to soften the tension between the author and the reader.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • Softening the tension
  • Between author and reader
  • So we take turns
  • By default…

The user/browser specifies initial preferences

— Håkon Lie, Cascading HTML style sheets – a proposal

  • The user and browser
  • Specify initial preferences
  • Tend to be global
  • Apply to every website we visit

First… 🖥 User Agent Styles

aka Browser Defaults
  • User agent (browser) goes first
  • Providing legible defaults…
screenshot
(Firefox DevTools: settings/inspector/show browser styles) [CHSS Proposal]

demo:

  • inspect styles
  • none from document, only from browser
  • remove: * { all: initial; }
  • Without browser styles,
  • Unreadable wall of content…
css…
/* initial values */
display: inline;
background: transparent;
color: CanvasText;
font-style: normal;
flex-basis: auto;
/* etc. */
Initial Values, from specifications
  • Initial values
  • Are defined for each property
  • The same on all elements
  • Always display:inline, even on divs…
css…
html { display: block; }
body { display: block; }
p { display: block; }
div { display: block; }
article, aside, footer, header, hgroup,
main, nav, search, section { display: block }
address { display: block; }
blockquote { display: block; }
/* etc etc */
  • Browsers add display:block
  • everywhere we expect it
css…
body { margin: 8px; }
a:link {
  color: blue;
  text-decoration: underline; }
h1, h2, h3, h4 /* etc */ {
  font-weight: bold;
  font-size: something big I dunno; }
  • They also add things like
  • 8px margin on the body
  • Link colors and underlines
  • Heading styles, large bold text
  • Space around paragraphs and lists, etc

User Agent Styles

Collected by Jens Oliver Meiert
  • These are the user agent styles
  • And they apply to every site on the web
  • With only minor differences between browsers

Second… 👥 User Styles

Establish desired preferences

  • After browser defaults
  • Users apply their preferences

[CSS] provides author and reader with the same notation

— Håkon Lie, Cascading HTML style sheets – a proposal

  • Originally using CSS syntax as well
Safari settings panel, advanced tab, with a red scribble highlighting a style sheet option, with none selected by default.
Safari: settings / advanced / style sheet…
  • Safari still supports this option
  • In the settings panel
  • Upload a stylesheet
Language and appearance preferences in Firefox include light/dark mode, colors, fonts, and zoom level
Firefox appearance settings
  • Most other browsers have switched
  • To providing limited preferences through a graphic interface

User Styles

  • Safari/WebKit:
    Settings / Advanced / Style sheet…
  • Firefox/Gecko:
    about:preferences
  • Chrome/Blink:
    chrome://settings/appearance
  • The details are different
  • But the results are the same
  • Users get to have preferences
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • And remember,
  • When we talk about ‘users’ or ‘readers’
  • on the web…

Remember… We Are All Users

all of us read other people’s web sites

  • That’s all of us
  • We’re talking about all of us
  • We all use the web

Remember, We’re Allowed
To Have Preferences

I changed mine, and recommend it!
  • We’re all allowed to have preferences
  • I set a few, and recommend trying it
  • Worried as dev “but I’ll see something different”
  • That’s the point!
  • Remember to check with different settings

Finally… 🎨 Author Styles

  • Finally, ‘document’ or ‘author’ styles
  • (also us)

🗺 Cascade Origins

  1. 🖥 User Agent Defaults (applied first)
  2. 👥 User Preferences (override defaults)
  3. 🎨 Author Styles (so powerful)
  • We come last, and get highest priority
  • We override the user preferences
  • Which override the browser defaults
girl reaching into a white bucket, with paint all over her hands and the floor around her photo: Tanaphong Toochinda
  • So we can kinda just do whatever
  • Smear our brands all over everything
Darth Vader
choking a rebel soldier
as storm troopers watch
  • But we tend to stomp around
  • choking people with our special powers
  • So that’s not great

This proposal tries to soften the tension between the author and the reader.

— Håkon Lie, Cascading HTML style sheets – a proposal

  • That’s the tension
  • Håkon wanted to soften
  • Between authors and readers,
  • And he was clear that

If conflicts arise the user should have the last word

— Håkon Lie, Cascading HTML style sheets – a proposal

  • If conflicts arise
  • The user should have the last word

Why we have…Importance

  • That’s why we have importance
Kylo Ren and Rey
standing in front of an entire star war
with spaceships and lasers
and AT-AT walkers
  • A way for the other origins
  • To take back control when it matters,
  • and bring balance to the cascade…
  • When anyone adds !important to a declaration…
  1. 🖥 User Agent Defaults
  2. 👥 User Preferences
  3. 🎨 Author Styles
  4. ❗🎨 Author Important
  5. ❗👥 User Important
  6. ❗🖥 User Agent Important
  • It creates a new origin
  • One of three important origins
  • All higher priority than the normal origins
  • But with their order reversed…
Spock, and Spock with a goatee
!important mirror universe
  • It’s a mirror universe
  • We all have evil twins with goatees
  1. ❗🎨 Author Important (goes first)
  2. ❗👥 User Important (override authors)
  3. ❗🖥 User Agent Important (most power)
Flipped ❗Important Origins
  • In the important origins
  • We go first (lowest priority)
  • Users override us
  • Browsers have final say
  1. 🖥 User Agent Defaults
  2. 👥 User Preferences
  3. 🎨 Author Styles
  4. ❗🎨 Author Important
  5. ❗👥 User Important
  6. ❗🖥 User Agent Important
  • Important origins do always win,
  • But the real purpose is to keep us contained,
  • stuck there in the middle
  • Our normal and important styles next to each other
  • Where we can’t cause too much harm

User Agent Styles

Collected by Jens Oliver Meiert
  • Browsers do use importance
  • (demo: find in page)
UA Important Styles [present, debug]

demo:

  • Specificity is contained
  • Importance is reversed
In the font preferences dialogue, a default-checked option: Allow pages to choose their own fonts, instead of your selections above
Firefox: un-check for !important behavior
  • Importance works in Safari user styles
  • Firefox provides a checkbox
  • Chrome provides a ‘minimum font size’

The purpose of…Importance

  • Importance doesn’t change specificity
  • It changes the origin of a style
  • And it flips the priority of origins.
  • The purpose…

Authors 👎🏼 Specificity Wars

With our own colleagues and libraries

  • Is not for fighting amongst ourselves
  • To override styles that came before us

Browsers/Users 👍🏼 Protect Styles

From higher origins breaking important things

  • The purpose is for users and browsers
  • To protect from future origins
  • Styles that might get added by the document author
Darth Vader
choking a rebel soldier
as storm troopers watch
  • We’re the baddies here
  • We think we’re the boss of the web,
  • but we’re not

Often Isolated

  1. 🎨 Author Styles
  2. ❗🎨 Author Important
  3. ❗…
  4. ❗…
  • And the fact that our origins
  • (Normal and important)
  • Are isolated together
  • Means we don’t always notice
  • What’s happening around us
Mechanical astrolabe with Earth at the center, and concentric rings for other planets/stars
  • We start to think
  • We’re the center of the universe
Clockwork orrery, with a scribbled arrow pointing to the earth tilt gears labeled 'specificity'
  • On our own
  • Dealing with specificity
Clockwork orrery, with planets circling the sun, and the earth off to one side
  • When we’re really just one
  • ‘Pale Blue Dot’
  • In the solar system of the cascade

2 Bonus Origins… For Intermediate Styles

in transitions and animations

  • Technically two additional origins
  • For ‘intermediate’ styles,
  • Generated by animations & transitions

hotPink » teal

  • If we define the two endpoints
  • (say HotPink to Teal)
  • The browser has to go through other colors…

hotPink
rgb(93 138 220) ?!
teal

  • (Depending on the color space we use)
  • Maybe rgb(93 138 220)
css…
button {
  background: plum;
  transition: background 1s;
}
button:hover { background: pink; }
  • Because both endpoints of a transition
  • Have their own origins and importance…
  1. 🖥 User Agent Defaults
  2. 👥 User Preferences
  3. 🎨 Author Styles
  4. ❗🎨 Author Important
  5. ❗👥 User Important
  6. ❗🖥 User Agent Important
  7. ➡️ Transitions
  • Transitioning values have to override everything
  • We’ve all had our say by that point
css…
:target { animation: bg-change 3s ease-in both; }
@keyframes bg-change {
  from { background: pink; }
  to { background: cyan; }
}
  • Animations are different
  • Only the animation property cascades
  • Keyframes live outside the cascade, disconnected
No !important keyframes [present, debug]
  • Importance isn’t allowed in keyframes
  • will cause the declaration to be ignored
  1. 🖥 User Agent Defaults
  2. 👥 User Preferences
  3. 🎨 Author Styles
  4. 🏇🏽 Animations
  5. ❗🎨 Author Important
  6. ❗👥 User Important
  7. ❗🖥 User Agent Important
  8. ➡️ Transitions
  • So we still need a way to override the results of an animation
  • Animated styles slot in between normal and important styles
The Cascade (as a funnel) [present, debug]
  • Important styles always win
  • Importance also splits us into a different path
  • Changes how every following step works
  • For example…
  • Light DOM styles override shadow DOM styles
  • Unless we add !important, and then it’s reversed

🌗 (Shadow) Context

styling web components

  • This is called Context in the cascade
  • It’s like ‘origin’
  • But for web components

Shadow Styles Are Custom Defaults

similar to user agent origin

  • Web components are designed to act like custom HTML
  • So shadow DOM styles act kinda like browser defaults

Again… Importance is Defensive

and reverses priority

  • Again, importance is defensive
  • Allowing component authors to protect essential styles
The Cascade (as a funnel) [present, debug]
  • Element attached (or inline) styles are the exception
  • There’s no reversal here
  • inline styles win when declarations have the same importance
  • But Cascade Layers reverse
  • for the same reason origins do

Cascade Layers

Cascading & Inheritance Level 5
  • Layers were proposed at the end of 2019, and already…
Support data from CanIUse.com on the css-cascade-layers feature
There’s also a polyfill [Can I Use]
  • Well supported across browsers
  • For almost 3 years
css…
@layer settings {}
@layer tools {}
@layer generic {}
@layer elements {}
@layer objects {}
@layer components {}
@layer overrides {}
  • They give us a way to organize our code
  • And help us manage the cascade

Layers of Specificity

  • Layers of specificity
  • The declaration in the highest layer wins
  • Before we bother to compare specificity
  • Within the winning layer
  • We’ll look at that more when we talk about organizing conventions

Like Origins, ❗️important Layers Reverse

  • But like origins and context
  • Important layers are reversed
  1. Resets (weakest)
  2. Themes
  3. Components (strongest)
  • So if we have three layers
  • Each one overriding the previous

!important

  • And then we add important styles
  • Inside each layer
  1. Resets
  2. Themes
  3. Components
  4. ❗important Components
  5. ❗important Themes
  6. ❗important Resets
  • We now have six layer
  • With important layers reversed
Kylo Ren and Rey
standing in front of an entire star war
with spaceships and lasers
and AT-AT walkers
  • Again, the goal is balance

Protect Styles From Future Layers

Prioritize -> Layers
Protect -> Importance

  • If we just want to override
  • Or manage priorities
  • That’s what layers are for
  • Importance only when essential
css…
@layer reset {
  [hidden] { display: none !important; }
}
  • Reasonable thing to put in a reset
  • Reasonable for reset to have low priority
  • But we don’t want future layers to override this one declaration
The Cascade (as a funnel) [present, debug]
  • There’s more in here to talk about
  • And we’ll come back throughout the workshops
  • Get into some of the weeds

CSS allows Web Design Systems

html…
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
<p style="color: mediumVioletRed;"></p>
  • Not just one-offs that we copy-and-paste
Published book with badly super-imposed hand-pointer cursor and scribbled word click!
  • Or static documents that we export once
A pixelated broken-image icon, showing a photo torn at one corner
  • And then pass back and forth
  • Like a fax machine

CSS ensures Responsive Web Design

Over the shoulder, a person wearing headphones, using a braille display attached to a laptop
  • Across different browsers and devices
  • Different interfaces
  • The needs or preferences of different users

That means Our Needs & Preferences

  • Our needs
  • And our preferences
  • All of us

Web for all. Web on everything.

— W3C Mission Statement

  • Because the web is for everyone
The second browser, a text-only terminal with numbered links for keyboard control
Line Mode Browser, developed by Nicola Pellow
  • And is designed to work everywhere

The Cascade Makes That Possible

  • And the cascade is fundamental to that goal
  • What makes it possible
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • Allowing us to style collaboratively
  • With browsers, users,
  • (and hopefully aliens)

The cascade Is Expressive

  • By taking into account
  • the purpose and priority of each style
  • For the browser to use
The Cascade (as a funnel) [present, debug]
  1. Who requested the style? (origin)
  2. How much do they care? (importance)
  3. Does it come from the shadow DOM? (context)
  4. Is it an inline style? (element attached)
  5. What layer is it in? (cascade layers)
  6. How specific is the selector? (specificity!)
  7. How close is the scope root? (proximity, new)
  8. Which value was declared last? (order, single)

Graphic design of unknown content with unknown collaborators, on an infinite and unknowable canvas, across operating systems, interfaces, languages, and writing modes

— me

  • The goal here is unlike any other medium.
  • We’re doing [quote]
  • It’s absurd, but the cascade helps make it happen
  • So long as we follow the most important rule…
avatar

A Jedi uses the [Cascade] for knowledge and defense, never for attack.

— Yoda (basically)

« resources
Bring this workshop to your company.
Slide Controls

View:

Navigate slides using the arrow-keys.