Responsive Web Design with HTML5 and CSS: Build future-proof responsive websites using the latest HTML5. 5 Ed and CSS techniques. 5 Ed
Key Features
- Understand what responsive web design is, and learn to design effective, accessible, and future-proof front-end applications
- Explore the newest CSS features like view transitions, scroll-driven animations, P3 colors, and CSS functions
- Learn brand-new time-saving additions to the HTML language, including dialogs and modals
Book Description
Responsive Web Design with HTML5 and CSS, Fifth Edition, is the very latest, up-to-date version of one of the bestselling books on HTML5 and CSS. It emphasizes pragmatic application, teaching the approaches needed to build websites and applications, with downloadable examples.
Written in Ben's friendly and easy-to-follow style, this title can be read as a complete guide, or used as a reference for each topic.
If you're a backend dev looking to understand the front of the web stack and its possibilities, or perhaps a frontend dev looking for a comprehensive resource on everything new in HTML and CSS to build the most efficient UIs, this is the book for you. Even if you are deferring your code writing to AI, this book gives you the requisite knowledge to understand the validity and efficiency of AI's output.
Among the many topics, we cover approaches for better accessibility, utilizing variable fonts, explainers on the latest color manipulation techniques and functions, in-depth coverage of bleeding-edge features such as scroll-driven animations, view transitions, CSS anchor positioning, CSS layers, container queries, nesting, and much more.
By the end, you'll not only have a thorough understanding of responsive web design and what's possible with the latest HTML5 and CSS, but also know how to best implement each technique.
What you will learn
- Leverage color functions to mix colors and convert between color spaces
- Use media and container queries to detect touch/mouse and color preference
- Leverage HTML semantics to author accessible markup
- Use SVGs to provide resolution-independent images and learn to efficiently display them
- Create animations as items enter and leave the viewport using just CSS
- Discover CSS custom properties and make use of new CSS functions
- Add validation and interface elements to HTML forms
- Check whether the frontend code produced by AI tools is effective for your goals
Who this book is for
Are you a full-stack or backend developer who needs to improve their front-end skills?
Perhaps you work on the frontend and need a definitive overview of all that modern HTML and CSS has to offer?
Maybe you have done a little website building, but you need a deep understanding of responsive web designs and how to achieve them?
Perhaps you are using AI tools to produce code and want to check the output?
If any of those scenarios sound familiar, this is the book for you!
All you need to take advantage of this book is a working understanding of HTML and CSS. No JavaScript knowledge is needed.
Cover....1
Copyright Page....3
Contributors....5
Table Of Contents....8
Preface....26
Part 1: The Fundamentals of Responsive Web Design....34
Chapter 1: The Essentials of Responsive Web Design....36
The browser and device landscape....37
Defining responsive web design....38
Responsive web design in a nutshell....38
Browser support....38
Text editors....40
Tools for software development....40
Should you be coding with AI?....41
Our first responsive example....42
Our basic HTML file....42
Taming images....47
A brief tangent on widthmax-width for images....49
Enter media queries....50
Breakpoints....50
Amending the example for a larger screen....51
The shortcomings of our example....56
Summary....56
Chapter 2: Writing HTML Markup....58
Getting the start of HTML pages right....60
The doctype....61
The HTML tag and lang attribute....61
Character encoding....61
The forgiving nature of HTML5 markup....62
A sensible approach to HTML markup....62
All hail the mighty element....63
New semantic elements in HTML5....64
The
element....65
The
element....66
The
element....66
The
element....67
The
element....67
The
element....68
The
element....68
h1-h6 elements....68
Headings, sub-headings, and the hgroup element....69
The
element....70
The
element....70
The
element....70
The
and
elements....71
The
and
elements....72
Create an accordion effect with multiple linked details elements....75
The
element....75
HTML text-level semantics....76
The element....76
The element....76
The element....77
The element....77
The element....77
Obsolete HTML features....78
How to insert Unicode characters in HTML and CSS....78
Putting HTML elements to use....79
WCAG accessibility conformance and WAI-ARIA for more accessible web applications....81
Web Content Accessibility Guidelines (WCAG)....81
WAI-ARIA....82
Taking ARIA further....82
Embedding media in HTML5....83
Providing alternate media sources....85
Audio and video tags work almost identically....86
Responsive HTML5 video and iframes....86
How to maintain the aspect ratio....87
The loading attribute....87
The element....88
Summary....91
An exercise....91
Chapter 3: Media and Container Queries....94
The meta viewport tag....97
Why media queries are needed for a responsive web design....99
Basic conditional logic in CSS....99
Media query syntax....100
Media queries in link tags....101
Media query on an import at-rule....101
Media queries in a CSS file....102
Inverting media query logic....102
Combining media queries....102
A number of different media queries....103
Everyday media queries....103
What can media queries test for?....104
Features deprecated in CSS Media Queries Level 5....105
Using media queries to alter a design....105
Advanced media query considerations....108
Do media queries affect which files get downloaded or how the page renders?....108
Should you split media queries into their own files?....109
Consolidate media queries or scatter them where it suits?....109
Nesting media and container queries....111
What about file size?....111
Media Queries Level 5....112
Interaction media features....112
The pointer media feature....113
The hover media feature....113
User preference media features....114
The prefers-color-scheme media feature....114
The prefers-reduced-motion feature....115
Future possibilities....116
Range syntax....116
Container queries....117
Using container queries....118
Why name the container?....123
Container relative lengths....124
Possibilities....125
Container style queries....125
Nesting container style queries....126
Currently only work with CSS custom properties....127
Summary....128
Chapter 4: Fluid Layout and Flexbox....130
Converting a fixed pixel design into a fluid proportional layout....131
Why do we need flexbox?....136
Introducing flexbox....136
The bumpy path to flexbox....137
Getting flexy....137
Perfect vertically centered text....137
Offset items....139
Reverse the order of items....141
How about if we want them laid out vertically instead?....142
Column reverse....143
inline-flex....143
Flexbox alignment properties....144
align-items....146
align-self....147
Possible alignment values....148
justify-content....148
The flex property....151
Simple sticky footer....153
Visually re-ordering items....155
Wrapping with flex....160
What about gap?....163
Wrapping up flexbox....164
Summary....165
Chapter 5: Layout with CSS Grid....166
What CSS Grid is and the problems it solves....167
Basic Grid syntax....167
Grid-specific concepts and terminology....168
Setting up a Grid Layout....169
Explicit and implicit....173
grid-auto-rows and grid-auto-columns....174
grid-auto-flow....176
Placing and sizing Grid Layout items....177
gap....180
repeat....180
fr units....181
Placing items in the grid....181
span....182
dense....183
Named grid lines....184
grid-template-areas....187
auto-fit and auto-fill....189
The minmax() function....191
Shorthand syntax....192
The grid-template shorthand....193
The grid shorthand....193
The grid shorthand value – option one....194
The grid shorthand value – option two....194
The grid shorthand value – option three....195
A challenge....196
Allowing nested elements to take part in the grid....197
The subgrid value....199
Summary....203
Applying what you have learned so far....204
Part 2: Core Skills for Effective Frontend Web Development....206
Chapter 6: CSS Nesting, Layers, Selectors, and More....208
CSS nesting....209
Understanding the & symbol in nesting....211
Writing an ancestor relationship....212
Adjacent sibling and data-attribute example....212
Lists of nested selectors example....213
Nesting conditionals such as media queries....213
Cascade layers....215
Naming cascade layers....217
Where to declare layers....217
Adding rules to layers....218
The priority of rules in and outside of layers....218
Nesting layers inside other layers....219
The importance of !important....219
!important in cascade layers....221
Old browsers....222
Selectors, units, and capabilities....223
Anatomy of a CSS rule....223
Pseudo-elements and pseudo-classes....223
CSS selectors – beyond the normal!....224
CSS attribute selectors....225
CSS substring matching attribute selectors....226
The beginning with substring matching attribute selector....226
The contains an instance of substring matching attribute selector....227
The ends with substring matching attribute selector....227
Chaining attribute selectors....228
CSS structural pseudo-classes....229
The :last-child selector....230
The nth-child selectors....230
Understanding what nth rules do....231
The of selector....235
nth-based selection in responsive web designs....236
Combinator selectors – child, next sibling, and subsequent sibling....238
The child combinator....239
The next sibling....239
The subsequent sibling....240
The negation (:not) selector....240
The empty (:empty) selector....241
Grouping selectors....242
The :is() functional pseudo-class....243
The :where() functional pseudo-class....244
The :has() relational pseudo-class....245
Limiting the application of selectors with scope....247
Targeting elements with scope to get less specificity....248
scope specificity....249
Using scope inside a style tag....250
The practicality of scope....251
Responsive viewport relative lengths....251
Using supports to fork CSS....253
Feature queries....253
Using supports as a proxy for a feature you cant test for....255
Combining conditionals....255
Summary....257
Chapter 7: Web Typography....258
System fonts....259
The font-face CSS rule....259
Using custom fonts with online services....260
Implementing web fonts with font-face....260
Optimizing font loading with font-display....262
font-display....263
Consolidating the appearance of two fonts with font-size-adjust and size-adjust....265
The size-adjust property....267
Better text alignment with text-box....268
text-box-trim possible values....270
text-box-edge possible values....270
Controlling the flow of text with text-wrap....271
Variable fonts....273
font-face changes....273
How to make use of a variable font....276
Registered axis....276
Custom axis....277
Font features....277
Fancy numbers with font-variant-numeric....279
Summary....281
Exercise....281
Chapter 8: CSS Colors....284
RGB color....285
HSL color....286
Alpha channels....288
Alpha with hex....288
Alpha with functional notation....289
Space-separated functional color notation....290
Color concepts and terminology....290
Color space....291
Gamut....291
The current state of CSS color....293
Introductory note....294
Display-P3....294
The media (color-gamut) media query....296
LCH with the lch() function....296
OKLab and OKLch....299
Fallbacks for older browsers....299
The color-mix() function....300
The contrast-color() function....301
The original color-contrast() function....301
The original color-contrast() function was flawed....302
How did this happen?....302
The newer, but more limited contrast-color() function....302
Relative colors with the relative color syntax....303
Values always have to be numbers....303
The light-dark() function....304
Summary....305
Resources....305
Chapter 9: Stunning Aesthetics with CSS....306
Text shadows....307
Multiple text shadows....308
Box shadows....309
Inset shadow....309
Multiple box shadows....310
Understanding spread....310
Background gradients....311
The linear-gradient notation....312
Specifying gradient direction....312
Color stops....313
Radial background gradients....314
Handy extent keywords for responsive sizing....316
Conic gradients....317
Repeating gradients....320
Background gradient patterns....321
Multiple background images....323
Background size....323
Background position....324
Background shorthand....325
High-resolution background images....326
CSS filters....327
Available CSS filters....328
Combining CSS filters....333
A warning on CSS performance....333
CSS clip-path....335
CSS basic shapes....335
clip-path with a circle....336
clip-path with ellipse....337
clip-path with inset....337
clip-path with polygon....338
clip-path with URL (clipping source)....339
The shape() CSS function....340
More resources exploring shape()....342
Animating clip-path....343
mask-image....344
mix-blend-mode....347
Summary....347
Chapter 10: Responsive Images....350
Modern image formats....351
AVIF image format....352
WebP image format....352
Image format comparisons....353
Using the picture element to progressively enhance images....354
The inherent problem of responsive images....356
Simple resolution switching with srcset....357
Advanced switching with srcset and sizes....358
Did you say the browser might pick one image over another?....359
Art direction with the picture element....359
A practical note on providing alternate image formats and sizes....360
Summary....361
Chapter 11: SVG....362
A brief history of SVG....364
An image that is also a readable web document....365
The root SVG element....367
Namespace....368
The title and desc tags....368
The defs tag....368
The g element....368
SVG shapes....369
SVG paths....369
Creating SVGs with popular image-editing packages and services....369
Saving time with SVG icon services....370
Inserting SVGs into your web pages....371
Using an img tag....371
Using an object tag....371
Inserting an SVG as a background image....372
A brief aside on data URIs....372
Generating image sprites....373
Inserting an SVG inline....374
Reusing graphical objects from symbols....374
Inline SVGs allow different colors in different contexts....377
Making dual-tone icons that inherit the color of their parent....377
Recoloring SVGs with CSS custom properties....378
Reusing graphical objects from external sources....380
Recoloring SVG assets with a mask....381
What you can do with each SVG insertion method (inline, object, background-image, and img)....382
Extra SVG capabilities and oddities....383
SMIL animation....383
Styling an SVG with an external style sheet....384
Styling an SVG with internal styles....385
SVG properties and values within CSS....386
Animating an SVG with CSS....386
Animating SVG with JavaScript....388
A simple example of animating an SVG with GreenSock....388
Using SVGs as filters....390
A note on media queries inside SVGs....393
Optimizing SVGs....394
SVG implementation tips....395
Summary....395
Further resources....396
Chapter 12: Transitions, Transformations, and Animations....398
What CSS transitions are and how we can use them....399
The properties of a transition....401
The transition shorthand property....402
Transitioning different properties over different periods of time....403
Understanding timing functions....403
CSS 2D transforms....406
Scale....407
Translate....408
Using translate to center absolutely positioned elements....409
Rotate....411
Skew....412
Matrix....413
The transform-origin property....414
CSS 3D transformations....416
The translate3d property....419
A progressive enhancement example using translate3d....420
Animating with CSS....423
The animation-fill-mode property....426
Using starting-style to transition items entering the DOM....428
But you cant animate them being removed....430
Transition elements to display: none with transition-behavior....430
Animating height with the calc-size() function....432
The animation-composition property....433
Summary....434
Exercises and training....435
Chapter 13: Custom Properties and CSS Functions....436
Working with custom properties....437
Simple theming....438
Setting and getting custom property values with JavaScript....440
Custom properties and specificity....441
Setting a fallback value....442
env() environment variables....443
Custom properties and web components....443
CSS functions....444
calc()....445
min()....447
max()....447
clamp()....448
Putting it all together....449
Summary....451
Chapter 14: Forms....452
HTML5 forms....453
Understanding the component parts of HTML5 forms....454
The placeholder attribute....455
Styling the placeholder text....455
The required attribute....456
The autofocus attribute....457
The autocomplete attribute....458
The list attribute and the associated datalist element....459
The pattern input attribute....461
Styling the input caret with the caret-color CSS property....462
HTML5 input types....463
The email input type....463
The number input type....465
Using min and max to create number ranges....467
Changing the step increments....468
The url input type....468
The tel input type....471
The search input type....473
The color type input....473
Date and time....474
The date input type....474
The month input type....476
The week input type....476
The time input type....477
The range input type....478
Styling HTML5 forms with CSS....479
Indicating required fields....481
Creating a background fill effect....485
New and
styling....486
Default select styling....486
Customizable selects....488
Summary....489
Part 3: Latest Platform Features and Parting Advice....490
Chapter 15: Cutting-Edge CSS Features....492
The Popover API....492
Styling the popover....494
Anchor positioning....497
Creating an anchor relationship....498
Positioning anchored content with position-area....500
Positioning with anchor() functions....502
Sizing the anchored elements with anchor-size()....503
Overflow management with position-try....504
Using position-try....505
position-try flip tactics....506
Custom positions with position-try....507
Limitations and frustrations of anchor positioning....508
Scroll-driven animations....511
The animation-timeline property....513
The animation-range property....513
Driving the animation with scroll()....515
View transitions....517
Same-document view transitions....517
Changing default durations....519
Every element to transition needs a unique view-transition-name value....519
Selecting simlilar transitions with view-select-class....521
Pitfalls with view transitions....522
Cross-document view transitions....524
Summary....526
Chapter 16: Bonus Techniques and Parting Advice....528
Truncating text....529
Single-line truncation....529
Multi-line truncation....530
Creating horizontal scrolling panels....531
Styling scrollbars....534
Scrollbar color accessibility....536
Proprietary -webkit- scrollbar styling....537
CSS Scroll Snap....538
The scroll-snap-type property....538
The scroll-snap-align property....539
The scroll-snap-stop property....539
Smooth scrolling with CSS scroll-behavior....540
Rounded gradient borders with semi-transparent backgrounds....541
Parting advice....544
Getting designs in the browser as soon as possible....544
Testing on real devices....545
Embracing progressive enhancement....545
Defining a browser support matrix....546
Functional parity, not visual parity....546
Choosing the browsers to support....547
Tiering the user experience....547
Avoiding CSS frameworks in production....548
Hiding, showing, and loading content across viewports....548
Validators and linting tools....549
Performance....550
Performance tools....551
The next big things....553
Summary....554
Other Books You May Enjoy....558
Index....562