HTML Responsive Web Design


Responsive web design involves crafting web pages that appear appealing and functional on various devices.

Responsive web design automatically adapts to various screen sizes and viewports.


Responsive Web Design

What is Responsive Web Design?

Responsive Web Design is about using HTML and CSS to automatically resize, hide, shrink, or enlarge, a website, to make it look good on all devices (desktops, tablets, and phones):


Setting The Viewport

For a website that works well on different devices, include this <meta> tag on all your web pages:

By doing this, you're basically telling the browser how to manage the size and scaling of your page.

Here's a comparison between a webpage without the viewport meta tag and the same webpage with the viewport meta tag:

Without the viewport meta tag:
With the viewport meta tag:

Responsive Images

Responsive images are pictures that adjust well to fit any size of web browser.

Using the width Property

When the CSS width is set as 100%, the image becomes responsive and adjusts its size to fit different screens, getting larger or smaller as needed:



In the given example, remember that the image can be made bigger than its actual size. However, a more effective approach in many situations is to utilize the max-width property instead.

Using the max-width Property

When you set the max-width property to 100% for an image, it can become smaller if needed, but it won't become bigger than its original size.




Show Different Images Depending on Browser Width

With the HTML <picture> element, you can set up various images for various sizes of web browser windows.

Change the size of your web browser window to observe how the image below adjusts based on its width.

Flowers


Responsive Text Size

You can adjust the text size using the "vw" unit, which stands for "viewport width."

By doing this, the text will automatically adjust its size based on the size of the browser window:

Hello World

Adjust the size of your browser window to observe how the text size changes accordingly.


Viewport refers to the size of the browser window. 1vw is equal to 1% of this window's width. For instance, if the viewport is 50cm wide, then 1vw would correspond to 0.5cm.


Media Queries

Besides adjusting text and images to fit properly, media queries are often employed in creating responsive web pages.

Using media queries, you can create distinct styles for various browser sizes.

Try adjusting the size of your browser window to observe that the three div elements below will be arranged side by side on bigger screens and will be stacked on top of each other on smaller screens.

Main Content


Right Content




Responsive Web Page - Full Example

A well-designed webpage should appear attractive both on big computer screens and small mobile phones.



Responsive Web Design - Frameworks

Every well-known CSS Framework provides responsive design capabilities.

They're free and user-friendly..


Bootstrap

Another popular CSS framework is Bootstrap: