Responsive Web Design


Responsive Web Design

Responsive web design is about creating web pages that look good on all devices!

A responsive web design will automatically adjust for different screen sizes and viewports.

 

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

To create a responsive website, add the following <meta> tag to all your web pages:

Example

<meta name="viewport" content="width=device-width, initial-scale=1.0">







Live Demo & Try it yourself!

This will set the viewport of your page, which will give the browser instructions on how to control the page's dimensions and scaling.

Here is an example of a web page without the viewport meta tag, and the same web page with the viewport meta tag:

Responsive Images


Responsive Images

Responsive images are images that scale nicely to fit any browser size.

Using the width Property

If the CSS width property is set to 100%, the image will be responsive and scale up and down:

 

Responsive Image

When the CSS width property is set in a percentage value, the image will scale up and down when resizing the browser window. Resize the browser window to see the effect.

 

Example

<img src="/images/cat.jpg" style="width:100%;">

 

Notice that in the example above, the image can be scaled up to be larger than its original size. A better solution, in many cases, will be to use the max-width property instead.







Live Demo & Try it yourself!

Using the max-width Property


Using the max-width Property

Using the max-width Property

If the max-width property is set to 100%, the image will scale down if it has to, but never scale up to be larger than its original size:

 

Responsive Image

"max-width:100%" prevents the image from getting bigger than its original size. However, if you make the browser window smaller, the image will still scale down.

Resize the browser window to see the effect.

Example

<img src="/images/cat.jpg" style="max-width:100%;height:auto;">







Live Demo & Try it yourself!

Show Different Images Depending on Browser Width


Show Different Images Depending on Browser Width

The HTML <picture> element allows you to define different images for different browser window sizes.

Resize the browser window to see how the image below changes depending on the width:

 

Show Different Images Depending on Browser Width

Resize the browser width and the image will change at 600px and 1500px.

Flowers

 







Live Demo & Try it yourself!

Responsive Text Size


Responsive Text Size

The text size can be set with a "vw" unit, which means the "viewport width".

That way the text size will follow the size of the browser window:

 

GSSS KHOKHAR

Resize the browser window to see how the text size scales.







Live Demo & Try it yourself!

Responsive Web Design - Frameworks


Responsive Web Design - Frameworks

All popular CSS Frameworks offer responsive design.

They are free, and easy to use.

W3.CSS

W3.CSS is a modern CSS framework with support for desktop, tablet, and mobile design by default.

W3.CSS is smaller and faster than similar CSS frameworks.

W3.CSS is designed to be independent of jQuery or any other JavaScript library.







Live Demo & Try it yourself!

Bootstrap


Bootstrap

Another popular CSS framework is Bootstrap:







Live Demo & Try it yourself!