How to use Viewport In CSS

We can use viewport units to set font sizes relative to the viewport size. This ensures that font sizes adjust according to the size of the viewport, making them responsive.

Syntax:

.class_name {
font-size: 4vw;
}

Example: The below code will explain the use of the viewport units to make CSS font size fit container effectively.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>GFG</title>
    <meta name="viewport" content=
"width=device-width, initial-scale=1.0" />
    <style>
        .responsive-text {
            font-size: 4vw;
            text-align: center;
            border: 2px solid black;
        }
    </style>
</head>

<body>
    <div class="container">
        <p class="responsive-text">
            w3wiki is a leading platform that provides 
            computer science resources and coding challenges 
            for programmers and technology enthusiasts, along 
            with interview and exam preparations for upcoming 
            aspirants. With a strong emphasis on enhancing coding 
            skills and knowledge, it has become a trusted destination 
            for over 12 million plus registered users worldwide. The 
            platform offers a vast collection of tutorials, practice 
            problems, interview tutorials, articles, and courses, covering 
            various domains of computer science.
        </p>
        <p class="responsive-text">
            Our exceptional mentors hailing from top 
              colleges & organizations have the ability 
              to guide you on a journey from the humble beginnings 
            of coding to the pinnacle of expertise. 
              Under their guidance watch your skills flourish 
              as we lay the foundation and help you conquer the 
            world of coding.
        </p>
        <p class="responsive-text">
            Our brand is built on the pillars of expertise, 
              accessibility, and community. We strive to 
              empower individuals to enhance their programming 
            skills, to bridge the gap between academia and 
              industry, and provide a supportive community to 
              the learners. w3wiki is committed to promoting 
            technological advancement and providing opportunities 
              for growth in the ever-evolving field of computer science.
        </p>
    </div>
</body>

</html>

Output:

How to make CSS Font Size Fit Container Effectively ?

Making CSS font size fit a container effectively involves ensuring that the text scales appropriately based on the dimensions of the container. This is crucial for maintaining readability and a consistent user experience regardless of the device being used.

Table of Content

  • Using Viewport
  • Using Media Queries
  • Using CSS Clamp

Similar Reads

Using Viewport

We can use viewport units to set font sizes relative to the viewport size. This ensures that font sizes adjust according to the size of the viewport, making them responsive....

Using Media Queries

We can implement media queries to define specific font sizes for different screen sizes. This allows us to adjust font sizes based on the screen size of the device....

Using CSS Clamp

We can utilize CSS Clamp to make text content flexible within containers. It takes three parameters: value1, value2, and value3. value1 represents the minimum allowed value, value2 is the preferred value, and value3 is the maximum allowed value....