- CSS for JavaScript Developers | An online course that teaches the fundamentals of CSS for React/Vue devs
- Homepage | A11y Coffee
- Radix Primitives
- Learn CSS Â |Â web.dev
Fundamentals
- Selectors
- Pseudo-classes
:hover
:focus
:checked
:first-child
,:last-child
:first-of-type
,:last-of-type
- Pseudo-elements
::placeholder
::before
::after
- Combinators
>
- Pseudo-classes
- Color
- Named
- RGB
- Hex
- HSL
- Units
- px
- em
- rem
- %
- Typography
font-family
- Web fonts
- Formatting
- Bold
font-weight
- 1 to 1000
- default = 400
bold
= 700
- Italic
font-style: italic;
- Underline
- links
text-decoration
underline
none
- Bold
- Semantics
<strong>
<em>
- Screen readers, “copy”
- Alignment
text-align
left
right
center
text-transform
uppercase
capitalize
- Spacing
letter-spacing
line-height
Rendering Logic
- Inheritance
- The Cascade
- ID > class > tag
- The CSS Cascade
- Directions
- Block (vertical)
- Inline (horizontal)
- CSS Writing Modes â—† 24 ways
- Logical properties
margin-block-start
margin-inline-start
- CSS logical properties and values - CSS: Cascading Style Sheets | MDN
- i18n
- Box Model
- Layers
-
- Content
-
- Padding
- shorthand
- vertical, horizontal
- top, right, bottom, left
-
- Border
- shorthand - width, style, color
- width
border-style
solid
,dotted
, …- required
border-color
- Border Radius
- Incomplete List of Mistakes in the Design of CSS [CSS Working Group Wiki]
border-radius should have been corner-radius.
- Circle -
border-radius: 50%;
- Incomplete List of Mistakes in the Design of CSS [CSS Working Group Wiki]
outline
- doesn’t affect layout
-
- Margin
- Negative margin
- Auto margins
-
box-sizing
- Default =
content-box
- New Default:
border-box
- Default =
- Layers
- Flow Layout
-
- Block elements
<div>
,<header>
, …display: block;
-
- Inline elements
span
,<a>
- Replaced elements
<img />
,<video />
,<canvas />
display: inline-block
- Width algorithms
auto
min-content
,max-content
fit-content
min-width
,max-width
<figure>
,<figcaption>
- Height algorithms
height: 100vh;
- Fallback for older browsers
height: 100svh;
-
- Margin Collapse
- Only vertical margins collapse
- Margins only collapse in Flow layout
- Only adjacent elements collapse
- The bigger margin wins
- Nesting doesn’t prevent collapsing
- Margins must be touching in order for them to collapse.
- Margins can collapse in the same direction
- More than two margins can collapse
- Negative margins
- Multiple positive and negative margins
- Margin considered harmful | Max Stoiber (@mxstbr)
Positioned layout
position
- default -
initial
,static
relative
- relative to its natural position
top
,left
,right
,bottom
- doesn’t impact layout like margins
absolute
- float above UI
- stack multiple elements
z-index
- no effect in Flow layout
- default -
auto
=0
- Stacking context - CSS: Cascading Style Sheets | MDN
- incorporeal
- centering trick
inset: 0;
- set all 4 edge properties (
top
,Âleft
,Âright
, andÂbottom
)
- set all 4 edge properties (
- can only be contained by other elements using Positioned layout
fixed
- similar to
absolute
- only contained by the viewport
- immune to scrolling
- Un-fixing Fixed Elements with CSS Transforms – Eric’s Archived Thoughts
- similar to
sticky
- sticks to an edge as you scroll
- not incorporeal
- default -
overflow
- default -
visible
scroll
overflow-y
overflow-x
auto
hidden
scroll
with scrollbars removed
clip
- doesn’t create a scroll container
- Hidden Content
display: none;
- totally invisible and incorporeal
visibility: hidden;
- takes up space
- can be selectively undone by children
visibility: visible;
opacity
- not binary
- can still be focused
- helpful when animating visibility
- Accessibility
- React component for screen reader accessibility
aria-hidden="true"
- Hidden from screen readers
- default -
Modern Component Architecture
- Ecosystem
- Vanilla CSS
- No tooling
- Global and unscoped
- BEM naming convention can help
- Sass / Less
- Sass: Syntactically Awesome Style Sheets
- Getting started | Less.js
- preprocessor
- similar to TypeScript
- Sass compiles to CSS at build-time
- extends CSS with features like nesting, variables, and iteration
- Aphrodite
- GitHub - Khan/aphrodite: Framework-agnostic CSS-in-JS with support for server-side rendering, browser prefixing, and minimum CSS generation
- one of the first popular CSS-in-JS libraries
- Styles are written in JS
- Solves scoping and specificity
- Automatically adds vendor prefixes
- not a very active project
- CSS Modules
- GitHub - css-modules/css-modules: Documentation about css-modules
- allows you to write vanilla CSS, and import it into a JS file
import styles from './App.module.css';
- Offers aÂ
composes
 feature, to extend existing CSS classes - often mixed with PostCSS, a plugin ecosystem for extending CSS in beneficial ways (autoprefixing, transpiling, etc)
- styled-components
- GitHub - styled-components/styled-components: Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress đź’…
- every style is also a React component
- supports SSR
- most popular CSS-in-JS solution
- Obfuscates the underlying markup tags
- Emotion
- Emotion – Introduction
- similar to styled-components
- Not as popular or battle-tested as styled-components
- Tailwind
- Tailwind CSS - Rapidly build modern websites without ever leaving your HTML.
- utility-first CSS framework
- ”Utilities” in this context are short CSS classes that map to specific styles
- Relatively steep learning curve
- Adds a lot of “bulk” to your markup
- twin - With twin, you write Tailwind classes, but it gets transformed under-the-hood to use styled-components.
- Stitches — CSS-in-JS with near-zero runtime
- vanilla-extract — Zero-runtime Stylesheets-in-TypeScript.
- GitHub - callstack/linaria: Zero-runtime CSS in JS library
- Vanilla CSS
- styled-components 101
- Demystifying styled-components
createGlobalStyle
- Dynamic Styles
- Component Libraries
- Breadcrumb Pattern | APG | WAI | W3C
- Core options through props
- Composition with styled()
- Contextual styles
- ARIA: progressbar role - Accessibility | MDN
Flexbox
-
CSS Grid - 2D layouts
-
Flexbox - single dimension
-
display: flex
- parent element will still use Flow layout
-
flex-direction: row; /* row, column */
row-reverse
column-reverse
-
justify-content: flex-start; /* flex-end, space-between… */
-
align-items: stretch; /* flex-end, baseline… */
align-self
-
Growing and Shrinking
flex
flex-grow
flex-shrink
flex-basis
-
flex-wrap
-
gap
-
flex-direction
-
Ordering
flex-direction
order
flex-wrap: wrap-reverse
Responsive and Behavioural CSS
- Mobile
- Media Queries
- desktop-first
@media (max-width: 400px) {
- Mobile-first
@media (min-width: 401px) {
- The Surprising Truth About Pixels and Accessibility: should I use pixels or rems?
- Hovering
@media (hover: hover) and (pointer: fine) {
- Media Queries Level 4
- Preference-based media queries
@media (prefers-color-scheme: dark) {
@media (prefers-reduced-motion: no-preference) {
- Orientation
@media (orientation: portrait) {
@media (orientation: landscape) {
- desktop-first