Top 10 LVH API Solutions for Streamlining Your Development Processes

Jennie Lee
5 min readApr 6, 2024

--

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

Introduction to the vh and vw Units in CSS

CSS offers a variety of units to define dimensions, such as pixels, percentages, and ems. Among these units, the vh (viewport height) and vw (viewport width) units provide a unique way to specify dimensions relative to the viewport. In this article, we will explore the significance of these units, their history, and the challenges associated with their use. We will also discuss the introduction of new CSS units that aim to streamline development processes.

Definition and Purpose of the vh and vw Units

The vh and vw units represent a percentage of the viewport dimensions, which is the area of the browser window where the content is displayed. The 1vh unit corresponds to 1% of the viewport height, while 1vw unit corresponds to 1% of the viewport width. These units offer a flexible approach to design, allowing elements to scale dynamically based on the size of the viewport.

Brief History of the vh Unit and its Original Definition

The vh unit was first introduced in CSS3 with the intended definition of 1% of the height of the initial containing block. This definition aimed to provide consistent sizing relative to the viewport across different devices and browsers. However, mobile browsers introduced a behavior where scrolling would adjust the size of the viewport, resulting in confusion regarding the true representation of the vh unit.

Confusion about the vh Unit’s Representation due to Mobile Browser Behavior

The behavior of mobile browsers, where the viewport is adjusted when scrolling, raised questions about the accuracy of the vh unit’s representation. As a result, using the vh unit for elements that required a consistent size, such as font sizes, became problematic. Developers faced challenges in creating responsive designs that worked consistently across various devices and browsers.

The Responsive Solution

To address the issues associated with using the vh unit for elements that required consistent sizing, a responsive solution was introduced. This solution ensured that the size represented by the vh unit would react to changes in the viewport size, providing a more flexible approach to design.

The responsive solution allowed designers and developers to create layouts that adjusted dynamically based on the viewport dimensions. However, this solution also meant that font sizes defined using the vh unit would change as the viewport size changed. As a result, maintaining a consistent size for text elements proved to be challenging.

The Static Solution

Recognizing the limitations of the responsive solution, browser vendors implemented a static solution for the vh unit. This solution was adopted in Safari, Webkit, and Chrome browsers. In this implementation, the vh unit was defined as a static unit equivalent to the size of the viewport when the browser UI was at its smallest.

By providing a predictable representation of the vh unit, the static solution addressed many of the challenges faced by developers. It allowed for consistent sizing of elements without the need for manual adjustments or workarounds. However, this also meant that elements with a height of 100vh would overflow the screen when a page was first loaded, as the browser UI was still at its smallest size.

Introducing New CSS Units

In an effort to further streamline development processes and address the limitations of the traditional vh and vw units, new CSS units were proposed and accepted in the CSS specification in 2019 and 2021.

Large Viewport (lvh and lvw) Units

The large viewport (lvh and lvw) units were introduced to define dimensions based on the largest view size of the browser UI. These units provide a more accurate representation of element sizes on browsers with varying viewport dimensions. The lvh unit represents a percentage of the largest viewport height, while the lvw unit represents a percentage of the largest viewport width.

Small Viewport (svh and svw) Units

To complement the large viewport units, small viewport (svh and svw) units were also introduced. These units define dimensions based on the smallest view size of the browser UI. The svh unit represents a percentage of the smallest viewport height, while the svw unit represents a percentage of the smallest viewport width. The small viewport units ensure that elements maintain their intended sizes even on browsers with limited viewport dimensions.

Dynamic Viewport (dvh and dvw) Units

The dynamic viewport (dvh and dvw) units offer a unique approach to dimension specification. These units define dimensions based on the dynamic size of the viewport. As the user scrolls or interacts with the webpage, the content size can adjust dynamically. This allows for more fluid designs that adapt to user interaction and provide a more seamless experience. The dvh unit represents a percentage of the viewport height that adjusts as the user scrolls, while the dvw unit represents a percentage of the viewport width that also reacts to user interactions.

Concerns and Conclusion

While the introduction of new CSS units has aimed to streamline development processes and address the challenges associated with the traditional vh and vw units, there are still concerns regarding their definition and application.

Currently, the traditional vh and vw units are defined as being equivalent to one of the new units based on a UA-defined viewport size. However, this definition leaves room for vagueness and inconsistency across different browsers and devices. Developers and users may experience varying results when utilizing these units, leading to potential frustrations and complexities.

In conclusion, the vh and vw units provide valuable tools for designing responsive layouts based on viewport dimensions. The responsive and static solutions have made significant strides in addressing the challenges associated with these units. However, the introduction of new CSS units offers even more flexibility and control over element sizing. As the web evolves, it is important for developers and browser vendors to continue refining and improving CSS units to ensure a consistent and optimized user experience.

Looking for a Postman alternative?

Try APIDog, the Most Customizable Postman Alternative, where you can connect to thousands of APIs right now!

--

--