JavaScript Tutorial

HTML Responsive

Responsive design in HTML is a concept that allows HTML elements to adjust to the size of the device screen, ensuring that they look perfect on any device, including mobile, desktop, or tablet.

The responsive design relies on several factors, including viewport width, text size, responsive images, and other elements, to ensure that elements quickly adjust to the available space in the display view.

To perfect the design with different browsers and devices, many new techniques are involved in responsive designing, such as media queries, which are included in CSS. Media queries allow the browser to adjust the design according to the user's device size.

Setting viewport

Setting viewport is another important part of responsive design. It is used to set the viewport to the user page view, which helps the browser control the dimensions of the webpage along with its scaling. This ensures that elements are automatically adjusted as per different device sizes and display screens.

Responsive images

Another important aspect of responsive design is responsive images. These are images that can be scaled nicely to fit any browser size. By using responsive images, the design can adapt to different screen sizes and device resolutions.

A problem with the above method (width: 100%) is that the image can be scaled up to be larger than its original size. So, it is better to use the max-width property instead.

Set max-width property

Setting the max-width property to 100% will cause the element to expand to the full width of its parent container, which may not necessarily be responsive. But setting the max-width property is a good way to ensure that an element doesn't become too wide on larger screens, while still allowing it to scale down on smaller screens. For example, you could set a max-width of 800px for a container element, so that it doesn't become too wide on larger screens, but can still scale down on smaller screens.

Responsive text

Using the "vw" (viewport width) unit in CSS can help make text responsive by allowing it to adjust its size relative to the size of the viewport. For example, setting the font size to "4vw" means that the text will always be 4% of the viewport width regardless of the device or screen size. This ensures that the text is readable and not too small or too large on different devices.

Viewport specifies the browser window size. 1vw = 1% of viewport width. Means, if the viewport is 100cm wide, 1vw is 1.0cm.

Using media query

Using media queries is crucial in responsive design to ensure that text, images, and other elements are responsive on different devices and browser sizes. There are various frameworks available nowadays to make web pages more responsive, such as:

  1. Responsive Stylesheet: This framework allows users to use different stylesheet frameworks like W3.CSS, which plays a key role in creating responsive designs. It supports mobile-first design by default and is easy to learn and develop.

  2. Bootstrap: This is the most popular framework that is rapidly growing and freely available to users. It is more user-friendly than other frameworks because it's based on web development languages like HTML, CSS, and jQuery, which help to make web pages more responsive.

  3. Latest Responsive CSS: This framework supports various kinds of browsers as well as all types of devices, such as smartphones, tablets, laptops, and more.

Go back to Previous Course