Establishing points at which a process can be interrupted and resumed is known as defining breakpoints.
Responsive breakpoints are certain points at which adjustments are made to the layout and design of the website based on the size of the screen. These decisions are not made arbitrarily; they are based on information.
- Search for common screen resolutions for mobile phones, tablets, laptops and desktops to find popular device sizes. These offer you advice on possible points of intervention;
- Examine how your content and design fragment or become unwieldy at different widths;
- Study how users interact with your website on various devices to improve the user experience.
An explanation of structuresSeveral CSS structures use defined breakpoints designed for standard screen dimensions. This provides ease of use, but it is essential to know how to customise them if necessary.
Creating CSS multimedia queriesCSS multimedia queries allow varied styles to be applied according to specific conditions, with screen size being the main factor. This is the fundamental structure:
@media query intended for screens at least 768 pixels wide.
/* Specific styles for screens with a minimum width of 768px */
Let's analyse it step by step:@media: Indicating a media query.
(min-width: 768px): The situation, in this case being the minimum width of the viewport. You can use max-width and integrate features such as orientation (landscape or portrait).
The CSS styles contained in square brackets will only be applied if the specified condition is met.
Images that adjust their size and resolution based on the device and screen size on which they are being viewed.
Images are often the main reason why websites are slower, particularly on mobile devices with slower Internet connections. Responsive image methods ensure that your graphics look great and load quickly on any device.
The srcset attribute helps optimise images for different screen sizes.
The srcset attribute in your HTML elements is crucial for providing images that are sized appropriately for various devices.
This is how it works:
Please reshape the image.
src=‘photo-large.jpg’ should remain unchanged in the text.
srcset=‘photo-small.jpg’ 480w, photo-medium.jpg 800w, photo-large.jpg 1200w’ has different image sizes available for selection.
sizes=‘(max-width: 768px) 480px, (max-width: 1200px) 800px, 1200px’ remains unchanged.
alt=‘Text describing an image’ />
Let's break this down:
- Src: Provides the default path of the image, ensuring backwards compatibility;
- srcset: Provides a collection of image files and their associated widths (w descriptor) for specific use cases;
- Dimensions: This part offers the browser guidance on how to place the image within the design on various screen sizes, helping to select the ideal display option;
- Browser magic: By examining the user's device, screen dimensions and image clues, the browser automatically chooses the best image from the set of sources.
Load content only when necessarySlow loading is a technique that delays the loading of images that are not immediately visible in the user's viewing window (i.e. ‘below the fold’). See why this is important:
- Faster initial page load: Critical website content can be loaded more quickly as image loading is delayed until the user scrolls;
- Reduced data usage: This is especially beneficial for mobile users with limited data plans;
- Improved SEO potential: Faster initial page loads can contribute to a positive user experience signal, potentially helping search rankings.
How slow loading works- Placeholders: Instead of loading images directly, low-resolution placeholders can be used;
- JavaScript detection: JavaScript listens for user scrolling;
- Image trigger: When an image placeholder enters (or approaches) the preview window, its src attribute is filled with the path of the actual image, triggering loading.
Considerations for slow loading- Balancing the user experience: slow loading is weighted. Images that are immediately necessary for comprehension must be completed in time;
- SEO impact: Make sure search engines can still index your images. Modern slow loading techniques are generally optimised for SEO.
Options for lazy loading content- Used in up-to-date browsers, Native Lazy Loading can be implemented by including the loading=‘lazy’ attribute in your tags;
- JavaScript libraries: Provide greater control to implement unique functionalities;
- WordPress plugins/CDNs: Many plugins, along with CDNs, can automatically handle lazy loading on your WordPress website.
Adaptable menuThe navigation on your website acts as a guide for visitors. When using smaller screens, the menu needs to adapt to give users the best possible experience.
Factors to take into account for touch-screen devices- Target size: Make sure that the size of hyperlinks or navigation buttons is easy to touch with a finger. Try to achieve at least 48px by 48px;
- Make sure there is enough distance between the hyperlinks to avoid unintentional clicks on surrounding elements;
- Visual feedback: Give clear visual cues (such as changing colour) after tapping on a navigation item.
Menus with hamburger iconsThe familiar hamburger menu is now a common feature for navigation on mobile devices. This is how it works in DRW:
- Space conservation: Condenses the navigation menu into one button, which opens up valuable screen space;
- Familiarity: The three-line symbol is generally accepted as representing a hidden menu.
Off-screen navigation barsOff-screen menus are menus that slide out from the side of the screen, usually activated by a button. This is where they truly excel:
- Extra space: They allow for larger navigation structures or sub-menus compared to the hamburger menu drop-down style;
- Personalisation: Greater versatility in terms of design, placement (swiping left/right) and animated impacts.
Crucial reminder: Whatever style of menu you choose, make sure there's a simple way to close it once it's been opened.
Adaptable typographyTypography is crucial to the readability and overall aesthetic of your website. As screen dimensions evolve, it's crucial that text size, line spacing and other typographic elements adapt smoothly.
Units for font specification.
Now let's dissect the measurements you'll use to specify text dimensions in a flexible setting:
- Pixels (px): Although commonly used, pixels are static units - they're not suitable for responsiveness as they don't adjust to different screen sizes;
- Em: Measurement relative to the current font size. If the font size of a main element is set to 16px, 1em is equal to 16px. The calculation is influenced by nesting;
- Rem is a relative unit that is always determined by the size of the root font, normally set in the element, creating greater predictability;
- View units (vw, vh) are equivalent to 1% of the view width for 1vw and 1% of the view height for 1vh. These have the potential to produce impactful results, but must be used with caution.
Adjustable line spacingLine height refers to the distance between lines of text. Maintaining the correct size in relation to the font size is essential for readability.
- Line height without units: A frequently used method is to specify a value without units (e.g. line height: 1.6). This calculates a factor of the existing font size;
- Maintain flow: Modify the line spacing on various screen sizes to ensure a pleasant reading experience on all devices.
Optimisation and experimentsThoroughly testing and optimising your responsive site is the last crucial step in taking it from good to excellent.
Test compatibility in different browsersDifferences in browser rendering can cause problems for even the most carefully designed responsive layouts. Here's why it's essential:
- Commonly used web browsers: Test the latest versions of Chrome, Firefox, Edge, Safari and the main mobile browsers;
- Recognise incompatibilities: Identify layout problems, font rendering problems or inconsistencies in JavaScript behaviour;
- Assistance aids: Tools and services for browser developers, such as BrowserStack, simplify the cross-browser testing process.
Testing on real devices- Although browser emulators have their uses, there is no substitute for testing on real physical devices;
- Simulators can't accurately mimic the tactile feedback, screen differences and potential performance variations of real mobile devices and tablets;
- If you can't afford to buy several devices yourself, consider borrowing them from friends and family or investing in a few key models to test.
Tools for testing responsivenessListed below are some commonly used tools for examining the responsiveness of your website:
- Google's Mobile-Friendly Test is the fundamental assessment. It quickly checks whether Google considers your website compatible with mobile devices and identifies any significant problems;
- Responsinator is a basic tool that allows you to see how your website looks on different popular devices, simulating their screens. It's perfect for a brief visual inspection;
- Browser development tools, such as those found in Chrome and Firefox, include reactive design modes and device emulators for thorough testing;
- Other factors to take into account when testing.
Make sure you observe how the scroll works on touch devices and check that interactive components such as forms and buttons work smoothly.
Test the performance of your image optimisation and lazy loading techniques on slower connections by checking the loading of images.
Performance metrics: Use tools such as Lighthouse or WebPageTest to obtain full performance evaluations and identify possible obstacles.
Accessibility considerationsTrue responsiveness goes beyond the physical dimensions of the screen. Consider the accessibility needs of disabled users in your design.
- Semantic HTML implies the use of appropriate title tags, including descriptive alternative text, and other elements;
- Adequate colour contrast is important to ensure legibility for visually impaired users;
- Test the website's navigability using only a keyboard;
- Testing with a screen reader can help you see your website from a new point of view.
By using these testing tactics and taking accessibility into account, you'll be well on your way to providing an exceptional responsive experience for all users!