Adaptive design and responsive design are two ways of creating interfaces that display correctly on different devices. They have a common goal of ensuring ease of use on any screen, but the methods of implementation are different.
Adaptive layout is used when we need to display a specific layout for each device type. Layouts can be similar to each other or they can be completely different.
How it works: When you visit a website, your device and screen size are first determined. You will then be given the appropriate HTML and CSS. The number of layouts depends on the design and requirements of the project. Often three layouts are created: for desktops, tablets and mobile devices, but there are also more complex options.
For designers, drawing several types of pages is a common thing, regardless of whether the site will be adaptive or responsive.
For front-end developers, adaptive layout is a more difficult task. Each layout needs to be typeset separately, with its own markup and styles. Such code is more difficult to maintain: if we change the appearance of an element, we need to change it in all layouts.
Advantages of adaptive design:
Disadvantages of adaptive design:
CSS-frameworks
CSS frameworks are sets of ready-made solutions that help us avoid problems when displaying the site on different devices and in different browsers. Each framework offers its own approach to implementing responsive design.
Here are some of them:
Bootstrap. The most popular CSS framework in web development. It allows us to easily and quickly adapt the site to any device using a 12-column grid.
Bootstrap benefits:
Materialize. This is a platform created on the principles of material design («cards», smooth transitions, no sharp corners, strict layouts and animations).
Features of Materialize CSS:
Bulma. A modern framework that uses Flexbox instead of the traditional column grid. This allows us to create flexible and adaptive layouts.
Bulma features:
Pure. A set of small adaptive modules that we can use in any project.
Features of Pure CSS:
CSS3 Media Queries
This is a CSS tool that allows us to control the styles of elements according to the characteristics of the user’s device.
In simple terms, we can set conditions by which the browser will decide which styles to apply to the page and which not to.
Creating a media query begins with the keyword @media, followed by one or more conditions. As a condition, you can specify the type of device or the requirements for a specific characteristic. The requirement for a specific characteristic is written in parentheses.
After compiling @media, the styles specified in it will be applied only if the final result of the calculation of the conditions is true.
An example of a media query with one condition:
@media screen {
/* styles will be applied when the condition is true */
}
Example of a media query with a combination of several conditions:
@media (min-width: 992px) and (max-width: 1199.98px) { ... }
In @media you can specify certain types of devices:
For example, this @media is for screens only:
@media screen { ... }
And here for screens and printers:
@media screen, print { ... }
The media feature width, min-width, and max-width allows you to set a condition for the equality of the viewport width to a certain value. For example, apply CSS only for a viewport with a width of 320px.
@media (width: 320px) { ... }
To set conditions for the height of the viewport, you can use height, min-height, and max-height.
For example, @media for viewport height greater than 720px:
@media (min-height: 720px) { ... }
Orientation allows you to set certain styles based on the mode (landscape or portrait) in which the site is displayed.
For example, depending on the orientation of the viewport, we will display different pictures:
@media (orientation: landscape) {
.cover { background: url(bg-l.png) no-repeat; }
}
@media (orientation: portrait) {
.cover { background: url(bg-p.png) no-repeat; }
}
Aspect-ratio, min-aspect-ratio, and max-aspect-ratio allow you to set styles depending on the aspect ratio of the viewport.
/* Minimum aspect ratio */
@media (min-aspect-ratio: 9/16) {
.header {
background-color: #0dcaf0;
}
}
Resolution, min-resolution, and max-resolution can be used when you need to set styles depending on the pixel density of the device.
For example, set a different font size for devices with a pixel density per inch greater than 150:
/* Default */
p {
font-size: 16px;
}
When connecting a style sheet, you can use the media attribute to set media queries and thereby define the conditions when they should be used.
<link rel="stylesheet" media="screen and (max-width: 991.98px)" href="/assets/mobile.css">
<link rel="stylesheet" media="screen and (min-width: 992px)" href="/assets/desktop.css">
In addition to <link>, they can also be used in @import:
@import url(mobile.css) screen and (max-width: 991.98px);
@import url(desktop.css) screen and (min-width: 992px);
Responsive layout is based on the idea that the user receives the same HTML and CSS, regardless of the device. The appearance of the page is adapted using CSS styles and media queries.
Simply put, if you open a responsive site in a browser and start to resize the window, you will see how the page elements are rebuilt based on the width and height of the viewport.
Advantages of responsive design:
Disadvantages of responsive design:
One of the tools for achieving responsive design is viewport units: vw, vh, rem, em, and combinations thereof. Below we will show some examples of their use.
Viewport units in CSS are percentages of the screen size available in the web browser to display content. Unlike pixels, which remain the same regardless of screen size, viewport units offer a flexible approach to sizing elements, fonts, and padding.
vw and vh:
When using pixels to create a header element, its height will be constant on different screens:
header {
width: 100%;
height: 100px;
}
Let’s make our header more responsive by giving it a dynamic height of 10vh. Depending on the screen size, the header will always take up 10% of the screen height:
<style>
header {
width: 100%;
height: 10vh;
text-align: center;
background-color: #9089fc;
}
Let’s look at some examples of using vw and vh to create responsive designs:
Creating a full-screen section with a background image that adjusts to the height and width of the viewport:
main {
width: 100vw;
height: 100vh;
background: url("background-image.png") no-repeat center center;
background-size: cover;
}
Position elements relative to the viewport size to create a more responsive layout:
.container {
padding: 5vh 5vw;
}
.section {
margin-bottom: 2vh;
}
Adjust font sizes using viewport units so that text remains proportional across devices. This can be done like this:
body {
font-size: 2vw;
}
However, using only vw for font sizes can result in text that is too small or too large on very small or very large screens. Often use the clamp () function to set the minimum and maximum font size:
body {
font-size: clamp(16px, 2vw, 24px);
}
The clamp () function is used to dynamically adjust the font size of the body element, with three parameters:
Both em and rem are relative units that are calculated from the font size.
rem (from root ephemeral unit).
em (from ephemeral unit) or root element
In modern browsers, the root font size is 16px, so 1rem = 16px.
Let the font size of the root element <html> be 16 pixels:
html {
font-size: 16px;
}
Then the font size of the element with the class block will be equal to 16px × 1.5 = 24px:
.block {
font-size: 1.5rem;
}
The value in em units is always calculated from the font size of the element: it is either inherited from the parent or set on the element itself. Continuing our example, if the block element is simply given a width of 5em, then the inherited font size will be used for the calculation: 16px × 1,5 × 5 = 120px.
.block__elem {
width: 5em;
}
And if the element itself is set to a font size of 2em, then another multiplier will be added to the inherited size: 16px × 1,5 × 5 × 2 = 240px.
.block__elem {
width: 5em;
font-size: 2em;
}
Adaptive design is better suited for projects where we know in advance which devices the site will be used on, and where there are clear layout requirements. It allows us to fine-tune the interface for each device.
Responsive design is a more versatile and flexible approach. It is ideal for projects where we need support for a large number of devices and screen sizes.
Usually responsive design is a more practical and flexible solution. But before starting a project, it is better to check with the client if he needs a design for a specific device.