
Watch the Recording
If you missed the meetup or would like a recap, watch the video below or read the transcript. If you have questions about what was covered in this meetup please tweet us @EqualizeDigital on Twitter or join our Facebook group for WordPress Accessibility.
Read the Transcript
Links Mentioned
- Nick’s Contact Information
- Accessibility, when you need JavaScript to help with tabindex
- NicktheGeek Github /css-color-modes
- Podcast Episode: Your Website Makes Me Want To Puke, Pentire Margarita
- Funkify: Disability Simulator
- Web Accessibility Perspectives Videos
- How to Counter Arguments from Developers and Designers: Anne-Mieke Bovelett
- Discover issues with rendering performance
- Bionic Reading Converter
About the Meetup
Learn more about WordPress Accessibility Meetup.
Article continued below.
Stay on top of web accessibility news and best practices.
Join our email list to get notified of changes to website accessibility laws, WordPress accessibility resources, and accessibility webinar invitations in your inbox.
Summarized Session Information
In this session, Nick Croft presents an in-depth look into the evolution and future of responsive design, focusing on color modes. He covers the history of responsive design, starting from fixed layouts to the latest advancements in CSS and HTML that facilitate highly adaptive layouts. Nick delves into media query basics and the power of combining media queries to create specific CSS rules.
He explores the future of responsive design, highlighting the importance of layout customization, display quality, color modes, interaction methods, and user preferences. New media queries introduced in Media Query Level 5, such as light level, inverted colors, prefers color scheme, and reduced motion, offer advanced customization options for developers to create more responsive and accessible web experiences.
Nick also explains the benefits of using CSS variables, particularly in WordPress development, and provides practical examples of implementing light mode, dark mode, increased contrast, and reduced motion. He concludes with optimization techniques, including custom media queries, conditional imports, and media query stylesheets, to enhance performance and manage large stylesheets effectively.
Session Outline
- History of responsive design
- Media queries basics
- The future of responsive design
- New media queries
- Using CSS variables
- Examples
- Optimizing
History of responsive design
Fixed layout
In the early days of web design, fixed layout was the norm. Websites were created with fixed widths, often designed for specific monitor resolutions such as 640 pixels, 800 pixels, or even 1200 pixels for high-end setups. However, this approach had significant limitations, as content would overflow or get crushed on different devices, particularly on the smaller screens of the time. This resulted in poor user experience, prompting developers to seek better solutions.
Liquid layout
To address the limitations of fixed layouts, developers introduced liquid layouts, which used percent-based widths to create more flexible designs. These layouts adjusted to fit various screen sizes but were still not fully optimized for mobile devices.
As mobile phones primarily served as communication tools with limited browsing capabilities, liquid layouts were an improvement but not a comprehensive solution for the emerging mobile web.
Resolution dependent
The next step in the evolution of responsive design was resolution-dependent layouts. This approach utilized JavaScript to load different style sheets based on the screen resolution. While this allowed for greater flexibility and adaptability, it also required significant maintenance, as each resolution needed its own complete set of style sheets, making the process cumbersome for developers.
Mobile URLs
With the advent of smartphones, companies began creating separate mobile URLs to serve mobile users more effectively. These URLs detected mobile requests at the server level and redirected users to a mobile-specific site.
Although this approach provided a better mobile experience, it often resulted in limited functionality compared to desktop versions and involved managing separate themes and content for mobile and desktop sites.
Responsive design
The introduction of responsive design marked a significant milestone. Using media queries and various CSS techniques, developers could create layouts that adapted to different devices seamlessly. This approach led to the concept of mobile-first design, prioritizing mobile user experience as mobile web traffic surpassed desktop traffic.
Responsive design became essential as users increasingly accessed websites on their phones, requiring designs that could dynamically adjust to various screen sizes and orientations.
Next-gen responsive
The latest advancements in responsive design include new CSS and HTML features that facilitate the creation of highly adaptive layouts.
Grid and flex layouts and other CSS3 innovations enable developers to build layouts that automatically adjust and stack based on device size. Features like fluid typography ensure consistent text presentation across different screen sizes, enhancing the user experience.
These advancements represent the natural progression from liquid layouts and early responsive designs, allowing for more sophisticated and adaptable web designs.
Media query basics
This section explores the fundamental aspects of media queries, a critical component in responsive web design.
@media media-type and (media-feature-rule) {
/* CSS rules go here */
}
The primary media types are “All,” “Print,” and “Screen,” each targeting different mediums of content display.
Media features allow developers to tailor their CSS rules to various device characteristics. Key media features include:
- Size:
width
,min-width
,max-width
,height
,min-height
,max-height
. - Layout:
orientation
andaspect-ratio
. - Device features:
hover
andscripting
. - Preferences:
reduced motion
andcontrast
.
Combining media queries
Combining media queries offers powerful ways to create highly specific CSS rules. Three examples illustrate this concept:
Basic combination: @media screen and (min-width: 600px) and (orientation: landscape)
applies styles if the screen width is at least 600 pixels and in landscape mode.
@media screen and (min-width: 600px) and (orientation: landscape) {
body {
color: blue;
}
}
Joined queries: @media screen and (min-width: 600px), screen and (orientation: landscape)
combines two conditions using a comma, applying the styles if either condition is met.
@media screen and (min-width: 600px) screen and (orientation: landscape) {
body {
color: blue;
}
}
Negation: @media not all and (orientation: landscape)
excludes styles in landscape mode, applying them to all other orientations and media types.
@media not all and and (orientation: landscape) {
body {
color: blue;
}
}
These combinations allow developers to fine-tune the user experience based on multiple criteria, ensuring that websites are adaptable to various devices and user preferences. Complex media queries can be created by joining multiple conditions, enabling precise targeting of user needs and device capabilities.
The future of responsive design
Layout
The future of responsive design offers increasingly sophisticated options for layout customization. Developers can now address orientation (such as landscape or portrait) and aspect ratios (e.g., 16:9). This allows for more precise adjustments to layout based on the specific characteristics of the device being used. These advancements help optimize the website layout for various devices and screen sizes, providing a better user experience.
Display quality
Improvements in display quality detection enable developers to target high-resolution and low-resolution screens differently. Developers can create pixel-perfect designs that maintain visual integrity across various devices by understanding how a device measures pixels. This capability is crucial for fine-tuning the appearance of web elements, ensuring that designs look sharp and consistent, regardless of the display quality.
Color mode
With the ability to detect device color modes, developers can ensure website colors remain consistent and on-brand across different devices. This includes accommodating devices that use different color palettes or mixing methods. By addressing these variations, developers can maintain brand integrity and visual consistency, which is essential for a cohesive user experience.
Interaction
Responsive design is evolving to understand better and respond to user interaction methods. This includes detecting whether a device supports hover (e.g., a mouse) or touch input. By tailoring the user experience based on the interaction method, developers can provide more intuitive and accessible interfaces. For example, hover-based interactions might be replaced with touch-friendly device alternatives.
Preference
Addressing user preferences is considered the next generation of responsive design. As operating systems on both mobile and desktop devices share more information about user preferences, developers can create experiences tailored to individual needs. For instance, if a user has dark mode enabled on their device, websites can automatically adjust to dark mode without requiring manual toggles. Similarly, preferences like reduced motion can be detected, allowing websites to disable potentially nauseating animations and replace them with more subtle effects like opacity changes.
The ultimate goal is to enhance accessibility and user experience. It is paramount that websites do not cause discomfort, such as motion sickness. By leveraging user preference data, developers can create more inclusive and enjoyable web experiences, recognizing the diverse needs of their audience and adapting accordingly.
New media queries
Media Query Level 5
Media Query Level 5 represents the latest advancements in responsive web design, building upon the foundations of the previous four levels. Initially, media queries enabled basic responsive functionality, with subsequent levels refining and simplifying their usage.
Media Query Level Five introduces many new features that significantly enhance the ability to tailor web experiences to user environments and preferences.
These new media queries empower developers to create more responsive, accessible, and user-friendly web experiences, accommodating a wide range of user needs and preferences.
light-level
One of the notable features of Media Query Level 5 is the ability to detect the light level in the user’s environment. This capability allows websites to adjust their contrast based on whether the user is in a low-light or high-light setting.
For instance, a user browsing outdoors in bright sunlight could benefit from increased contrast for better visibility. In contrast, a user in a dimly lit room might prefer reduced brightness to avoid eye strain. This adaptation mimics the responsiveness of modern apps, offering a more seamless and comfortable browsing experience.
inverted-colors
Another feature is detecting inverted colors, which is particularly useful for users with specific vision impairments. Inverted colors can make content more readable for those with low vision, and now, websites can detect and respond to this setting in iOS and macOS operating systems. This ensures the content is accessible to a broader range of users by accommodating their visual preferences.
prefers-color-scheme
The prefers color scheme media query allows websites to align with the user’s preferred color scheme, whether in light or dark mode. By detecting this preference, websites can automatically switch to the appropriate color scheme, enhancing the user experience. This is particularly beneficial as more users adopt dark mode to reduce eye strain and save battery life on their devices.
prefers-contrast
Websites can now detect whether users prefer higher or lower contrast. While higher contrast is generally considered more accessible, some users might find it overwhelming. Detecting a preference for reduced contrast allows websites to adjust their design accordingly, avoiding the starkness of white-on-black text, which can be difficult for some users to read.
prefers-reduced-motion
The prefers reduced motion media query caters to users who experience discomfort or motion sickness from excessive animations and movement on websites. By detecting this preference, websites can disable or minimize motion effects, providing a more comfortable browsing experience.
prefers-reduced-transparency
Similar to reduced motion, prefers reduced transparency addresses the potential overstimulation caused by semi-transparent elements. For instance, a modal window with a transparent background can be challenging for some users to process. By detecting a preference for reduced transparency, websites can render these elements fully opaque, reducing visual complexity and enhancing readability.
prefers-reduced-data
The prefers reduced data media query is particularly useful for users with limited data plans or those who prefer a streamlined browsing experience. This feature allows websites to simplify content, turning off sidebars, related posts, and other non-essential elements. By focusing on the core content, websites can provide a more efficient and less overwhelming experience, catering to users’ data preferences and improving overall usability.
Using CSS variables
CSS variables offer a powerful tool for modern web design, allowing developers to streamline their code and enhance flexibility. This section explores the benefits and applications of CSS variables, particularly in the context of WordPress development.
New theme JSON-Based themes
The introduction of theme.json in WordPress themes marks a significant advancement. This JSON file enables themes to automatically output CSS variables, simplifying the process of theme customization.
New themes, especially those based on Full Site Editing (FSE), come with built-in support for CSS variables. This allows users to update colors and other design elements directly from the block editor. This seamless integration between the theme.json file and CSS variables empowers users to customize extensively without delving into complex CSS coding.
Ease of CSS updates
One of the standout features of CSS variables is their ability to change styles without the struggle of selector specificity. In traditional CSS, developers often encounter issues with highly specific selectors and the use of the !important
keyword, leading to conflicts and cumbersome overrides.
CSS variables alleviate this problem by allowing global changes that cascade through the stylesheet, minimizing the need for repetitive and conflicting rules.
Efficiency in rule changes
CSS variables significantly reduce the amount of code needed to update multiple styles simultaneously. For instance, if a variable is used to define a common property like padding, margin, or color, changing the variable’s value updates all instances where it is applied. This efficiency is particularly beneficial when implementing responsive design through media queries. Instead of modifying each individual rule, developers can adjust the variable, and the changes will propagate throughout the entire stylesheet.
By leveraging CSS variables, developers can create more maintainable, scalable, and flexible stylesheets, enhancing both the development process and the end-user experience. Integrating CSS variables into WordPress themes through theme.json further simplifies theme customization, making it accessible to a broader range of users.
Examples
Light mode
This section begins with an example of a website displayed in light mode. The default experience for users includes a teal page header with white text, a full-width WordPress cover block featuring a wood-fired pizza oven with white text overlay, and a section with a white background and a teal call-out box.
The site includes black text for body content and a card grid gallery showcasing images of pizza and a dough ball.
This setup represents the standard appearance without any user-specific preferences applied.
Dark mode
Switching to dark mode, the website’s appearance changes to accommodate users who prefer darker interfaces. The header background color shifts from teal to dark blue, and the overall background changes from white to dark charcoal gray. Text colors invert accordingly, with black text becoming white to maintain readability.
This transformation is achieved using a few CSS and media queries lines, demonstrating how CSS variables and media queries can effectively manage such changes.
Increased contrast
The website adjusts its colors to offer better contrast for users who prefer higher contrast. In this example, the header background changes to a higher contrast blue instead of teal, enhancing readability.
This adjustment is managed through media queries that detect the user’s contrast preferences and apply the necessary CSS rules to ensure a visually accessible experience.
Inverted colors
Inverted colors present a unique challenge. The example shows a white header with black text, an intentional adjustment to improve visibility for low-vision users who use inverted colors. By carefully selecting background and text colors, the website ensures that content remains readable even when colors are inverted.
For instance, a pure black background with white text can be too harsh, so using a dark charcoal background with white text offers a better experience. This careful consideration helps avoid issues such as migraines or seizures triggered by high contrast.
Reduced motion
To accommodate users who prefer reduced motion, the example includes a video demonstrating removing hover effects that cause elements to expand. Initially, hovering over cards causes them to grow slightly, but with the “prefers reduced motion” setting enabled, this effect is disabled. Instead, the transform property is set to none, ensuring a stable and comfortable experience for users sensitive to motion.
Optimizing
text
Custom media queries
Custom media queries are a powerful tool for optimizing CSS. By defining custom media queries, developers can reuse them throughout the stylesheet, reducing redundancy and file size. An example of a custom media query is:
@custom-media--medium-devices (min-width:50rem);
@custom-media--large-landscape (min-width:70rem) and (orientation: landscape);
These custom queries can then be applied as follows:
@media(--medium-devices){
.container {
max-width:40rem;
}
}
However, custom media queries are not yet widely supported, so this method is something to look forward to for future optimization.
Conditional imports
Conditional imports allow CSS to be loaded only when specific conditions are met, optimizing load times and performance. For example:
@import url(reduced-motion.css) screen and (prefers-reduced-motion);
This rule will load the reduce-motion.css
file only if the user has the prefers-reduced-motion
setting enabled. This approach helps keep the primary CSS file lightweight while accommodating various user preferences. While implementing conditional imports may require additional build processes or plugins, the performance benefits can be significant.
Media query stylesheets
Using separate stylesheets for different media queries can further optimize CSS. In HTML, this can be done with:
<link
rel="stylesheet"
media="screen and (prefers-reduced-motion)" href="reduced-motion.css">
For WordPress, the wp_enqueue_style
function can be used to conditionally load stylesheets:
wp_enqueue_style(
'reduced-motion',
get_stylesheet_directory_uri() . 'reduced-motion.css',
[ 'main' ],
'1.0.0',
'screen and (prefers-reduced-motion)' );
This function ensures that the stylesheet is loaded only when the specified media query condition is met, such as prefers-reduced-motion
. This method helps manage large stylesheets by loading only the necessary CSS for specific user preferences, thus enhancing performance and user experience.