If you are building for the modern web, then you have to design your application responsive. Before you ship your application, you need to make sure that the application runs perfectly across browsers.
The need to do a cross-browser compatibility test stems from the number of available devices out there. The smartphone boom has made the web accessible to everyone, but at the same time, it has made it harder for developers to ensure that they provide an optimal experience to the end-user.
Not only you need to keep in mind smartphones’ small screen space, but also the pixel density of the devices.
On the technological side, HTML at the core provides a great framework to build upon. If you are using other technologies, then it becomes even more complex to ensure responsive design for all different media screen sizes. You are free to design your own page based on your requirement and then ensure that it is optimal to be consumed from any device.
Before we jump into the process of testing responsive web design cross-browser compatibility, we need to get a better understanding of Responsive Web Design(RWD) and cross-browser testing.
Table of contents:
Cross-browser testing refers to the practice of making your web apps work across different web browsers. As a developer, you need to think about your end-users and how they will feel when using a particular browser. And, you need to do this for all your users, and not just a particular section of users.
Cross-browser testing becomes challenging because you need to take care of different aspects of browsers, including old versions, support of different libraries, device capabilities, and also about special users, including people with disabilities.
Ethan Marcotte first coined the responsive Web Design term in the year 2019. According to him, RWD determines the process of developing and design the web page so that it is responsive to different platforms, screen sizes, and orientations.
In short, the end result is to ensure that the web page looks good on different devices and screen sizes.
However, the challenges creep from the fact that RWD has no single approach or technology.
This means that you are free to take whatever approach you can take to make your web app responsive.
The key aspects that you need to make sure about are the following three points:
With all of these in mind, let’s get started with optimizing our responsive web design.
The best approach is to think responsive first when designing and developing your web page. This way you will ensure that you use the best practice, and hence do not need to do the heavy lifting when the project is at closing stages.
At the start of your project, you should always use the viewport meta tag to your advantage. To do so, you need to use the following line of code in the HTML <head> section.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
The above line tells the browser that the webpage is responsive.
The width=device-width provides the necessary browser level scaling to ensure that the content fits the screen. This is only applicable for rendering on desktop sites.
The new HTML5 standard has provided many elements that can help you make your site responsive. One such element is <picture>. You can use it cleverly to showcase as per the device resolution, aspect ratio, or orientation.
Let’s check the code below.
<picture> <!-- image when width >> height --> <source srcset="spaceship-landscape.jpg" media="(min-aspect-ratio:1/1)" alt="spaceship-landscape" /> <!-- default image --> <img src="spaceship-potrait.jpg" alt="spaceship-potrait" /> </picture>
Here we used the <source> option.
Media Queries are also very useful when it comes to creating a responsive first site. With it you target viewport specific range.
h1 { font-size: 1rem; } @media (min-width: 720px) and (max-width: 800px) { h1 { font-size: 1.5rem; } }
The first h1 selector is applied for all viewport. However, when there is a particular viewport of 720px to 800px, then the h1 selector font-size is modified.
There are obviously other implementation strategies that you can use including CSS Grid and Flexbox, CSS Columns, or even CSS Viewport Units. You also benefit from the fact that most browsers offer great responsive design support.
There are obviously different ways you can test the responsive design of a site. One of the most common ways is to do in-browser testing. With it, you can simply resize the browser to see how the site adapts to new viewport limitations. Moreover, you can also take advantage of the web developer menu built within the browser. This approach is always limited as it doesn’t give you answers about the site’s capability to work on older devices, high-density displays, processing speed, or how it responds to touch.
In case you need to test out different mobile OS, you need to shift your focus on mobile emulators. There are plenty of mobile emulators that you can use, both for Android and iOS. We suggest checking out Android Studio and Genymotion for Android testing. For iOS, we suggest you check out Electric Mobile Studio and Apple Xcode.
Next, we have online testing services where you run your site through their test servers to learn about its cross-browser compatibility, responsive design, and more! We suggest checking out Sauce Labs, and CrossBrowser Testing.
As a web developer, if you can get access to a real device, then nothing beats it. You can always connect the device to the PC using a USB cable and then choose to debug solutions such as Android Studio or the browser to test out the application easily.
In conclusion, we can easily say that there is no single standardized way to approach Responsive Web Design or Cross-browser compatibility. So, you need to pick your own approach style and then use it to optimize the sites in the best possible way for the end-users.