back to module

Smashing Workshops

Hints & Suggestions

Arrows navigate, cmd/ctrl-k for settings

Welcome!

  • A few things before we dive in:
  • Can I get a show of emoji,
  • or quick comments in the chat…

Where are you?

And what time of day?

What kind of work?

  • Enterprise
  • Non-profit
  • Startup
  • Government
  • Education
  • Agency
  • etc…

Writing or Reviewing CSS?

(reviewing humans or chatbots?)

How long have you
been making websites?

So Much Material

  • Ok, I have so many more questions
  • But mostly I want to hear your questions,
  • And we have time for that at the end of each day
  • But there’s a lot to get through first.
  • Some of it will go quickly, but we can always come back
  • Don’t have to memorize everything!

Takeaway… A CSS Mindset

  • Understand the mental model, what’s possible
  • And I want to leave you with resources
  • You can come back to on your own time
  • Mostly I want to teach you how CSS works
  • Not as a theoretical exercise
  • It’s the only way to write maintainable CSS!

While we’re together Let’s Discuss

  • I’m going to dive in
  • Feel free to interrupt me
  • I can’t see you, so you’ll have to say something
  • While we’re here, let’s discuss

Any questions before we start?

CHSS

Cascading HTML Stylesheets -- a proposal
Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • Håkon Lie, 1994
  • email, still archived online
Historical style sheet proposals
Historical style sheet proposals
  • not the only proposal for styles on the web
  • 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
1990 [WorldWideWeb Browser/Editor]
  • Sir Tim 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
1992 [Nicola Pellow, Line Mode Browser]
  • Nicola Pellow
  • Line Mode browser
  • text-only
  • no install
  • any device with an internet connection
avatar

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

— Tim Berners-Lee, HTML Design Constraints
  • from the start
  • goal of the web is universal access
  • not building one more closed platform
  • but a common language across platforms
avatar

Web for all. Web on everything.

— W3C, Design Principles
  • Mission statement of W3C
A zillion different mobile devices of all sizes
A lineup of 'smart' watches with tiny displays
Over the shoulder, a person wearing headphones, using a braille display attached to a laptop
  • read the screen to you
Various home 'smart' speakers
  • no screen at all
A light pen pointing at an old monitor keyboard mouse touch screen braille keyboard mic VR hand-held motion-sensing controllers joysticks and game pads
  • These devices aren’t read-only
  • also have different controls
  • different ways to interact with content
avatar

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

— Tim Berners-Lee, HTML Design Constraints
  • If we really want this to work
  • Everywhere for everyone
World Wide Web Project
World Wide Web Project
  • leads to some interesting constraints
  • documented on the original website
  • (still online)
avatar

…This implies no device-specific markup…

— Tim Berners-Lee, HTML Design Constraints
Resilient HTML: present, debug
  • browsers ignore code they don’t understand

[DEMO]

  • individual attributes
  • entire HTML tags
World Wide Web Project
World Wide Web Project
  • 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
emulator is currently broken [WorldWideWeb30.com]
  • modern website, on the first browser
  • (this emulator is sadly broken)
  • No css
  • No images
  • all the text is there

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

— WWW Project Constraints
  • But that creates a big problem for design specifically
  • To be a common language everywhere…

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

— WWW Project Constraints
Sir Tim at a computer showing a badly photoshopped image of the previous slide
  • Sir Tim wrote that
  • in 1990 or something

Web Design Will Never Happen

  • Alright you have the rest of the day off
  • Any questions?
Viola WWW browser demonstrating early stylesheets
  • The problem isn’t styles
  • Early browsers all had built-in stylesheets,
The second browser, a text-only terminal with numbered links for keyboard control
Nicola Pellow, Line Mode Browser
  • Even the text-only browser
  • uppercase headings, space between paragraphs, etc
  • But these styles come from the browser
  • And apply the same to every page on the web
  • All websites look the same
  • And we have no control as web page authors
InDesign book-cover layout
  • This is not the way print works
  • If we’re designing a book, we don’t get defaults from our printer
  • We control everything…
  • page size (static, forever)
  • down to the inks used, and the paper to print on
Published book
Published book with badly super-imposed hand-pointer cursor and scribbled word click!
  • We can click all we want
Published book
  • It just sits there
  • 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
  • our control is a limitation of the medium

Web Styles Must Be Contextual

a radical shift!
  • the web is different
  • even static sites aren’t static
  • what we ship is not always what our audience sees
  • styles must adapt to situations…
  • the web is responsive to context

@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
  • And often unpredictable content
  • Changing all the time
  • All of these variables, because…
Big 3d text in space says we're not alone.
  • We’re not alone here
  • We’re part of an ecosystem
  • Our decisions impact other people
  • And on the web, we don’t get final say
3d we're not alone overlaid with browser logos
  • We’re collaborating with browsers
  • (instructed to ignore us)
3d we're not alone overlaid with browser logos and a guy with a tool belt holding 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?
ET and the kids flying their bicycles across the sunset
  • They’re probably just trying to get home.
avatar

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

— Miriam Suzanne
  • How are we supposed to do…
  • It’s absurd

Web Design Seems Impossible

  • Under those constraints,
  • design is clearly impossible…

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

— Roy Smith, www-talk “Re: Adobe’s PDF”
  • But no one was happy with that outcome
  • When every site looks the same
  • That’s boring for both authors and users
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
  • Just like print design!
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
Workshop page on oddbird.net displayed as black and white text on the WWW browser emulator
emulator is currently broken [WorldWideWeb30.com]
  • The browser can’t protect structured content inside an image
  • If it doesn’t load, it’s lost
avatar

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

— Håkon Lie, 2014 interview
  • So images were a real risk
  • Suddenly we have control
  • But at what expense?
Historical style sheet proposals
Historical style sheet proposals
  • And so we get a rush of proposals
  • around 1993 and 1994
  • trying to save the web from images!
Closeup of the Style history page with one phrase in focus, HTML To The Max
  • It’s time to take HTML to the max!
code
(HEAD,BODY fontSize=normal
           BGColor=white
           FGColor=black
  (H1 fontSize=largest
      BGColor=red
      FGColor=white)
  (H2 fontSize=large)
  (A FGColor=red)
  (CMD,KBD,SCREEN,LISTING,EXAMPLE fontFamily=fixed)
  (BOLD,EMPH,STRONG fontWeight=bold)
)
Pei-Yuan Wei, October 1993 (Viola.org)
  • Pei Wei’s Viola browser
  • Was the first to allow custom style sheets for a page
  • About a year before CSS was proposed
  • Parts of this should look familiar
  • selectors, nesting, property-value pairs, even inheritance
Imagine CSS without Inheritance
  • They all have inheritance…
  • Design would be terrible without inheritance
  • Check out the video later if you’re curious

“an easily parsable format”

@DEFAULT fo(fa=ti,sp=pr,si=14,we=me,sl=ro,fo=in,bo=in,li=no,nu=1,fn='')
ju(st=le,hy=0,ke=0) co(nu=1,wi=80) br(lo=af,ob=it)
li(lo=in,ma=no,li=un,nu=1,be=no,af=no,hi=0)

@UL in(le=5)
@LI ma(pr=ro,be=4) in(le=10,ri=10)
Robert Raisch, June 1993
  • Robert Raisch proposed this
  • ‘easily parsable format’
  • a few months before Viola came out
  • I assume he means parsable by machines?
  • You can see the default selector there, kinda like :root
  • We’re setting fonts in the fo() function
  • Family=times, spacing is proportional, size 14,

[Times] is not meant as a font name, per se. Rather it is a suggestion of a particular style of character representation.

— Robert Raisch, “Request for comments: STYLESHEETS”
  • But Robert is clear that these styles are only suggestions!
  • Even the times font-family
  • doesn’t mean we get the ‘times’ font specifically,
  • it just means we want something like times,
  • a serif font!
  • And he repeats this phrasing…

Styles are suggestions or hints about behavior, not rules…

— Robert Raisch, “Request for comments: STYLESHEETS”
  • Over and over,
  • We’re not writing rules,
  • but suggestions or hints about behavior.

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

— Robert Raisch, “Request for comments: STYLESHEETS”
  • Sometimes all-caps
  • hints and suggestions which might not be used.
  • And the other proposals pick this up…

Specified attributes are taken as “hints” that will degrade in a controlled way depending on the level of support… in the operating environment.

— Jon Bosak, Proposal for a language optimized for WWW delivery
  • Jon Bosak’s
  • Hints that will degrade in a controlled way
  • Or, with CHSS…
avatar

…Allow the author to attach style hints.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • We can allow the author to attach style hints
avatar

Provide hints that the browser may or may not use.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • Hints that the browser may or may not use
avatar

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

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • Authors should have stylistic influence,
  • without resorting to page description languages
  • like postscript, the language for making PDFs
  • without giving us full control
  • Our styles should be resilient…
Resilient CSS: present, debug
  • Like HTML is resilient
  • browsers ignore css that they don’t understand
  • We don’t get a blank page with an error message,
  • We get the content with default styles.
  • Always protect the content!

Content should be viewable and accessible by default.

— W3C, Platform Design Principles
  • This becomes another design principle of the w3c
  • content should be viewable and accessible by default
  • Which is why…
CSS is Rad: present, debug
  • The default overflow is visible
  • if we get so cocky
  • that we try to shove large text in a small box
  • The browser will try to bail us out
  • Not because it’s the best-looking solution
  • but because the web is unpredictable
  • and browsers prioritize content over style
  • That’s a good thing!
  • What’s the alternative?
InDesign is [+]
  • InDesign doesn’t even worry about accidental overflow
  • The whole word just disappears!
  • But that’s fine, because we can fix it
  • before we hit print,
  • and it will stay fixed forever
Published book
  • Unchanging
  • Unaware of context
  • Unable to adapt
We're Not Alone, with browser logos, a guy in construction clothes carrying a laptop, and ET
  • By giving up some design control
  • We allow the web to carry our designs
  • Farther than we could ever go alone
  • Because we’re not alone,
avatar

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

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • So CSS wasn’t the first stylesheet proposal
  • It didn’t invent selectors, or properties, or even inheritance
  • But it put the focus on collaboration
avatar

While the author (or publisher) often wants to give the documents a distinct look and feel…

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • Authors want to show their creativity and branding,
  • with a distinct look and feel,
  • make their document visually interesting.
avatar

…the user will set preferences to make all documents appear more similar.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • But users will have preferences,
  • styles that they like better (or even require)
  • like larger text or dark mode,
  • and sites should respect those preferences!
  • making websites a bit more similar for that user.
  • We’re trying to balance creative design with user agency
Algorithms are breaking how we think
Technology Connections, Algorithms are breaking how we think
  • Despite what we’re told by massive platforms
  • User agency is important!
avatar

The proposed scheme is balanced in the sense that it provides author and reader with the same notation for specifying style.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • We do that by allowing everyone to contribute styles
  • Written in the same language
css
/* a 'declaration' */
property: value;
color: blue;
  • Each of us providing
  • our style hints as declarations,
  • a property and a value
css
/* a selector, with attached declarations… */
/* a 'style rule' (or 'rule set') */
p {
  background: white;
  color: mediumVioletRed;
}
  • We can group those together,
  • and add selectors
  • forming rule-sets…
html
<!-- link a style sheet -->
<link rel="stylesheet" href="styles.css">
css
/* import another style sheet */
@import url('more-styles.css');
  • Which can be attached to an HTML document,
  • Giving us…
avatar

An ordered list (cascade) of style sheets.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • An ordered list (or ‘cascade’) of stylesheets
  • all applied to the same web site,
  • But not coordinated…
Kylo Ren and Rey
standing in front of an entire star war
with spaceships and lasers
and AT-AT walkers

The cascade exists to ensure there’s balance in the ecosystem –

avatar

… allow the author to attach style hints.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)

We can allow authors to attach styles, by treating those styles as hints.

Resilient HTML: present, debug

Like HTML, CSS fails silently, protecting the content, and ignoring unrecognized styles.

avatar

Web for all. Web on everything.

— W3C, Design Principles

That’s how we ensure a web that works on everything.

avatar

If conflicts arise the user should have the last word…

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)

And if conflicts arise between the author and user, then the user gets the last word.

avatar

Web for all. Web on everything.

— W3C, Design Principles

So the web also works for everyone.

CSS is A Declarative Language

  • But we’re not writing style rules
  • We’re providing hints and suggestions
  • In a declarative syntax

width: 500px;

  • Some declarations seem simple,
  • the width of a box

text-wrap: pretty;

“Pretty” is in the eye of the beholder by Geoff Graham
  • While some are more abstract,
  • wrapping text so it looks ‘pretty’
  • (whatever that means)
  • The details are left up to the browser!

width: 500px;

Zoom, zoom, and zoom by Miriam
  • But even ‘simple’ declarations contain subtext
  • What do we mean by a pixel?
  • Should this box get smaller on a screen with higher resolution?
  • How should it respond to zooming in and out?
Diagram of an element box, with content, padding, border, and margin -- width and height labels are applied to the content only
The content-box model
  • Are we setting the width of the content box?
  • (so padding and border are added to our width)
Diagram of an element box, with content, padding, border, and margin -- width and height labels are applied to everything except the margin
The border-box model
  • Or the width of the entire box,
  • so padding and border are subtracted to get the content size?
Physical Dimensions: permalink
  • Maybe it’s not the width we care about at all,
Logical Dimensions: permalink
  • that’s just the direction text flows.
  • Are we trying to set the length of a line of text?
flow-inline-vert: permalink

Which might change depending on our writing mode.

inline-size: 500px;

We can express that by using logical properties.

width: min-content;
width: max-content;
width: fit-content;

Or maybe the pixels represent something else we can express more clearly, like the intrinsic size of our content

inline-size: 60ch;

  • The width of characters in the current font?

width: 100%;
width: 90vw;
width: 80cqi;

  • Should it be based on context
  • a parent element, viewport, or container

flex: 1

  • Or flexible in relation to sibling elements
  • And remaining space

inline-size: min(45em, 100%);

  • Or some combination
  • Like the minimum, of two values
A pink box labeled
context (defines available space),
and blue text overflowing the box
in the style of the awesome meme says
this content (takes up space)
  • Everything in CSS based on
  • constant back-and-forth
  • context pushing in,
  • (defining available space)
  • content pushing out
  • (taking up space)

16px != 1em

These are all different hints that we can provide to the browser – not just about what we want, but why we want it.

Sometimes 1em is equal to 16px but not always, because they mean different things. 1em is relative to the current font size, and (I don’t want to shock you, but) 1px is relative to the length of someone’s arm and your assumed distance from the screen.

Specs can get weird sometimes.

inline-size: min(34ch, 100%);

In CSS, the most useful declaration is the one that communicates our intent the most clearly.

Sometimes that requires a combination of units,

width: auto;

  • Or an abstract behavior like auto-sizing,
A zillion different devices of all sizes

So that the browser has as much information and flexibility as we can provide when adapting our rules to a range of different situations.

text-wrap: pretty;

  • We don’t have all the information, but the browser does
  • So the most useful tools in CSS
  • express this kind of abstract behavior
  • let the browser work out details

Expressive Like Poetry

  • The tools we have are expressive, like poetry
  • Not describing the exact layout pixel-by-pixel
  • (like we would for print)
  • but communicating high-level ideas
  • through algorithms and subtext
  • Not just the result we want
  • But the intent behind each choice

Subtext… 16px != 1em

CSS Values & Units
  • Units are great at this
  • (it’s why CSS has so many of them)
  • On the surface 1em is sometimes 16px
  • But they carry different implications
  • And adapt differently in context

In CSS… flex != grid

  • Similar with layout methods
  • We can sometimes get the same result
  • using either flexbox or grid
  • But they move differently at the edges
The first world wide website in the WWW Hypermedia Browser/Editor, on the neXt desktop -- an exercise in global availability
Design For Change
  • And our job, the entire reason we’re here
  • Is not to make things look good on one device,
  • Or in a single browser

Design For Change

  • But to design for change

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

— John Allsopp, A Dao of Web Design
  • By letting go of control
  • Over individual pixels,
  • But instead…
avatar

Provide hints that the browser may or may not use.

— Håkon Lie, Cascading HTML style sheets – a proposal (Oct 1994)
  • Express ourselves as clearly as possible
  • Through hints and suggestions
  • Which the browser can adapt…
  • to handle new and unexpected situations
CSS is Rad: present, debug

To me, this meme perfectly captures what is actually awesome about CSS – and how we can go wrong by taking too much control without considering the consequences.

Reasons to overflow – context : present, debug

Maybe the size of that box is based on the size of the browser, and the overflow is caused by a small screen.

Reasons to overflow – user font-size : present, debug

Maybe the user increased their font size.

avatar

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

— Miriam Suzanne

This is the problem that CSS is actually trying to solve – and it’s a complex problem.

We’re not just doing graphic design, we’re designing for the unknown…

Big 3d text in space says we're not alone.
  • And we’re not doing it alone
The second browser, a text-only terminal with numbered links for keyboard control
1992 [Nicola Pellow, Line Mode Browser]
  • browser is allowed to ignore us
avatar

If a trade-off needs to be made, always put user needs above all.

— W3C, Platform Design Principles
  • the user always gets final say
Kylo Ren and Rey
standing in front of an entire star war
with spaceships and lasers
and AT-AT walkers
  • not us vs them
  • we’re on both sides of this equation.
  • spend more time using the web than building it
  • We are both web users and also web authors.
Rey holding her yellow lightsaber up
in front of her, concentrating
  • claim our power as users
  • to customize our own web experiences
  • insist on a web where that’s possible
  • if we want that web, we have to build it for everyone else
  • give our readers control
avatar

Web for all. Web on everything.

— W3C, Design Principles

Our job is to ensure that this really is a web that can work everywhere, and a web that works for everyone.

Always put user needs above all.

— W3C

Next module… Order of Operations

« back to resources
SlideDeck Controls

View

Keyboard shortcuts
cmd/ctrl-k:
Toggle this control dialog
cmd/ctrl-shift-enter:
presentation (from first slide)
cmd/ctrl-enter:
presentation (from active slide)
alt-enter:
in speaker view (following active slide)

Color Settings