<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: AmanMandal1</title>
    <description>The latest articles on DEV Community by AmanMandal1 (@amanmandal1).</description>
    <link>https://dev.to/amanmandal1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F987470%2F40d313de-ea6e-4b53-a4ad-c570529d5005.png</url>
      <title>DEV Community: AmanMandal1</title>
      <link>https://dev.to/amanmandal1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amanmandal1"/>
    <language>en</language>
    <item>
      <title>CSS Color-Contrast(): A Step-By-Step Guide</title>
      <dc:creator>AmanMandal1</dc:creator>
      <pubDate>Thu, 25 Jul 2024 14:09:44 +0000</pubDate>
      <link>https://dev.to/testmuai/css-color-contrast-a-step-by-step-guide-240n</link>
      <guid>https://dev.to/testmuai/css-color-contrast-a-step-by-step-guide-240n</guid>
      <description>&lt;p&gt;Have you ever come across a website and literally got frustrated because you were having trouble using it? Maybe because the text size was too small, or perhaps it’s using some WebGL/Three.js technology that your browser doesn’t support, or the font color and contrast were too weird.&lt;/p&gt;

&lt;p&gt;If you think back to these annoying experiences where you could not navigate through a website correctly, there’s a high probability that you’ve experienced inaccessibility in one form or another. It creates an overlap between unpleasant user experience and inaccessibility.&lt;br&gt;&lt;br&gt;
For example, if you found yourself struggling to read small texts on a particular website, the chances are a visually impaired person wouldn’t be able to read at all.&lt;/p&gt;

&lt;p&gt;And somehow, if you are a designer and manage to design a website with a better font size, you would improve the experience and accessibility for all the users, including those with visual impairments. To build and launch an accessible website, the CSS color-contrast() feature can help developers provide adequately contrasting and accessible user interfaces where everyone can easily access and use information and services.&lt;/p&gt;

&lt;p&gt;By considering the needs of visually impaired and disabled individuals during the design process, we can build websites that are easy to navigate and understand for everyone. This means using clear and concise language, providing alternative text for images, and using structured layouts that are easy to understand.&lt;/p&gt;

&lt;p&gt;By following these principles, we can create an inclusive web accessible to all users and promote equality and inclusivity. And in this guide, we particularly see how the CSS color-contrast() helps us to create accessible user interfaces.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a great solution for cross browser testing on Safari? Forget about emulators or simulators — use real online browsers. Try LambdaTest to test on&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/test-on-safari-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Safari browser online&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Accessibility?
&lt;/h3&gt;

&lt;p&gt;The term ‘Accessibility,’ sometimes shortened to Ally, means the web design that works for everyone despite their language, location, ability, or hardware (device). Accessible design is not just about accommodating attention to people with permanent disabilities but creating a seamless experience for all users regardless of their abilities. It’s about designing a website that is easy to navigate, understand, and use for everyone, including those with physical impairments.&lt;/p&gt;

&lt;p&gt;Accessibility is crucial for creating a positive user experience for all individuals, including those with impairments. By ensuring that all users can easily navigate and access the information they need, we are promoting inclusivity and equality in the digital space. This benefits those with special needs and enhances the overall user experience. Check our tutorial on &lt;a href="https://www.lambdatest.com/learning-hub/accessibility-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;accessibility testing&lt;/a&gt; to learn more.&lt;/p&gt;

&lt;p&gt;According to a survey by the World Health Organization, approximately 16% of the world’s population lives with some form of disability, which is expected to increase with an aging population. This means that a significant proportion of internet users may have difficulties accessing traditional websites.&lt;/p&gt;

&lt;p&gt;By designing for accessibility, we can not only make the internet a more inclusive place for people with disabilities but also create new opportunities for businesses. Accessible websites can increase the potential customer base, provide a better user experience, and improve the brand reputation.&lt;/p&gt;

&lt;p&gt;One way to achieve this is by adhering to the Web Content Accessibility Guidelines (WCAG) developed by the World Wide Web Consortium (W3C). These guidelines provide specific recommendations for creating accessible digital content, including guidelines for text contrast.&lt;/p&gt;

&lt;p&gt;The WCAG recommends a minimum contrast ratio of 4.5:1 between text and its background to ensure that text is easy to read for all users, including those with visual impairments. By following these guidelines, designers can create websites that are accessible and user-friendly for all users, regardless of their abilities.&lt;/p&gt;

&lt;p&gt;So, considering the contrast ratio of text and background will not only enhance the user experience of visually impaired people and all users in general. And this ease of use, specifically considering visually impaired individuals, is the foundation for creating accessible &lt;a href="https://www.lambdatest.com/blog/20-elements-of-modern-web-design/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;modern web designs&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why is Web Accessibility important?
&lt;/h3&gt;

&lt;p&gt;Many designers used to think that accessibility is a &lt;strong&gt;‘nice to have’&lt;/strong&gt; feature when designing, but now accessibility is no longer considered an optional feature and has become a necessity for many organizations.&lt;/p&gt;

&lt;p&gt;According to a report by the WebAIM organization, 96.8% of home pages studied had WCAG2 failures. Having accessibility at the top of the mind while designing a user interface (UI) will improve the user experience for not only disabled individuals but also for the general user as well.&lt;/p&gt;

&lt;p&gt;By the way, It’s one thing to require alt text on an image element or a label for an input element, but enforcing color palettes is entirely different. So, now let’s look at how this CSS color-contrast() will help us with that!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rkdi2L7XtE4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;LambdaTest's online mobile emulators allow you to seamlessly test your mobile applications, websites, and web apps on mobile browsers and devices, without the need for a physical device. Try our&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/mobile-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;emulator online&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;now.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=youtube" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/selenium?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/playwright?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Appium&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview of CSS color-contrast() function
&lt;/h3&gt;

&lt;p&gt;While writing this article, CSS color-contrast() is an experimental feature, and it’s a part of CSS Color Module Level 5.&lt;/p&gt;

&lt;p&gt;Currently, the CSS color-contrast() feature is only available in Safari (TP). And you can turn on the feature in the &lt;strong&gt;Develop&lt;/strong&gt; and &lt;strong&gt;Experimental Features&lt;/strong&gt; menus.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AKmmUx1aI16I26ooE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AKmmUx1aI16I26ooE.png" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Source&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Below are CodePen examples that may not work if you are not using the above-recommended browser.&lt;/p&gt;

&lt;p&gt;The main purpose of this feature is to select the ideal contrasting color from a list when compared against a base color.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGUq0XgNjMXn___9S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AGUq0XgNjMXn___9S.png" alt="image" width="800" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; color: color-contrast(#505050 vs #fff, #000 )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our article refers to the first parameter as the &lt;strong&gt;“base color”&lt;/strong&gt; and the second parameter as the &lt;strong&gt;“color list.”&lt;/strong&gt; The CSS color-contrast() function can accept any browser-supported CSS color formats like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hexadecimal (#ff3300)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RGB (rgb(255, 0, 0))&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RGBA (rgba(25, 32, 65, 0.86))&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HSL colors (hsl(120, 100%, 125%))&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There’s also a third parameter to the function which is &lt;strong&gt;target contrast&lt;/strong&gt;, but we will talk about it in the later part of this blog.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started with CSS color-contrast()
&lt;/h3&gt;

&lt;p&gt;The CSS color-contrast() function ensures that text on a webpage has enough contrast with its background for easy readability. This is particularly important for visually impaired users who may struggle to read text with low contrast.&lt;/p&gt;

&lt;p&gt;From Rachel Andrew’s talk at AxeCon 2022, New CSS With Accessibility in Mind, we come to know how big of an impact a CSS feature can have in the world of accessible design.&lt;/p&gt;

&lt;p&gt;Rachel also demoed the new feature by dynamically defining text colors based on the background colors. Here is the CodePen example for CSS color-contrast().&lt;/p&gt;

&lt;p&gt;So, let’s take a quick look at this feature by setting some background colors and text colors.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --primary-background: #1e1e1e;
      }


      .content {
        Background-color: var(--primary-background);


        color: color-contrast(var(--primary-background) vs #fff, #000);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code block, we defined the &lt;strong&gt;–primary-background&lt;/strong&gt; custom property as a shade of dark grey, #1e1e1e. And then, we used the same property as the base color in the color-contrast () function and compared it against each item in the color list to find the highest contrasting value.&lt;/p&gt;

&lt;p&gt;Now let’s take it a little further and try to experiment with the function. We can effectively chain the &lt;strong&gt;color-contrast ()&lt;/strong&gt; functions by simply using the result of the base color of another function. This sounds tough, but let’s take the previous example of &lt;strong&gt;.content&lt;/strong&gt; only and try to chain it!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A comprehensive&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;end-to-end Testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tutorial that covers what E2E Testing is, its importance, its benefits, and how to perform it with real-time examples.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --primary-background: #5e5c5c;
        --primary-color: color-contrast(
          var(--primary-background) vs #fff,
          #000
        );
      }


      .content {
        background-color: var(--primary-background);



  color: var(--primary-color);
      }


      .content &amp;gt; p {
        color: color-contrast(var(--primary-color) vs #fff, #000);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code block, we defined the &lt;strong&gt;–primary-background&lt;/strong&gt; custom property as a shade of dark grey, and we use the same custom property as the base color in the &lt;strong&gt;color-contrast()&lt;/strong&gt; function and then compared it with the items in the color list, i.e., &lt;strong&gt;white&lt;/strong&gt; and &lt;strong&gt;black&lt;/strong&gt; and stored it in a custom variable called &lt;strong&gt;–primary-color&lt;/strong&gt;. Then in the &lt;strong&gt;.content&lt;/strong&gt; class, we used the background color and the color as variables, but here comes the interesting part!&lt;/p&gt;

&lt;p&gt;Inside the content class, we changed the text color of all the paragraphs (p tag) by chaining the color-contrast () function. We simply used the &lt;strong&gt;–primary-color&lt;/strong&gt; variable, i.e., a color derived using the color-contrast () we defined earlier in the &lt;strong&gt;root&lt;/strong&gt; as the base color. We compared it with the items in the color list.&lt;/p&gt;

&lt;p&gt;Here’s the complete example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Blog&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;h2&amp;gt;CSS color-contrast() demo&amp;lt;/h2&amp;gt;



      &amp;lt;div class="content"&amp;gt;
        &amp;lt;p&amp;gt;
          A simple paragraph example for the css color contrast function! Lorem ipsum, dolor sit amet consectetur adipisicing elit. Minima molestias
        ullam voluptas et obcaecati sapiente veritatis fugit exercitationem
          dolorem illo quidem sit soluta, tempore
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --primary-background: #505050;
        --primary-color: color-contrast(
          var(--primary-background) vs #fff,
          #000
        );
        /* --primary-color: white; */
      }


      body {
        margin: 0;
        padding: 0;
      }


      .container {
        width: 450px;
        margin: 0 auto;
        margin-top: 50px;
        border: 1px solid gray;
        font-family: "Franklin Gothic Medium", "Arial Narrow", Arial, sans-serif;
      }


      .container &amp;gt; h2 {
        padding-left: 20px;
        font-size: 2rem;
      }


      .content {
        background-color: var(--primary-background);
        color: var(--primary-color);
        padding: 20px;
      }


      .content &amp;gt; p {
        line-height: 1.4rem;
        font-size: 1.2rem;
        margin: 0;
        color: color-contrast(var(--primary-color) vs #fff, #000);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
      &amp;lt;h2&amp;gt;CSS color-contrast() demo&amp;lt;/h2&amp;gt;

      &amp;lt;div class="content"&amp;gt;
        &amp;lt;p&amp;gt;
          A simple paragraph example for the css color contrast function! Lorem
          ipsum, dolor sit amet consectetur adipisicing elit. Minima molestias
          ullam voluptas et obcaecati sapiente veritatis fugit exercitationem
          dolorem illo quidem sit soluta, tempore
        &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code is an example of how to use the CSS color-contrast() function to ensure that text color meets the minimum recommended contrast ratio as defined in the WCAG. It uses the CSS color-contrast() function to compare the contrast ratio of the text color against the background color and assigns a new class to the text if the contrast ratio is not met. This helps ensure that text is legible for all users, including those with visual impairments.&lt;/p&gt;

&lt;p&gt;By using the CSS color-contrast() function, the code can automate the process of checking for contrast ratios and enhance the user experience for all users. The above code is an example of how to implement accessibility features in a website. It adds value to accessibility by providing a simple and efficient way to ensure that text is legible for all users, including those with visual impairments.&lt;/p&gt;

&lt;p&gt;But we can take it further using the &lt;strong&gt;::selection&lt;/strong&gt; pseudo-element. Here’s how we can implement it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
      &amp;lt;h1&amp;gt;CSS Color-Contrast() ::Selection&amp;lt;/h1&amp;gt;


      &amp;lt;article class="article article-top"&amp;gt;
        &amp;lt;h2&amp;gt;Selenium Test Automation Cloud&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;
          A reliable, scalable, secure, and high performing test execution cloud
          that empowers development and testing teams to accelerate their
          release cycles. Test in parallel and cut down test execution by more
          than 10x.
        &amp;lt;/p&amp;gt;
      &amp;lt;/article&amp;gt;


      &amp;lt;article class="article article-bottom"&amp;gt;
        &amp;lt;h2&amp;gt;Cypress Automation Testing&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;
          Run end-to-end tests on a blazing fast Cypress test execution cloud. A
          reliable, scalable, secure and high performing test execution platform
          built for scale. Test on 40+ different browser and browser versions
          including headless versions.
        &amp;lt;/p&amp;gt;
      &amp;lt;/article&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    .content {
        --content-bg: #eef5ff;
        --content-color: color-contrast(var(--content-bg) vs #fff, #000);


        background: var(--content-bg);
        color: var(--content-color);
        padding: 0.5rem 1rem;
        border: 1px solid black;
        border-radius: 12px;
        margin-bottom: 12px;
      }


      .content:last-of-type {
        --content-bg: #4992af;
      }


      .content::selection {
        @supports (background: color-contrast(#000 vs #fff, #eee)) {
          background: color-contrast(var(--content-color) vs #8fc8de, #595959);
        }
      }


      :root {
        --body-base: #fbf8cc;
        --color-primary: #8fc8de;
        --scrollbar-bg: #222;
      }


      body::-webkit-scrollbar {
        width: 10px;
      }
      body {
        scrollbar-width: thin;
        scrollbar-color: var(--color-primary) var(--scrollbar-bg);
      }
      body::-webkit-scrollbar-track {
        background: var(--scrollbar-bg);
      }
      body::-webkit-scrollbar-thumb {
        background-color: var(--color-primary);
        border-radius: 6px;
        border: 3px solid var(--scrollbar-bg);
      }


      html,
      body {
        color: #000;
        font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
          "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
        font-size: 100%;
        letter-spacing: 0.25px;
        line-height: 1.75;
        margin: 0;
        padding: 0;
      }


      body {
        background: rgb(194, 226, 228);
        block-size: 100%;
        display: grid;
        min-block-size: 100vh;
        place-items: center;
      }


      a {
        color: #c8553d;
        text-decoration: underline 1px dashed;
        text-underline-offset: min(5px, 1em);
      }


      a:focus {
        outline: 1px solid currentColor;
        outline-offset: 3px;
      }


      a:hover {
        color: #131313;
      }


      h1,
      h2 {
        font-family: "Gill Sans", "Gill Sans MT", Calibri, "Trebuchet MS",
          sans-serif;
        line-height: 1.25;
      }


      .container {
        inline-size: min(750px, 50vw);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
      &amp;lt;h1&amp;gt;CSS Color-Contrast() ::Selection&amp;lt;/h1&amp;gt;

      &amp;lt;article class="article article-top"&amp;gt;
        &amp;lt;h2&amp;gt;Selenium Test Automation Cloud&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;
          A reliable, scalable, secure, and high performing test execution cloud
          that empowers development and testing teams to accelerate their
          release cycles. Test in parallel and cut down test execution by more
          than 10x.
        &amp;lt;/p&amp;gt;
      &amp;lt;/article&amp;gt;

      &amp;lt;article class="article article-bottom"&amp;gt;
        &amp;lt;h2&amp;gt;Cypress Automation Testing&amp;lt;/h2&amp;gt;
        &amp;lt;p&amp;gt;
          Run end-to-end tests on a blazing fast Cypress test execution cloud. A
          reliable, scalable, secure and high performing test execution platform
          built for scale. Test on 40+ different browser and browser versions
          including headless versions.
        &amp;lt;/p&amp;gt;
      &amp;lt;/article&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AORtMKL-duXCbdKkQ.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AORtMKL-duXCbdKkQ.gif" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above code block, we used the CSS color-contrast() function with the &lt;strong&gt;::selection&lt;/strong&gt; pseudo-element, and as you can see how effective it is!&lt;/p&gt;

&lt;p&gt;But the &lt;strong&gt;color-contrast()&lt;/strong&gt; function isn’t limited to only comparing HEX codes (#000000). The previous example can be tweaked to use different color types simultaneously while returning the same results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --content-bg: rgb(43, 23, 244);
        --content-color: color-contrast(
          var(--content-bg) vs #fff,
          hsl(0, 100%, 12%)
        );
      }


      .content {
        background-color: var(--content-bg);
        color: var(--content-color);
      }


      .content::selection {
        background: color-contrast(
          var(--article-color) vs hsl(0, 1%, 26%),
          white
        );
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The color-contrast() function can simply chain HSL colors, RGBA colors, RGB colors, etc. at the same time without giving any potential errors. So, because of this particular feature, working with contrasts will be easier and more accessible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;A comprehensive end-to-end Testing tutorial that covers what&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/learning-hub/end-to-end-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;E2E Testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;is, its importance, benefits, and how to perform it with real-time examples.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Color-Contrast() with Pseudo Classes
&lt;/h3&gt;

&lt;p&gt;We have used the &lt;strong&gt;::selection&lt;/strong&gt; pseudo-element with CSS color-contrast() function, and setting colors dynamically while selecting fonts is fascinating. But it’s more of a static thing, like text colors and backgrounds won’t change after they are rendered.&lt;/p&gt;

&lt;p&gt;So, let’s look at something much more intriguing, i.e., changing contrasts on interactive elements and their &lt;a href="https://www.lambdatest.com/blog/css-pseudo-class-selectors/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS pseudo-classes&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When navigating through a website, we sometimes use only our keyboard, and there are a variety of tab stops along the way, like &lt;strong&gt;buttons&lt;/strong&gt;, &lt;strong&gt;input&lt;/strong&gt; elements, &lt;strong&gt;links&lt;/strong&gt; inside the body, and maybe a &lt;strong&gt;linked image&lt;/strong&gt; or &lt;strong&gt;a card&lt;/strong&gt;. While each element must have a compliant focus indicator, it’s not easy to create a focus pseudo-element for all the elements present. And here, &lt;strong&gt;color-contrast()&lt;/strong&gt; can help!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --background-primary: #737272;
        --background-button: #1a73e8;
        --button-text-color: color-contrast(
          var(--background-button) vs #fff,
          #000
        );
        --button-hover: #13427e;
        --color-list: var(
          var(--background-button),
          var(--button-text-color),
          rgb(158, 113, 113),
          rgb(93, 88, 88)
        );
      }


      .rounded-btn {
        background: var(--background-button);
        color: var(--button-text-color);
      }


      .rounded-btn:hover {
        background-color: var(--button-hover);
      }


      .rounded-btn:focus {
        box-shadow: 2px 1px 23px 3px
          color-contrast(var(--background-primary) vs var(--color-list));
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s see what is going on in the above snippet.&lt;/p&gt;

&lt;p&gt;The — &lt;strong&gt;background-button&lt;/strong&gt; custom property is used as the base color in the color-contrast() function for selecting the value of — &lt;strong&gt;button-text-color&lt;/strong&gt;. Anytime the — &lt;strong&gt;background-button&lt;/strong&gt; changes, the custom — &lt;strong&gt;button-text-color&lt;/strong&gt; will also change because they are chained. Then we defined — &lt;strong&gt;button-hover&lt;/strong&gt; custom property for the &lt;strong&gt;:hover&lt;/strong&gt; pseudo-element.&lt;/p&gt;

&lt;p&gt;Now comes one of the most important pseudo-element when talking about accessibility, the &lt;strong&gt;:focus&lt;/strong&gt; element. The &lt;strong&gt;:focus&lt;/strong&gt; style is where the color-contrast() function can be expanded by using the — &lt;strong&gt;background-primary&lt;/strong&gt; custom property as the base color in the function. It’s compared to the current style of button, which provides the ability to have contextually-aware focus styles.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the example and try to understand it better.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;title&amp;gt;Blog&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;CSS Color-Contrast() :hover &amp;amp; :focus pseudo-classes&amp;lt;/h1&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;h3&amp;gt;Selenium Test Automation Cloud&amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;
        A reliable, scalable, secure, and high performing test execution cloud
        that empowers development and testing teams to accelerate their release
        cycles. Test in parallel and cut down test execution by more than 10x.
        browser.
      &amp;lt;/p&amp;gt;


      &amp;lt;button class="btn"&amp;gt;Test Online&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
        --body-base: #131e25;
        --color-primary: rgba(255, 124, 0, 1);
        --scrollbar-bg: #222;
      }
      html,
      body {
        color: #fff;
        font-family: "Barlow", sans-serif;
        font-size: 100%;
        letter-spacing: 0.25px;
        line-height: 1.75;
        margin: 0;
        padding: 0;
      }


      .container {
        width: 500px;
        border: 1px solid lightgray;
        padding: 20px;
        border-radius: 12px;
        background-color: #2d043a;
      }


      .container &amp;gt; h3 {
        color: rgb(181, 210, 212);
        font-size: 1.5rem;
      }


      .btn {
        --btn-base: #76d8ff;
        --btn-color: color-contrast(var(--btn-base) vs #fff, #000);
        --btn-gradient: linear-gradient(
          180deg,
          rgb(94, 150, 223) 0%,
          rgb(27, 83, 87) 100%
        );


        background: var(--btn-base);
        background: var(--btn-gradient);
        border: 5px solid var(--body-base);
        border-radius: 12px;
        color: var(--btn-color);
        padding: 1em 2em;
        font-size: 14px;
      }


      .btn:hover {
        --btn-base: #0079b1;
        --btn-gradient: linear-gradient(
          180deg,
          rgb(38, 88, 196) 0%,
          rgb(2, 53, 112) 100%
        );


        background: var(--btn-base);
        background: var(--btn-gradient);
        cursor: pointer;
      }


      .btn:focus {
        box-shadow: 0 0 1px 3px
          color-contrast(var(--body-base) vs var(--btn-base), #bbb);
      }
      .btn:active {
        opacity: 0.95;
        transform: scale(0.98);
        transform-origin: center;
      }


      body {
        background: #96a1a8;
        block-size: 100%;
        display: grid;
        min-block-size: 100vh;
        place-items: center;
      }


      h1,
      h2 {
        font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
        line-height: 1.25;
      }


      section {
        inline-size: min(750px, 50vw);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;CSS Color-Contrast() :hover &amp;amp; :focus pseudo-classes&amp;lt;/h1&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;h3&amp;gt;Selenium Test Automation Cloud&amp;lt;/h3&amp;gt;
      &amp;lt;p&amp;gt;
        A reliable, scalable, secure, and high performing test execution cloud
        that empowers development and testing teams to accelerate their release
        cycles. Test in parallel and cut down test execution by more than 10x.
        browser.
      &amp;lt;/p&amp;gt;

      &amp;lt;button class="btn"&amp;gt;Test Online&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;

  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AaNazlBoFyNJQQoXE.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2AaNazlBoFyNJQQoXE.gif" alt="image" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the above example, we have used the color-contrast() function with pseudo-classes. Stephanie Eckle’s presentation on “Modern CSS Upgrades To Improve Accessibility” provides a detailed and clear overview of various CSS upgrades that can improve accessibility for users. The presentation covers topics such as CSS color-contrast(), semantic HTML, and &lt;a href="https://www.lambdatest.com/learning-hub/responsive-design?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;responsive design&lt;/a&gt; and offers clear examples to illustrate the concepts. The presentation is a great resource for those looking to improve the accessibility of their websites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;New&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Selenium IDE&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;supports cross browser testing and parallel tests for automation along with record and replay function. Here’s why you shouldn’t miss out on it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Target Contrast Ratio
&lt;/h3&gt;

&lt;p&gt;In the beginning of this article, I talked about the optional third parameter for the CSS color-contrast() function. Now let’s dig deeper into this feature.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A1SgG0ZCcBIAqvpBr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F800%2F0%2A1SgG0ZCcBIAqvpBr.png" alt="image" width="800" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The optional third parameter for the color-contrast() function defines a target contrast ratio. The parameter accepts either a keyword — AA, AA-large, AAA, and AAA-large — or a number. When a target contrast is defined, the first color from the color list that meets or exceeds it is selected.&lt;/p&gt;

&lt;p&gt;Let’s take a look at an example to understand the feature properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;section class="container"&amp;gt;
      &amp;lt;h1&amp;gt;Target Contrast Ratio&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;
        CSS color-contrast() function is having a third parameter called as
        &amp;lt;span style="color: red"&amp;gt;Target contrast ratio&amp;lt;/span&amp;gt; . This feature is
        only available in Safari Browser right now, so if you are using any
        other browser this won't work!
      &amp;lt;/p&amp;gt;


      &amp;lt;div class="sample-block"&amp;gt;
        &amp;lt;p&amp;gt;Target Ratio: &amp;lt;span&amp;gt;AA (4.5)&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;


      &amp;lt;form&amp;gt;
        &amp;lt;label&amp;gt;
          Ratio Keywords
          &amp;lt;select id="ratios"&amp;gt;
            &amp;lt;option value="AA (4.5)" selected&amp;gt;AA (4.5)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AA-Large (3)"&amp;gt;AA-Large (3)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AAA (7)"&amp;gt;AAA (7)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AAA-Large (4.5)"&amp;gt;AAA-Large (4.5)&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;&amp;lt;/label
        &amp;gt;


        &amp;lt;label&amp;gt;
          Custom Ratio
          &amp;lt;input
            id="slider"
            type="range"
            min="0"
            max="20"
            value="4.5"
            step="0.1"
          /&amp;gt;
        &amp;lt;/label&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/section&amp;gt;


    &amp;lt;style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
        --contrast-target: AA;
      }


      .sample-block {
        --color-set: #001908, #005f73, #b5e62e, #bff5e3, #544107, #ee9b00;
        --base: color-contrast(
          var(--body-base) vs var(--color-set) to var(--contrast-target)
        );


        background: var(--base);
        display: grid;
        padding: 0.75em 1em;
        place-items: center;
      }


      .sample-block {
        background-color: whitesmoke;
        border-radius: 20px;
        margin-bottom: 30px;
      }


      .sample-block &amp;gt; p {
        color: black;
      }


      /* .sample-block &amp;gt; p {
        color: color-contrast(
          var(--base) vs var(--color-set),
          #fff to AA-Large
        );
      } */




      body::-webkit-scrollbar {
        display: none;
      }


      html,
      body {
        color: #fff;
        font-family: "Barlow", sans-serif;
        font-size: 100%;
        letter-spacing: 0.25px;
        line-height: 1.75;
        margin: 0;
        padding: 0;
      }


      body {
        block-size: 100%;
        display: grid;
        min-block-size: 100vh;
        place-items: center;
      }


      .container {
        background: rgb(24, 40, 52);
        padding: 20px;
        border-radius: 20px;
      }


      .container &amp;gt; h1 {
        text-align: center;
        margin-bottom: 30px;
        padding-bottom: 30px;
      }


      a {
        color: #e9d8a6;
        text-decoration: underline 1px dashed;
        text-underline-offset: min(5px, 1em);
      }


      a:hover {
        color: #ffe8d6;
      }


      a:focus {
        outline: 1px solid currentColor;
        outline-offset: 3px;
      }


      h1,
      h2 {
        line-height: 1.25;
      }


      section {
        inline-size: min(750px, 50vw);
      }


      form {
        display: grid;
        grid-gap: 2rem;
        grid-template-columns: 1fr 1fr;
        padding-block-end: 1rem;
      }


      label {
        display: grid;
        font-size: 1.2rem;
        font-weight: 600;
      }


      select,
      input {
        display: block;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;JavaScript:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document
        .querySelector("#ratios")
        .addEventListener("change", (e) =&amp;gt; {
          document.body.style.setProperty("--contrast-target", e.target.value);
          document.querySelector(".sample-block span").innerHTML =
            e.target.value;
        });


      document.querySelector("#slider").addEventListener("input", (e) =&amp;gt; {
        document.body.style.setProperty("--contrast-target", e.target.value);
        document.querySelector(".sample-block span").innerHTML = e.target.value;
      });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section class="container"&amp;gt;
      &amp;lt;h1&amp;gt;Target Contrast Ratio&amp;lt;/h1&amp;gt;
      &amp;lt;p&amp;gt;
        CSS color-contrast() function is having a third parameter called as
        &amp;lt;span style="color: red"&amp;gt;Target contrast ratio&amp;lt;/span&amp;gt; . This feature is
        only available in Safari Browser right now, so if you are using any
        other browser this won't work!
      &amp;lt;/p&amp;gt;

      &amp;lt;div class="sample-block"&amp;gt;
        &amp;lt;p&amp;gt;Target Ratio: &amp;lt;span&amp;gt;AA (4.5)&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;form&amp;gt;
        &amp;lt;label&amp;gt;
          Ratio Keywords
          &amp;lt;select id="ratios"&amp;gt;
            &amp;lt;option value="AA (4.5)" selected&amp;gt;AA (4.5)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AA-Large (3)"&amp;gt;AA-Large (3)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AAA (7)"&amp;gt;AAA (7)&amp;lt;/option&amp;gt;
            &amp;lt;option value="AAA-Large (4.5)"&amp;gt;AAA-Large (4.5)&amp;lt;/option&amp;gt;
          &amp;lt;/select&amp;gt;&amp;lt;/label
        &amp;gt;

        &amp;lt;label&amp;gt;
          Custom Ratio
          &amp;lt;input
            id="slider"
            type="range"
            min="0"
            max="20"
            value="4.5"
            step="0.1"
          /&amp;gt;
        &amp;lt;/label&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/section&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the &lt;strong&gt;target contrast ratio&lt;/strong&gt; is defined, the &lt;strong&gt;color-contrast()&lt;/strong&gt; function will return the very first value from the color list that meets the target. However, when no value in the color list meets the target contrast, that’s where the magic happens!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;h1{
        color: color-contrast(#000 vs #111, #222 to AA);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see in the above code snippet, the base color is &lt;strong&gt;black(#000),&lt;/strong&gt; and the color list consists of two dark shades of grey, but no value would meet the AA(4.5) target contrast. So what will happen then?&lt;/p&gt;

&lt;p&gt;CSS will fill in the blanks if the color list doesn’t contain a value that meets the target contrast — either black or white. In this case, color-contrast() could enable designers to enforce a specific level of accessibility.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.background-primary {
        --background: #000;
        --color-list: #111, #222;
      }


      .background-primary {
        background: var(--background);
        color: color-contrast(var(--background) vs var(--color-list));
      }
      .background-primary.with-target-ratio {
        color: color-contrast(var(--background) vs var(--color-list) to AA);
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s have a look at the above code snippet and try to understand the target ratio.&lt;/p&gt;

&lt;p&gt;The base .&lt;strong&gt;background-primary&lt;/strong&gt; class does not use a target contrast. And this results in the color being defined as #222, the highest contrasting value from the color list relative to the base color, black. But is the color #222 (another black shade) accessible here? The clear answer is a NO!&lt;/p&gt;

&lt;p&gt;Now let’s compare this to when the &lt;strong&gt;.background-primary&lt;/strong&gt; and the .&lt;strong&gt;with-target-ratio&lt;/strong&gt; classes are combined, and a target contrast is specified. The results are very different despite using the same base color and color list. If none of the colors in the color list meet the AA contrast target, the function chooses the color that does. In this case, &lt;strong&gt;White!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automated&lt;/em&gt;&lt;/strong&gt; &lt;a href="https://www.lambdatest.com/blog/automated-functional-testing-what-it-is-how-it-helps/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=mar23_ap&amp;amp;utm_term=ap&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;Functional Testing&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;&lt;em&gt;tests helps to ensure that your web app works as it was intented to. Learn more about functional tests, and how automating them can give you a faster release cycle.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Inevitable Drawbacks of CSS color-contrast()
&lt;/h3&gt;

&lt;p&gt;As we know, the CSS color-contrast() function is still an experimental feature, so there are many improvements at the time of writing this article. Let’s look at what they are and how to deal with them!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Visual Contrasts and Colors are not the same&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Highest contrast doesn’t mean the accessible one&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;No Gradients support as of now&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Color-contrast&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  It’s a Wrap!
&lt;/h3&gt;

&lt;p&gt;That was a lot to take in, but let’s quickly review what we’ve learned about the CSS color-contrast() function.&lt;/p&gt;

&lt;p&gt;So, the &lt;strong&gt;color-contrast()&lt;/strong&gt; function is an experimental feature that selects the greatest contrasting color. It takes three arguments: the base color, the color list, and the target contrast ratio (optional). The CSS color-contrast() simply compares the base color to the color list and returns the highest contrasting color, which helps to improve accessibility on the web on a much larger scale.&lt;/p&gt;

&lt;p&gt;Once the spec has been implemented and supported by browsers, the color-contrast() function can be the game-changing feature. There are plenty of unexplored areas and use cases for CSS color-contrast(). In the near future, we are hoping to see this feature on all browsers so that we all can start using it. Until then, keep experimenting and keep &lt;/p&gt;

</description>
      <category>css</category>
      <category>automation</category>
      <category>cloudtesting</category>
    </item>
    <item>
      <title>A Complete Guide On CSS Typography And Encoding</title>
      <dc:creator>AmanMandal1</dc:creator>
      <pubDate>Tue, 13 Dec 2022 14:25:26 +0000</pubDate>
      <link>https://dev.to/testmuai/a-complete-guide-on-css-typography-and-encoding-21hl</link>
      <guid>https://dev.to/testmuai/a-complete-guide-on-css-typography-and-encoding-21hl</guid>
      <description>&lt;p&gt;Have you ever stumbled on a website and asked yourself questions like, Who made this ??? How can I read this ???&lt;/p&gt;

&lt;p&gt;Then you proceed to another site, and you are like WOWWW !! This is so cool !!. Now let’s ask ourselves two questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What made the first website so unreadable and awful to you?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What made the second website so enjoyable and cool?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the second website, you might just scroll and keep scrolling, probably without actually reading anything, but you marvel at the developer’s creation.&lt;/p&gt;

&lt;p&gt;There are a lot of factors that determine if a site is readable/enjoyable or not, but we will talk about CSS Typography today! It is only logical to say that a designer should get good training in the main discipline of shaping written information, in other words: CSS Typography.&lt;/p&gt;

&lt;p&gt;This is intended as a practical guide to learning CSS typography and encoding. We’ll cover a range of practical and useful topics, like how to choose and use fonts. We will discuss some usability aspects if proper fonts are not used, but more importantly, how to create a pleasant user experience. We’ll go over the principles of &lt;strong&gt;CSS typography&lt;/strong&gt; and the properties that control them.&lt;/p&gt;

&lt;p&gt;Let’s begin with our CSS typography tutorial!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Need a great solution for &lt;a href="https://www.lambdatest.com/safari-browser-for-windows?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Safari on Windows&lt;/a&gt;? Forget about emulators or simulators — use real online browsers. Try LambdaTest for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Typography?
&lt;/h2&gt;

&lt;p&gt;Typography is the art of arranging letters and text to make the website legible, clear, and visually appealing to the reader. Typography involves font style, appearance, and structure, which aims to bring out certain emotions and convey specific messages.&lt;/p&gt;

&lt;p&gt;Type is the user interface for conveying information on the web. We can pull many levers to affect the usability of reading text, and that’s how we can create a pleasant user experience.&lt;/p&gt;

&lt;p&gt;After usability, typography is all about emotion. Do letters complement your content or contradict it? Do they amplify your brand’s personality or dampen it? Different types will make people feel different things applied to the same text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgblpkzvw75idqeba63ec.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgblpkzvw75idqeba63ec.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Typography isn’t an exact science. Good guidelines will get you most of the way there, but you’ll need to apply a little intuition too. Luckily, we’ve been reading text our whole life — books, magazines, the Internet — so we have much more instinct than we think!&lt;/p&gt;

&lt;h2&gt;
  
  
  Fonts and Typefaces: Differences
&lt;/h2&gt;

&lt;p&gt;There’s some confusion surrounding the difference between typefaces and fonts, with many treating the two as synonyms. A &lt;strong&gt;typeface&lt;/strong&gt; is a design style comprising various characters of varying sizes and weights, whereas a font is a graphical representation of text characters.&lt;/p&gt;

&lt;p&gt;Put simply, a typeface is a family of related fonts, while &lt;strong&gt;fonts&lt;/strong&gt; refer to the specific size, weight, or style of a typeface.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmq6ki5qkuacut1vzflbh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmq6ki5qkuacut1vzflbh.png" width="800" height="473"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In essence, a typeface is like a song, and the font is like its MP3 file. Both terms are used in typography literature, so it’s worth knowing the distinction. But, more recently, you can use both terms interchangeably, and designers will understand what you mean.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Do you use a Mac and want to run the test in Internet Explorer? This article explores how to test &lt;a href="https://www.lambdatest.com/blog/test-internet-explorer-for-mac/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Internet explorer for Mac&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Categorization of Fonts
&lt;/h2&gt;

&lt;p&gt;The broadest split is between &lt;strong&gt;serif&lt;/strong&gt; and &lt;strong&gt;sans-serif&lt;/strong&gt; typefaces. You’ve likely come across these terms just by seeing some typeface name floating around.&lt;/p&gt;

&lt;h3&gt;
  
  
  Serif
&lt;/h3&gt;

&lt;p&gt;A “serif” is a small stroke attached to the ends of letters, giving them a traditional feel. Most books and newspapers are set in serif typefaces. The ‘serif’ category includes sub-categories such as Old Style, Classical, Neo-Classical, Transitional, Clarendon, etc.&lt;/p&gt;

&lt;p&gt;Below is what the “Times New Roman” font looks like. Notice the tiny feet present at the tops and bottoms of each letter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc8uxyw3oxzuhpuopvx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foc8uxyw3oxzuhpuopvx2.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Sans Serif
&lt;/h3&gt;

&lt;p&gt;“Sans” comes from the French “without.” As the name states, sans-serif typefaces don’t have these extra strokes, giving them a smooth, modern feel. It includes humanist, geometric and grotesk, etc., as sub-categories.&lt;/p&gt;

&lt;p&gt;Below is the font called “Roboto” in the Sans Serif category. Again, notice the clean and straight lines compared to the serif fonts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fonzf68zf2drusnc10mon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fonzf68zf2drusnc10mon.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Monospace
&lt;/h3&gt;

&lt;p&gt;Monospace fonts are a noteworthy category all on their own. Each glyph (i.e., letter/number.symbol) in a monospace font has the same width (hence the mono spacing terminology), so it’s possible to arrange them into visual structures.&lt;/p&gt;

&lt;p&gt;You may be well familiar with monospace because we developers see it often when writing code, whether it’s helpful to make brackets and indents line up visually.&lt;/p&gt;

&lt;p&gt;Below is the font called “Courier Prime” in the Monospace category. Again, notice how the width between the letters are same (mono) compared to the other fonts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrdpiu6dfdq2ntinrghl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsrdpiu6dfdq2ntinrghl.png" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Upload your app for testing within seconds using the LambdaTest cloud and perform &lt;a href="https://www.lambdatest.com/mobile-app-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;mobile app test&lt;/a&gt; right away. Find bugs early on, improve performance, quality, user experience and make the most of mobile application testing on LambdaTest.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  “Web safe” Fonts vs Custom Fonts
&lt;/h2&gt;

&lt;p&gt;A font is “web safe” if most computers have it installed already, and they don’t have to download it separately when visiting your site. Examples include Arial, Times New Roman, Courier, Georgia, Verdana, and many more.&lt;/p&gt;

&lt;p&gt;A website can declare a custom font as a resource, just like CSS, images, or JavaScript. The visiting browser will download the font and apply it to the texts on the website.&lt;/p&gt;

&lt;p&gt;Another significant way to shed some of the weight of custom web fonts is to use a service that will host and serve them for you. The core benefit here is that third-parties store the files on a CDN (e.g., Cloudflare, StackPath, etc.), optimize them, and serve them to your site via a JavaScript snippet that gets dropped into the document head.&lt;/p&gt;

&lt;p&gt;Let’s see how it is to use a hosted service,&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"&amp;gt;
  &amp;lt;style&amp;gt;
    body {
      font-family: 'Roboto', sans-serif;
    }
  &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The above example is from Google Fonts — the most popular hosted service. It’s free to use and has a catalog of more than 1000 font families. It has fonts with beautiful design, different weights, bold/italics, and many advanced features.&lt;/p&gt;

&lt;p&gt;Another trendy one is Adobe Fonts. It comes with more than 1500 fonts. These are typically high-quality fonts which are paid ones.&lt;/p&gt;

&lt;p&gt;There are many other options like Fontspring, MyFonts by Monotype, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium testing tool&lt;/a&gt; to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One wrong choice leads to another hassle
&lt;/h2&gt;

&lt;p&gt;Many websites and applications are made to be used by many people to indulge in purchasing activities such as buying services or products online, consuming content, etc. They catalyze the process of creating a brand identity. Therefore, one wrong choice in selecting typography could lead to hassle and severe problems for the brand later.&lt;/p&gt;

&lt;p&gt;While selecting typography for a website/application, a small mistake might lead to a domino effect. This is why it is important to avoid making unsure decisions. There are some common errors the designers tend to commit, such as misjudged text line lengths, wrongly paired typefaces, poor body font choices, bad color choices, and wrongly chosen line height between two lines of text. All of these should be given utmost attention as they are prominent parts of helping users read fluently.&lt;/p&gt;

&lt;p&gt;Improper spacing, instability, and rare alignments in the selection of font families, sizes, and colors can ruin the overall brand image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fape0vx23tktpwecev0ce.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fape0vx23tktpwecev0ce.png" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Are you using Playwright for automation testing? Run your &lt;a href="https://www.lambdatest.com/playwright-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Playwright test&lt;/a&gt; scripts instantly on 50+ browser/OS combinations using the LambdaTest cloud. Sign up for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS and Typography
&lt;/h2&gt;

&lt;p&gt;Ok, so far, we have covered almost all the fundamentals and concepts of topography. Now let’s move on to the intersection of design and development. Now we can turn our attention to what properties we have to manipulate and style fonts, specifically with CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Font Sizing
&lt;/h2&gt;

&lt;p&gt;Changing font size is something inevitable in a project. The font-size property in CSS is used to specify the height and size of the font. It affects the size of the text of an element. This property accepts values, percentages, and a handful of keyword values. We use different units to measure fonts in CSS. Those are mainly divided into two categories, ‘&lt;strong&gt;Absolute&lt;/strong&gt;’ and ‘&lt;strong&gt;Relative&lt;/strong&gt;.’&lt;/p&gt;

&lt;p&gt;The actual size of an element expressed in relative units depends on other parts (e.g., parent element, or size of the viewport, etc.) of the page, while the actual size of an element expressed in absolute units is always the same. And as you might expect, that difference is important because they serve different functions, depending on design needs. Px (pixels), em, rem, and percentage are mainly used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Font Size (specified in px)
&lt;/h3&gt;

&lt;p&gt;Below is an example of how you could specify the font sizes in absolute units (i.e., pixels).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="box"&amp;gt;A text with font size 20px &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   body{
        text-align:center;
      }

      .box{
        background: #EEEEEE;
        margin : 40px auto;
        width : 250px;
        font-size : 20px;
        padding: 40px 20px;
        border : 1px solid;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="box"&amp;gt;A text with font size 20px &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  text-align:center;
}

.box{
  background: #EEEEEE;
  margin : 40px auto;
  width : 250px;
  font-size : 20px;
  padding: 40px 20px;
  border : 1px solid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code sample, the font size of the text is set to 20 px. We used the ‘px,’ an absolute unit, but we should avoid using absolute units like px and instead use relative units like ‘em’ or ‘rem’ as much as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Playwright tutorial will guide you through the setup of the &lt;a href="https://www.lambdatest.com/blog/playwright-framework?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;playwright browser testing&lt;/a&gt; framework, which will enable you to write end-to-end tests for your future projects.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Example: Font Size (specified in rem)
&lt;/h3&gt;

&lt;p&gt;Let’s look at the same example above, but we will use the relative unit ‘rem’ this time. It is important to note that rem depends upon the size of the root element of the HTML (1 rem = 16px).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="box"&amp;gt;A text with font size 2 rem &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
        text-align:center;
      }

      .box{
        background: #EEEEEE;
        margin : 40px auto;
        width : 250px;
        font-size : 2rem;
        padding: 40px 20px;
        border : 1px solid;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p class="box"&amp;gt;A text with font size 2 rem &amp;lt;/p&amp;gt;
​
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  text-align:center;
}

.box{
  background: #EEEEEE;
  margin : 40px auto;
  width : 280px;
  font-size : 2rem;
  padding: 40px 20px;
  border : 1px solid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Online mobile &lt;a href="https://www.lambdatest.com/mobile-emulator-online?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;emulator online&lt;/a&gt; from LambdaTest allows you to seamlessly test your mobile applications, websites, and web apps on mobile browsers and mobile devices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Font Weight
&lt;/h2&gt;

&lt;p&gt;Font weight is the “value” placed on your font to determine how bold or light your text will appear. There are many “values” that you can use depending upon your requirement. The weights available depend on the ‘font-family’ that is currently set.&lt;/p&gt;

&lt;p&gt;Different weights are used for different purposes on our website. Designers mostly prefer bold/bolder weights for the heading and the sub-headings and normal (300–600) weights for the content.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the syntax:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Global values */
font-weight: inherit;
font-weight: initial;
font-weight: revert;
Font-weight: revert-layer;
font-weight: unset;

/* Keyword values */
font-weight: normal;
font-weight: bold;

/* Keyword values relative to the parent */
font-weight: lighter;
font-weight: bolder;

/* Numeric keyword values */
font-weight: 100;
font-weight: 200;
font-weight: 300;
font-weight: 400;// normal
font-weight: 500;
font-weight: 600;
font-weight: 700;// bold
font-weight: 800;
font-weight: 900;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The ‘font-weight’ property is specified using any one of the &lt;strong&gt;values&lt;/strong&gt; listed below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Normal&lt;/strong&gt;: Normal font weight. Same as 400&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bold:&lt;/strong&gt; Bold font weight. Same as 700&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lighter:&lt;/strong&gt; A relative font weight. Lighter than the parent element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bolder:&lt;/strong&gt; A relative font weight. Bolder than the parent element&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;h3&amp;gt;Font Weights&amp;lt;/h3&amp;gt;

    &amp;lt;div class="container"&amp;gt;
      &amp;lt;p&amp;gt;Text with the font-weight of parent.&amp;lt;/p&amp;gt;
      &amp;lt;p class="normal"&amp;gt;Text with the font-weight 'normal'&amp;lt;/p&amp;gt;
      &amp;lt;p class="bold"&amp;gt;Text with the font-weight 'bold'&amp;lt;/p&amp;gt;
      &amp;lt;p class="lighter"&amp;gt;Text with the font-weight 'lighter'&amp;lt;/p&amp;gt;
      &amp;lt;p class="bolder"&amp;gt;Text with the font-weight 'bolder'&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  body {
        text-align: center;
        font-weight: 600;
      }

      .container {
        font-size: 20px;
        background: #eeeeee;
        margin: 40px auto;
        width: 400px;
        padding: 40px 20px;
        border: 1px solid;
      }
      .normal {
        font-weight: normal;
      }
      .bold {
        font-weight: bold;
      }
      .lighter {
        font-weight: lighter;
      }
      .bolder {
        font-weight: bolder;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Font Weights&amp;lt;/h3&amp;gt;

&amp;lt;div class="container"&amp;gt;
  &amp;lt;p&amp;gt;Text with the font-weight of parent.&amp;lt;/p&amp;gt;
  &amp;lt;p class="normal"&amp;gt;Text with the font-weight 'normal'&amp;lt;/p&amp;gt;
  &amp;lt;p class="bold"&amp;gt;Text with the font-weight 'bold'&amp;lt;/p&amp;gt;
  &amp;lt;p class="ligter"&amp;gt;Text with the font-weight 'lighter'&amp;lt;/p&amp;gt;
  &amp;lt;p class="bolder"&amp;gt;Text with the font-weight 'bolder'&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  text-align: center;
  font-weight: 600;
}

.container {
  font-size: 20px;
  background: #eeeeee;
  margin: 40px auto;
  width: 400px;
  padding: 40px 20px;
  border: 1px solid;
}
.normal {
  font-weight: normal;
}
.bold {
  font-weight: bold;
}
.lighter {
  font-weight: lighter;
}
.bolder {
  font-weight: bolder;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code example, all the texts are given different classes concerning their different font weights. The text with the class ‘normal’ has a normal font weight (400). The text with the class of ‘bold’ has a font weight of bold (700).&lt;/p&gt;

&lt;p&gt;The text with the class of ‘lighter’ has a font weight of lighter, i.e., a relative unit. It makes the font lighter than the parent’s font weight. And the last text with a class of bolder (a relative unit) makes the font bolder than the parent’s font.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;New &lt;a href="https://www.lambdatest.com/blog/selenium-ide-what-is-it-why-is-it-must-for-every-qa/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium IDE&lt;/a&gt; supports cross browser testing and parallel tests for automation along with record and replay function. Here’s why you shouldn’t miss out on it!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Line Height
&lt;/h2&gt;

&lt;p&gt;Line height is one of the most important factors affecting readability. It’s controlled by the line-height property in CSS, best expressed as a unit-less number corresponding to multiple of the defined font size.&lt;/p&gt;

&lt;p&gt;When applied to a block-level element, the line-height property defines, as its name suggests. The line-height property uses the following units:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;px&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;em&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;%&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;unitless numbers (e.g., 1.5)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The unitless values act like percentages. So 150% is equal to 1.5. The purpose of the line height is to define a readable line spacing for your text. Because readability depends upon the text’s size, it is recommended to use a dynamic value relative to the text’s size.&lt;/p&gt;

&lt;p&gt;Using ‘px’ is not recommended because it defines a static value. The recommended method is to use &lt;strong&gt;unitless numbers&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
    line-height: 1.5;
   }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For body text, a line height of 1.4 or 1.5 times the size of the text is recommended.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For headings, a line height of 1.2 is recommended.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Line Height&amp;lt;/h4&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;p class='first'&amp;gt;An aim is a goal or objective to achieve in life. In order to succeed in life, one must have a goal. My aim in life is to be a teacher. Teaching is a noble and responsible profession. I have come to know that the ever-increasing misery and distress, are &amp;lt;/p&amp;gt;

      &amp;lt;p class='second'&amp;gt;An aim is a goal or objective to achieve in life. In order to succeed in life, one must have a goal. My aim in life is to be a teacher. Teaching is a noble and responsible profession. I have come to know that the ever-increasing misery and distress, are &amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  font: 15px Georgia, serif;
  text-align: center;
}

.container{
  text-align: left;
  background: #EEEEEE;
  padding: 20px 20px;
  border: 1px solid;
  margin: 30px auto;
  display: flex;
  width: 30rem;
  gap: 30px;
}

.first{
  line-height: 1.2;
}

.second{
  line-height:1.5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;h4&amp;gt;Line Height&amp;lt;/h4&amp;gt;
&amp;lt;div class="container"&amp;gt;
  &amp;lt;p class='first'&amp;gt;An aim is a goal or objective to achieve in life. In order to succeed in life, one must have a goal. My aim in life is to be a teacher. Teaching is a noble and responsible profession. I have come to know that the ever-increasing misery and distress, are &amp;lt;/p&amp;gt;

  &amp;lt;p class='second'&amp;gt;An aim is a goal or objective to achieve in life. In order to succeed in life, one must have a goal. My aim in life is to be a teacher. Teaching is a noble and responsible profession. I have come to know that the ever-increasing misery and distress, are &amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  font: 15px Georgia, serif;
  text-align: center;
}

.container{
  text-align: left;
  background: #EEEEEE;
  padding: 20px 20px;
  border: 1px solid;
  margin: 30px auto;
  display: flex;
  width: 30rem;
  gap: 30px;
}

.first{
  line-height: 1.2;
}

.second{
  line-height:1.5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see in the above code example, the left paragraph has a line height of 1.2, and the right side paragraph has a line height of 1.5. Line height plays a significant role in typography. So here are some guidelines to define a good line height:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Increase line height for thick fonts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increase line height when fonts are a dark color.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Increase line height for long-form content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Through this usability testing tutorial, you will learn how &lt;a href="https://www.lambdatest.com/learning-hub/usability-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;usability testing&lt;/a&gt; is a great way to discover unexpected bugs, find what is unnecessary or unused before going any further, and have unbiased opinions from an outsider.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Letter Spacing
&lt;/h2&gt;

&lt;p&gt;Letter spacing is one of the most important factors affecting readability. It is controlled by the CSS letter-spacing property. The letter-spacing property controls the space between each letter in a given element or block of text. Values supported by letter-spacing include font-relative values (em, rem), absolute values (px), and the normal property, which resets to the font’s default.&lt;/p&gt;

&lt;p&gt;Using font-relative values is recommended so that the letter-spacing increases or decreases appropriately when the font size is changed, either by design or by user behavior.&lt;/p&gt;

&lt;p&gt;In general, you only need to worry about the letter spacing for text elements that are particularly big or small because most fonts are spaced well at typical paragraph size.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
      letter-spacing: 1em;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The most important point to note when using letter-spacing is that the specified value does not change the default — it is added to the browser’s default spacing.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: letter-spacing also supports negative values, which will tighten the appearance of text rather than loosening it. Let’s have a look at the below code example.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Letter Spacing&amp;lt;/h3&amp;gt;
&amp;lt;div class="container"&amp;gt;
&amp;lt;p&amp;gt;A sentence with no additional spacing&amp;lt;/p&amp;gt;
&amp;lt;p class="loose"&amp;gt;A sentence with little loose spacing of &amp;lt;span&amp;gt;2px&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p class="tight"&amp;gt;A sentence with little tight spacing of &amp;lt;span&amp;gt;-1.5px&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  font: 15px Georgia, serif;
  text-align: center;
  }
  .loose {
  letter-spacing: 2px;
  }
  .tight {
  letter-spacing: -1.5px;
  }
  .container {
  font-size: 20px;
  background: #eeeeee;
  margin: 40px auto;
  width: 350px;
  padding: 30px 20px;
  border: 1px solid;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Letter Spacing&amp;lt;/h3&amp;gt;
&amp;lt;div class="container"&amp;gt;
  &amp;lt;p&amp;gt;A sentence with no additional spacing&amp;lt;/p&amp;gt;
  &amp;lt;p class="loose"&amp;gt;A sentence with little loose spacing of &amp;lt;span&amp;gt;2px&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
  &amp;lt;p class="tight"&amp;gt;A sentence with little tight spacing of &amp;lt;span&amp;gt;-1.5px&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  font: 15px Georgia, serif;
  text-align: center;
}
.loose {
  letter-spacing: 2px;
}
.tight {
  letter-spacing: -1.5px;
}
.container {
  font-size: 20px;
  background: #eeeeee;
  margin: 40px auto;
  width: 350px;
  padding: 30px 20px;
  border: 1px solid;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code example, the sentence with the class ‘loose’ has a letter-spacing of 2px, and the sentence with the class ‘tight’ has a letter-spacing of -1.5px. You can see how much difference a horizontal space can make in the CSS typography.&lt;/p&gt;

&lt;p&gt;Let’s take a look at letter-spacing with another example,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsjqmstjzu6o1xqvf42e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpsjqmstjzu6o1xqvf42e.png" width="703" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above image, the top one has no letter-spacing, whereas the second has a letter-spacing of 1px and the bottom one letter-spacing is -1px. It’s not a giant change, but I think it’s obvious which is easiest to read.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this Ad hoc testing tutorial, let’s deep dive into what &lt;a href="https://www.lambdatest.com/learning-hub/ad-hoc-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=learning_hub" rel="noopener noreferrer"&gt;ad hoc testing&lt;/a&gt; is, its advantages, disadvantages, types, characteristics, and their best practices.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Text Alignment
&lt;/h2&gt;

&lt;p&gt;The text-align property in CSS is used to specify the horizontal alignment of text in an element. It is used to set the alignment of the content horizontally inside a block element. It plays a major role in CSS typography because of its nature.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  p {
        text-align: center;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;These are the traditional values for text-align:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;left&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The default value. The content aligns along the left side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Left)&amp;lt;/h4&amp;gt;
  &amp;lt;p class='box'&amp;gt;The text is left aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: left;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 0;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Left)&amp;lt;/h4&amp;gt;
&amp;lt;p class='box'&amp;gt;The text is left aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
  font:15px Georgia, serif;
  text-align: center;
}
​
.box{
  text-align: left;
  border: 1px solid;
  width: 300px;
  margin : 20px auto;
  padding: 30px 0;
  background: #EEEEEE;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;right&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The content aligns along the right side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Right)&amp;lt;/h4&amp;gt;
  &amp;lt;p class='box'&amp;gt;The text is right aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: right;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 0;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Right)&amp;lt;/h4&amp;gt;
  &amp;lt;p class='box'&amp;gt;The text is right aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: right;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 0;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;center&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Content centers between left and right edges, and the white spacing on each line’s left and right sides should be equal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Center)&amp;lt;/h4&amp;gt;
  &amp;lt;p class='box'&amp;gt;The text is center aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: center;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 0;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (Center)&amp;lt;/h4&amp;gt;
  &amp;lt;p class='box'&amp;gt;The text is center aligned!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: center;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 0;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;justify&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Content spaces out so that as many blocks fit onto one line as possible, the first word on that line is along the left edge, and the last word is along the right edge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (justify)&amp;lt;/h4&amp;gt;
    &amp;lt;p class="box"&amp;gt;
      I'm justified. I fill the space exactly (except on the last line), even if
      I have to stretch a bit at times
    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  body {
        font: 15px Georgia, serif;
        text-align: center;
      }

      .box {
        text-align: justify;
        border: 1px solid;
        width: 300px;
        margin: 20px auto;
        padding: 30px 5px;
        background: #eeeeee;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (justify)&amp;lt;/h4&amp;gt;
&amp;lt;p class='box'&amp;gt;
  I'm justified. I fill the space exactly (except on the last line), even if I have to stretch a bit at times
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
    font:15px Georgia, serif;
    text-align: center;
  }

  .box{
    text-align: justify;
    border: 1px solid;
    width: 300px;
    margin : 20px auto;
    padding: 30px 5px;
    background: #EEEEEE;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;inherit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The value will be inherited from the parent element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;h4&amp;gt;Text Align (inherit)&amp;lt;/h4&amp;gt;
    &amp;lt;p class="box"&amp;gt;
      I inherit the alignment of my parent. In this case, that means left.
    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   body {
        font: 15px Georgia, serif;
      }
      h4 {
        text-align: center;
      }
      .box {
        text-align: inherit;
        border: 1px solid;
        width: 300px;
        margin: 20px auto;
        padding: 30px 5px;
        background: #eeeeee;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;Text Align (inherit)&amp;lt;/h4&amp;gt; 
&amp;lt;p class='box'&amp;gt;I inherit the alignment of my parent. In this case, that means left.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  font: 15px Georgia, serif;
}
h4{
  text-align: center;
}
.box {
  text-align: inherit;
  border: 1px solid;
  width: 300px;
  margin: 20px auto;
  padding: 30px 5px;
  background: #eeeeee;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;In this article, we look at what Regression testing is, its importance and types, and how to perform &lt;a href="https://www.lambdatest.com/blog/regression-testing-what-is-and-how-to-do-it/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;regression test&lt;/a&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pseudo Elements in CSS
&lt;/h2&gt;

&lt;p&gt;A pseudo-element in CSS is a keyword added to a selector that lets you style a specific part of the selected elements. For example, styling the first letter or line of an element.&lt;/p&gt;

&lt;p&gt;Pseudo-elements are like virtual elements that we can treat like regular HTML elements. They don’t exist in the document tree or DOM, which means we don’t type pseudo-elements in HTML but rather create them with CSS. Also, the double colon(::) and the single colon(:) difference is merely a visual distinction between CSS2 and CSS3 pseudo-elements. You are free to use either.&lt;/p&gt;

&lt;p&gt;In short, inserting content before or after the content of an element can be done using Pseudo Elements in CSS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;selector::pseudo-element {
         property: value;
       }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are many Pseudo Elements in CSS, but the ones which are most commonly used are,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;:: first-line Pseudo-element&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;:: first-letter Pseudo-element&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  First-Line Pseudo Element
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;::first-line Pseudo-element&lt;/strong&gt; applies styles to the first line of a block-level element. Note that the length of the first line depends on many factors, including the width of the element, the width of the document, and the font size of the text.&lt;/p&gt;

&lt;p&gt;Note that only a few properties are applied for first-line pseudo-element like font properties, color properties, background properties, word-spacing, letter-spacing, text-decoration, vertical-align, line-height, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;h3&amp;gt;First-Line Pseudo Element&amp;lt;/h3&amp;gt;
    &amp;lt;p class='box'&amp;gt;
      This is a paragraph using first-line pseudo-element &amp;lt;br /&amp;gt;
      to style first line of the paragraph. Content in the first line turns red
      and becomes bold.
    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
        background-color: whitesmoke;
        text-align: center;
      }

      .box {
        background: #eeeeee;
        margin: 20px auto;
        width: 400px;
        border: 1px solid;
        padding: 20px 10px;
      }
      p::first-line {
        color: Red;
        font-weight: bold;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;First-Line Pseudo Element&amp;lt;/h3&amp;gt; 
&amp;lt;p class='box'&amp;gt;
  This is a paragraph using first-line pseudo-element &amp;lt;br /&amp;gt;
  to style first line of the paragraph. Content in the first line turns red
  and becomes bold.
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  background-color: whitesmoke;
  text-align: center;
}

.box{
  background: #EEEEEE;
  margin: 20px auto;
  width: 400px;
  border: 1px solid;
  padding: 20px 10px;
}
p::first-line {
  color: Red;
  font-weight: bold;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code example, &lt;strong&gt;::first-line&lt;/strong&gt; pseudo-element for the&lt;/p&gt;

&lt;p&gt;tag is set with the red color, which makes the first line of the paragraph red.&lt;/p&gt;

&lt;h2&gt;
  
  
  First-Letter Pseudo Element
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;::first-letter Pseudo-element&lt;/strong&gt;&lt;br&gt;
applies styles to the first letter of the first line of a block-level element, but only when not preceded by other content (such as images).&lt;/p&gt;

&lt;p&gt;Note that only a few properties are applied for first-line pseudo-element like font properties, color properties, background properties, word-spacing, letter-spacing, text-decoration, vertical-align, line-height, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTML:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   &amp;lt;h3&amp;gt;First-Letter Pseudo Element&amp;lt;/h3&amp;gt;
    &amp;lt;p class='box'&amp;gt;
      This is a paragraph using first-letter pseudo-element &amp;lt;br /&amp;gt;
      to style first letter of the paragraph. Content in the first letter turns red
      and becomes bold.
    &amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;CSS :&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
        background-color: whitesmoke;
        text-align: center;
      }

      .box {
        background: #eeeeee;
        margin: 20px auto;
        width: 400px;
        border: 1px solid;
        padding: 20px 10px;
      }
      p::first-letter {
        color: Red;
        font-weight: bold;
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;First-Letter Pseudo Element&amp;lt;/h3&amp;gt;
&amp;lt;p class='box'&amp;gt;
  This is a paragraph using first-letter pseudo-element
  to style first letter of the paragraph. Content in the first letter turns red and becomes bold.
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;CSS:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  background-color: whitesmoke;
  text-align: center;
}

.box {
  background: #eeeeee;
  margin: 20px auto;
  width: 400px;
  border: 1px solid;
  padding: 20px 10px;
}
p::first-letter {
  color: Red;
  font-weight: bold;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In the above code example, &lt;strong&gt;::first-letter&lt;/strong&gt; pseudo element is used on the&lt;/p&gt;

&lt;p&gt;tag, which turns the first letter into bold and red.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automated testing&lt;/a&gt; for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Deep dive into Character Encoding
&lt;/h2&gt;

&lt;p&gt;If you use anything other than the most basic English text, people may not be able to read the content you create unless you say what ‘&lt;strong&gt;character encoding&lt;/strong&gt;’ you used. Not only does a lack of character encoding information spoil the readability of displayed text, but it may mean that your data cannot be found by a search engine.&lt;/p&gt;
&lt;h2&gt;
  
  
  So what’s a character encoding?
&lt;/h2&gt;

&lt;p&gt;Words and sentences in text are created from characters. Examples of characters include the Chinese ideograph ‘诶‘ or the Devanagari character &lt;strong&gt;‘ख’&lt;/strong&gt;. Characters needed for a specific purpose are grouped into a character set. The characters are stored in the computer as one or more &lt;strong&gt;bytes&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Basically, you can visualize this by assuming that all characters are stored in computers using a special code. A &lt;strong&gt;character encoding&lt;/strong&gt; provides the key to unlock (i.e., crack) the code. It is a set of mappings between the bytes in the computer and the characters in the character set. Without the key, the data looks like garbage.&lt;/p&gt;

&lt;p&gt;So when you input text using a keyboard or in some other way, the character encoding maps characters. You choose specific bytes in computer memory. Then, it reads the bytes back into characters to display the text.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to declare a Character Encoding?
&lt;/h2&gt;

&lt;p&gt;You should always specify the encoding used for an HTML page. If you don’t, you risk that characters in your content are incorrectly interpreted. This is not just an issue of human readability. Due to the increase in machines, they need to understand your data too.&lt;/p&gt;

&lt;p&gt;Declaring character encodings in HTML provides quick recommendations for everyone who just wants to be told what to do and more information for those who need it.&lt;/p&gt;

&lt;p&gt;Declaring character encoding in CSS provides information for CSS.&lt;/p&gt;
&lt;h2&gt;
  
  
  Byte-Order Mark (BOM)
&lt;/h2&gt;

&lt;p&gt;The byte-order mark or BOM is something you will come across when using a Unicode-based character encoding, such as UTF-8 and UTF-16. Most of the time, you will not have to worry about the byte-order mark in UTF-8.&lt;/p&gt;

&lt;p&gt;In HTML5, browsers are required to recognize the UTF-8 and use it to detect the encoding of the page, and recent versions of major browsers handle the BOM as expected when used for UTF-8 encoded pages.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Character Escapes
&lt;/h2&gt;

&lt;p&gt;Character escapes are a way of writing a character in markup using only ASCII code points. They are useful if you cannot type in the actual character or want to clearly show invisible characters.&lt;/p&gt;

&lt;p&gt;Using only ASCII characters, you can use a character escape to represent any character from the Unicode character set in HTML or CSS.&lt;/p&gt;
&lt;h2&gt;
  
  
  Character Encoding Best Practices
&lt;/h2&gt;

&lt;p&gt;In this tutorial on CSS typography, let’s look at some of the best practices of character encoding.&lt;/p&gt;

&lt;p&gt;Content is composed of a sequence of characters. Characters represent letters of the alphabet, punctuations, etc. But content is stored in a computer as a sequence of bytes, in numeric form. Sometimes to represent a single character, more than one byte is used. The way that the sequence of bytes is converted to character depends on what key is used to encode the text, and that key is called &lt;strong&gt;character coding&lt;/strong&gt;. Let’s have a look at some best practices to follow,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Always save your pages as UTF-8.&lt;/p&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Always declare the encoding of your document. Use the HTTP header if you can. You can use @charset to declare the encoding of your style sheet, but you only need to do so if your style sheet contains non-ASCII characters. Use the HTTP header if you can.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Try to avoid using the BOM (Byte-Order Mark) in UTF-8.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Using LT Browser to test CSS Typography and Encoding
&lt;/h2&gt;

&lt;p&gt;If you’re a web designer or front-end developer, chances are you’ve used the popular Android devices to check your site’s layout. We don’t really think about any other devices at all when we’re in the midst of a project. That is, until we come across a problem that only occurs in iPhone or Samsung (you know, like that one image that refuses to display properly).&lt;/p&gt;

&lt;p&gt;If you can’t figure out what’s going on with it in Android, your only recourse is to switch over and test it on another device. When it comes to testing the &lt;a href="https://www.lambdatest.com/lt-browser?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile view&lt;/a&gt; of CSS typography and encoding of your site, however, there’s a better way than switching back and forth between devices all day long: LT Browser from LambdaTest.&lt;/p&gt;

&lt;p&gt;LT Browser is a one-of-a-kind &lt;a href="https://www.lambdatest.com/mobile-friendly-test?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile-friendly testing tool&lt;/a&gt; with cutting-edge capabilities. It comes loaded with 50+ preloaded viewports for mobile, tablets, desktop, and laptops to simulate various resolutions and device orientations, along with advanced display and network controls to perform &lt;a href="https://www.lambdatest.com/learning-hub/responsive-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;responsive testing&lt;/a&gt; of your website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44zckzlsz3lecpfxx10l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F44zckzlsz3lecpfxx10l.png" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LT Browser is a complementary tool for web developers offered by LambdaTest platform. LambdaTest is a cloud-based &lt;a href="https://www.lambdatest.com/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cross browser testing&lt;/a&gt; solution that is the modern way to test your web experience. It allows you to automatically produce bug-free, responsive applications that work across 3000+ devices and browsers.&lt;/p&gt;

&lt;p&gt;By leveraging LambdaTest’s &lt;a href="https://www.lambdatest.com/virtual-browsers?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;online browsers&lt;/a&gt;, you can perform &lt;a href="https://www.lambdatest.com/feature?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;browser compatibility testing&lt;/a&gt; of your CSS typography and encoding and ensure they are working correctly on every major browsers and OS combinations.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/K1dlmU3QWWk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;You can also Subscribe to the &lt;a href="https://www.youtube.com/channel/UCCymWVaTozpEng_ep0mdUyw?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube Channel&lt;/a&gt; and stay updated with the latest tutorials around &lt;a href="https://www.lambdatest.com/automated-browser-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;automated browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec13_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Cypress automation&lt;/a&gt;, CI/CD, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  It’s a Wrap!
&lt;/h2&gt;

&lt;p&gt;CC typography and encoding are often overlooked, but they are crucial to user interface design. Mastering the skill of CSS typography will see you well on your way to becoming a fantastic UI designer and a better developer.&lt;/p&gt;

&lt;p&gt;In this tutorial on CSS typography and CSS encoding, we had a detailed discussion about typography and how we can use CSS to make it better by using some of the CSS properties like font-weight, font-size, line-height, etc. Still, this is not an exhaustive guide, but something I hope will encourage you to take control of CSS typography in your future projects.&lt;/p&gt;

&lt;p&gt;I hope you liked this article on CSS typography and CSS encoding. Feel free to share with your friends and other developers. Any retweets and or LinkedIn shares are always welcome.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy Styling!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>marketing</category>
      <category>contentwriting</category>
    </item>
    <item>
      <title>A Complete Guide To CSS Container Queries</title>
      <dc:creator>AmanMandal1</dc:creator>
      <pubDate>Fri, 09 Dec 2022 17:49:22 +0000</pubDate>
      <link>https://dev.to/testmuai/a-complete-guide-to-css-container-queries-2m4m</link>
      <guid>https://dev.to/testmuai/a-complete-guide-to-css-container-queries-2m4m</guid>
      <description>&lt;p&gt;In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., &lt;a href="https://m.facebook.com" rel="noopener noreferrer"&gt;https://m.facebook.com&lt;/a&gt;). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.&lt;/p&gt;

&lt;p&gt;But after a few years, in 2010, Ethan Marcotte introduced the concept of Responsive Design. &lt;a href="https://www.lambdatest.com/learning-hub/responsive-design?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Responsive Web Design&lt;/a&gt; is the idea that design and development should respond to the user’s behavior and environment based on the screen size, device, and orientation. And central to that idea was the availability of &lt;a href="https://www.lambdatest.com/blog/css-media-queries-for-responsive-design/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS Media Query&lt;/a&gt;, which allowed setting various layout rules depending on the size of the viewport.&lt;/p&gt;

&lt;p&gt;The responsive design opened up many more layout solutions with the help of Media Query. Frameworks like &lt;a href="https://www.lambdatest.com/blog/css-grid-vs-bootstrap/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Bootstrap&lt;/a&gt; rose in popularity due to providing responsive grid systems. As per W3Techs, Bootstrap is used by 19.3% of all websites, with a market share of 79.5%.&lt;/p&gt;

&lt;p&gt;Nowadays, component libraries (ReactJS) have gained popularity because of its &lt;strong&gt;‘build once, deploy anywhere’&lt;/strong&gt; nature. A component is built once and can be used anywhere in the layout to make complex interfaces more efficient. And those components come together to create a webpage.&lt;/p&gt;

&lt;p&gt;Currently, you can only change the webpage layout with respect to the viewport using Media Query. But when writing media queries for UI elements, we are trying to find a &lt;strong&gt;“magic”&lt;/strong&gt; viewport value for a breakpoint like &lt;strong&gt;320px — 480px&lt;/strong&gt; for mobile devices, &lt;strong&gt;481px — 768px&lt;/strong&gt; for tablets/iPads, &lt;strong&gt;769px — 1024px&lt;/strong&gt; for small laptops and &lt;strong&gt;1025px — 1200px&lt;/strong&gt; for big screen laptops/pc, so that the target element has minimum dimensions, and the layout doesn’t break. This value usually differs from the viewport dimension and leads to bugs when the inner container’s dimension or layout changes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F0%2ApEohGIFS1C55Hwj_.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2400%2F0%2ApEohGIFS1C55Hwj_.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is one of the issues that &lt;strong&gt;CSS Container Queries&lt;/strong&gt; attempt to fix. &lt;strong&gt;CSS Container Queries extend existing media query&lt;/strong&gt; functionality with queries that depend on the target element dimensions. And in this blog, we will dive deep into the concept of &lt;strong&gt;CSS Container Queries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Perform browser automation testing on the most powerful cloud infrastructure. Leverage LambdaTest &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;automation testing platform&lt;/a&gt; for faster, reliable and scalable experience on cloud.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with CSS Container Queries
&lt;/h2&gt;

&lt;p&gt;The most important thing to know about CSS Container Queries is that “containers” are the elements being queried, but rules within the CSS Container Queries affect only the descendants of the container. In other words, you may define the ‘body’ element, ‘ main’ element, or perhaps event list items. Then, CSS Container Queries will allow defining rules for how elements within those change across container sizes.&lt;/p&gt;

&lt;p&gt;CSS Container Queries are not as straightforward as regular media queries. You’ll have to add the &lt;strong&gt;container&lt;/strong&gt; property to the parent UI element to make CSS Container Queries work, but there’s a reason, and we’ll cover that next.&lt;/p&gt;

&lt;h2&gt;
  
  
  Browser Support
&lt;/h2&gt;

&lt;p&gt;CSS Container Queries are by default enabled in Chrome (the latest version). For smooth and better performance, you can install the latest browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A8dtMul1159GP4_zQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A8dtMul1159GP4_zQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;**Note:&lt;/em&gt;* If you are not using the above-recommended browser, the following CodePens might not work. So an image showcasing the intended working example will be provided alongside the CodePens demo.*&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Accelerate your release velocity with blazing fast &lt;a href="https://www.lambdatest.com/automation-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;test automation cloud&lt;/a&gt;!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Contain Property
&lt;/h2&gt;

&lt;p&gt;CSS contain property has been added to most modern browsers and has a decent 90% browser support when writing this article.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A-hy3ZGN-EtzkRQCz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2A-hy3ZGN-EtzkRQCz.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The contain property is mainly used for performance optimization by hinting to the browser which parts of the page can be treated as independent and won’t affect the other elements of the page. If a change occurs in a single element, the browser will re-render only that part instead of the whole page. With contain property values, we can specify which types of containment we want to use — layout, size, paint, content, or none.&lt;/p&gt;

&lt;p&gt;The level 3 draft specification adds the &lt;strong&gt;inline-size&lt;/strong&gt; and &lt;strong&gt;block-size&lt;/strong&gt; keywords to &lt;strong&gt;contain&lt;/strong&gt;. In addition, the draft specification proposes some new properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Container-type&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Defines an element as a &lt;strong&gt;query container&lt;/strong&gt;. Descendants can query aspects of its sizing, layout, and state.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Container-name&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Specifies a list of &lt;strong&gt;query container names&lt;/strong&gt; for &lt;strong&gt;@container&lt;/strong&gt; rules to filter which query containers are targeted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Container&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A shorthand property to set both &lt;strong&gt;container-type&lt;/strong&gt; and &lt;strong&gt;container-name&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Try an online &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;Selenium automation&lt;/a&gt; Grid to run your browser automation testing scripts. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Container-Type
&lt;/h2&gt;

&lt;p&gt;It assigns a query container to an element. Depending on the value, descendants can query aspects of its size, layout, style, and state of the object. This helps to make setting the &lt;strong&gt;contain&lt;/strong&gt; property easier with arguments that combine different properties.&lt;/p&gt;

&lt;p&gt;The container type property can have the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Size:&lt;/strong&gt; Creates a query container that supports dimensional queries on both the inline and block axis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Inline-size:&lt;/strong&gt; Creates a query container that supports dimensional queries on the inline axis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Block-size:&lt;/strong&gt; Creates a query container that supports dimensional queries on the block axis.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Style:&lt;/strong&gt; Allows for style queries by defining a query container.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;State:&lt;/strong&gt; Allows for state queries by defining a query container.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Size, Inline-size, and Block-size are also given layout, size, and style containment.&lt;/p&gt;

&lt;p&gt;But what does the CSS Contain property used for optimization have to do with CSS Container Queries? For CSS Container Queries to work, the browser must know if a change occurs in the element’s children layout. It should re-render only that component. The browser will know to apply the code in the container query to the matching component when the component is rendered or the dimension of the container changes.&lt;/p&gt;

&lt;p&gt;Let’s have a look at contain property with a small code example.&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper"&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;article class="card"&amp;gt;
        &amp;lt;header&amp;gt;
          &amp;lt;h3 class='header'&amp;gt;
            Order Pizza Anywhere &amp;amp; Anytime
          &amp;lt;/h3&amp;gt;
        &amp;lt;/header&amp;gt;

        &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/OzPVEvW.jpg" alt="a pizza"&amp;gt;&amp;lt;/div&amp;gt;

        &amp;lt;div class="content"&amp;gt;
          &amp;lt;p class='para'&amp;gt;Delicioussss Pizza at your doorstep!! All you have to do click the 'Order' button and enjoy your amazing pizza &amp;lt;/p&amp;gt;
          &amp;lt;button class='btn'&amp;gt;Order now&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;

      &amp;lt;/article&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS :&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
          box-sizing: border-box;
        }

        img {
          max-width: 100%;
          height: 100;
          display: block;
        }

        body {
          font: 1.2rem Roboto, sans-serif;
          background: whitesmoke;
          line-height: 1.5;
        }

        .wrapper {
          padding: 20px;
          display: grid;
          grid-template-columns: 2fr 1fr;
          gap: 20px;
        }

        .card {
          background: white;
          box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
          border-radius: 12px;
          display: grid;
          overflow: hidden;
          padding: 15px;
        }

        .card .image {
          border-radius: 10px;
        }

        .image &amp;gt; img {
          border-radius: 10px;
        }

        .card .content {
          padding: 10px;
        }

        .para {
          font-size: 14px;
        }

        .btn {
          cursor: pointer;
          color: black;
          background: lightgray;
          padding: 10px 20px;
          border-radius: 5px;
          border: none;
        }

        .btn:hover {
          background: gray;
          color: white;
        }

        .card h2 {
          margin: 0;
          padding: 10px;
        }

        .container {
          container-type: inline-size;
        }

        @container (min-width: 500px) {
          .card {
            grid-template-columns: 1fr 2fr;
            grid-template-rows: auto 1fr;
            align-items: start;
            column-gap: 20px;
          }

          .card h2 {
            padding: 0;
            margin: 0.5em 0 0 0;
          }

          .card header {
            grid-row: 1;
            grid-column: 2;
          }

          .card .image {
            grid-row: 1 / 3;
            grid-column: 1;
          }

          .card .content {
            grid-column: 2;
            grid-row: 2;
            padding: 0 20px 20px 0;
          }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As we can see in the above code block, we are not adding the ‘container’ property to a more distant parent like ‘wrapper’ and keeping the container as close to the affected element as possible.&lt;/p&gt;

&lt;p&gt;That is why we should correctly signal the browser about the change. Wrapping a distant parent element with a ‘container’ property can be counter-productive and negatively affect page performance. In worst-case scenarios of misusing the ‘container’ property, the layout may break, and the browser won’t render it correctly.&lt;/p&gt;

&lt;p&gt;That’s all for now about the ‘container’ property. Now let’s look at the CSS Container Queries and how they work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Automate &lt;a href="https://www.lambdatest.com/cypress-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=webpage" rel="noopener noreferrer"&gt;cypress testing&lt;/a&gt; and perform browser automation testing with LambdaTest. Our cloud infrastructure has 3000+ desktop &amp;amp; mobile environments. Try for free!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are CSS Container Queries?
&lt;/h2&gt;

&lt;p&gt;A Container (also called a Wrapper) is an element that contains another element(s). So in simple terms, CSS Container queries specify changes to an element in relation to its parent container or element rather than the entire viewport.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ag6861nsBzpdcLWp4xk0XnA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ag6861nsBzpdcLWp4xk0XnA.jpeg" alt="**(Desktop — 1084px)**"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU3rqfQeYngkfufgocrA4QQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AU3rqfQeYngkfufgocrA4QQ.png" alt="**(Mobile — 386px)**"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a component is placed within an item, it’s contained within it. That means we can query the width of its parent and modify the component based on that. CSS Container Queries enable developers to approach responsiveness from a component standpoint, where elements on a page are designed to be responsive as individual units. This means that regardless of where these elements are placed on the page, they will adjust based on the parent element’s size rather than the entire page’s size.&lt;/p&gt;

&lt;p&gt;After the container property has been added to the card element wrapper in the above code example, we can write a container query. We’ve added a container property to an element with a container class, so now we can include any of its child elements in a container query.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\    .container {
          container-type: inline-size;
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Just like a regular media query, we need to define a query using &lt;strong&gt;min-width&lt;/strong&gt; or &lt;strong&gt;max-width&lt;/strong&gt; properties and nest all selectors inside the block. However, we’ll use the &lt;strong&gt;@container&lt;/strong&gt; keyword instead of &lt;strong&gt;&lt;a class="mentioned-user" href="https://dev.to/media"&gt;@media&lt;/a&gt;&lt;/strong&gt; to define a container query.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; @container (min-width: 500px) {
          .card {
            grid-template-columns: 1fr 2fr;
            grid-template-rows: auto 1fr;
            align-items: start;
            column-gap: 20px;
          }

          .card h2 {
            padding: 0;
            margin: 0.5em 0 0 0;
          }

          .card header {
            grid-row: 1;
            grid-column: 2;
          }

          .card .image {
            grid-row: 1 / 3;
            grid-column: 1;
          }

          .card .content {
            grid-column: 2;
            grid-row: 2;
            padding: 0 20px 20px 0;
          }
        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper"&amp;gt;
  &amp;lt;div class="container"&amp;gt;
    &amp;lt;article class="card"&amp;gt;
      &amp;lt;header&amp;gt;
        &amp;lt;h3 class='header'&amp;gt;
          Order Pizza Anywhere
        &amp;lt;/h3&amp;gt;
      &amp;lt;/header&amp;gt;

      &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/F5W5bY6.jpg" alt="a pizza"&amp;gt;&amp;lt;/div&amp;gt;

      &amp;lt;div class="content"&amp;gt;
        &amp;lt;p class='para'&amp;gt;Delicioussss Pizza at your doorstep!! All you have to do click the 'Order' button and enjoy your amazing pizza &amp;lt;/p&amp;gt;
        &amp;lt;ul&amp;gt;
          &amp;lt;li&amp;gt;Loaded with Cheese&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;Rich in taste&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;50% off on first order&amp;lt;/li&amp;gt;
        &amp;lt;/ul&amp;gt;
        &amp;lt;button class='btn'&amp;gt;Order now&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;

    &amp;lt;/article&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: 100;
  display: block;
}

body {
  font: 1.2rem Roboto, sans-serif;
  background: whitesmoke;
  line-height: 1.5;
}

.header{
}

.wrapper {
  padding: 20px;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap:20px;
}

.card {
  background: white;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  border-radius: 12px;
  display: grid;
  overflow: hidden;
  padding: 15px;
}

.card .image {
/*   border: 10px solid #000; */
  border-radius: 10px;
}

.image &amp;gt; img{
  border-radius: 10px;
  height: 400px;
  object-fit:cover;
}

.card .content {
  padding: 10px;
}

.content &amp;gt; ul{
    display:none;
  }

.para{
  font-size: 14px;
}

.btn{
  cursor: pointer;
  color: black;
  background: lightgray;
  padding : 10px 20px;
  border-radius: 5px;
  border: none;   
}

.btn:hover{
  background: gray;
  color: white;
}

.card h2 {
  margin: 0;
  padding: 10px;
}

.container{
  container-type: inline-size;
}

@container (min-width: 500px) {
  .card {
    grid-template-columns: 1fr 2fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    column-gap: 20px;
  }

  .card h2 {
    padding: 0;
    margin: .5em 0 0 0;
  }

  .card header {
    grid-row: 1;
    grid-column: 2;
  }

  .card .image {
    grid-row: 1 / 2;
    grid-column: 1;
  }

  .card .content {
    grid-column: 2;
    grid-row: 1/2;
    padding: 60px 20px 20px 0;
  }

  .content &amp;gt; ul{
    display:flex;
    flex-direction:column;
    list-style:none;
    padding-left:0;
    font-size:14px;
    color: green;
    line-height:30px;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMq5Ba8znDPrv0uuFWMJ8Eg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AMq5Ba8znDPrv0uuFWMJ8Eg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AfcfyUF7OU-rU2xTE74EYYQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AfcfyUF7OU-rU2xTE74EYYQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS Container Queries provide a new and refreshing approach to responsiveness. However, it is by no means a replacement for media queries. Instead, consider it a cool new addition to the developer’s responsive toolbox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Cypress automation testing tutorial will help you learn the benefits of &lt;a href="https://www.lambdatest.com/blog/cypress-test-automation-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;cypress automation&lt;/a&gt;, and how to install Cypress and execute Cypress automation testing over scores of browsers and operating systems online.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What problems do CSS Container Queries solve?
&lt;/h2&gt;

&lt;p&gt;CSS Container Queries offer a unique solution for developers working on large-scale projects where different components make up different parts of the webpage. They allow components to modify their appearance to fit the context in which they’re put. This means that the components can be used repeatedly, making them reusable.&lt;/p&gt;

&lt;p&gt;Many websites have components that need to change their layout based on the container’s available width. This may not always be related to the viewport’s size but to where the component is placed in the layout. CSS Container Queries provide a solution for developers to change component style and layout depending on the available width of the container or parent element.&lt;/p&gt;

&lt;p&gt;Here’s a proper example so that we can see the power of container queries:&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper"&amp;gt;
    &amp;lt;div class="left"&amp;gt;
      &amp;lt;article class="card"&amp;gt;
        &amp;lt;header&amp;gt;
          &amp;lt;h2&amp;gt;Little Doggo&amp;lt;/h2&amp;gt;
        &amp;lt;/header&amp;gt;

        &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/0l8iHZD.jpg" alt="a little puppy in the grass"&amp;gt;&amp;lt;/div&amp;gt;

        &amp;lt;div class="content"&amp;gt;
          &amp;lt;p&amp;gt;A dog is a beautiful creature on the earth that consists of four legs and sharp teeth. The teeth of a dog are tough and bright, which helps in biting the flesh of the body. Dogs have an intelligent nature, which is why they help officers in catching thieves and strangers. They consist of a very loud barking nature..  &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;

      &amp;lt;/article&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class="right"&amp;gt;
    &amp;lt;article class="card"&amp;gt;
        &amp;lt;header&amp;gt;
          &amp;lt;h2&amp;gt;Little Doggo&amp;lt;/h2&amp;gt;
        &amp;lt;/header&amp;gt;

        &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/0l8iHZD.jpg" alt="a little puppy in the grass"&amp;gt;&amp;lt;/div&amp;gt;

        &amp;lt;div class="content"&amp;gt;
          &amp;lt;p&amp;gt;A dog is a beautiful creature on the earth that consists of four legs and sharp teeth. The teeth of a dog are tough and bright, which helps in biting the flesh of the body. Dogs have an intelligent nature, which is why they help officers in catching thieves and strangers. They consist of a very loud barking nature.. &amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;

      &amp;lt;/article&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS :&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  display: block;
}

body {
  font: 1em Roboto, sans-serif;
  background: whitesmoke;
}

.wrapper {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap:20px;
}

.card {
  background: white;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  border-radius: 12px;
  display: grid;
  overflow: hidden;
}

.card .image {
/*   border: 10px solid #000; */
  border-radius: 10px;
}

.card .content {
  padding: 10px;
}

.card h2 {
  margin: 0;
  padding: 10px;
}

/* make the two grid items a containment context */
.left,
.right{
  container-type: inline-size;
}

@container (min-width: 500px) {
  .card {
    grid-template-columns: 1fr 2fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    column-gap: 20px;
  }

  .card h2 {
    padding: 0;
    margin: .5em 0 0 0;
  }

  .card header {
    grid-row: 1;
    grid-column: 2;
  }

  .card .image {
    grid-row: 1 / 3;
    grid-column: 1;
  }

  .card .content {
    grid-column: 2;
    grid-row: 2;
    padding: 0 20px 20px 0;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper"&amp;gt;
  &amp;lt;div class="left"&amp;gt;
    &amp;lt;article class="card"&amp;gt;
      &amp;lt;header&amp;gt;
        &amp;lt;h2&amp;gt;Cross Browser Testing&amp;lt;/h2&amp;gt;
      &amp;lt;/header&amp;gt;

      &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/dV3ywkg.png"&amp;gt;&amp;lt;/div&amp;gt;

      &amp;lt;div class="content"&amp;gt;
        &amp;lt;p&amp;gt;Browser &amp;amp; app testing cloud to perform both exploratory and automated testing across 3000+ different browsers, real devices and operating systems. &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

    &amp;lt;/article&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="right"&amp;gt;
  &amp;lt;article class="card"&amp;gt;
      &amp;lt;header&amp;gt;
        &amp;lt;h2&amp;gt;Cross Browser Testing&amp;lt;/h2&amp;gt;
      &amp;lt;/header&amp;gt;

      &amp;lt;div class="image"&amp;gt;&amp;lt;img src="https://i.imgur.com/dV3ywkg.png"&amp;gt;&amp;lt;/div&amp;gt;

      &amp;lt;div class="content"&amp;gt;
        &amp;lt;p&amp;gt;Browser &amp;amp; app testing cloud to perform both exploratory and automated testing across 3000+ different browsers, real devices and operating systems. &amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;

    &amp;lt;/article&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
  height: 100%;
  display: block;
}

body {
  font: 1.2rem Roboto, sans-serif;
  background: whitesmoke;
  line-height: 1.5;
}

.wrapper {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap:20px;
}

.card {
  background: white;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  border-radius: 12px;
  display: grid;
  overflow: hidden;
  max-width:400px;
}

.card .image {
/*   border: 10px solid #000; */
  border-radius: 10px;
}

.image &amp;gt; img{
/*   object-fit:contain; */
}

.card .content {
  padding: 10px;
}

.card h2 {
  margin: 0;
  padding: 10px;
}

/* make the two grid items a containment context */
.left,
.right{
  container-type: inline-size;
}

/* the card is placed as a child of the two grid items, displaying as one or two columns  */
@container (min-width: 500px) {
  .card {
    grid-template-columns: 1fr 2fr;
    grid-template-rows: auto 1fr;
    align-items: start;
    column-gap: 20px;
  max-width:100%;

  }

  .card h2 {
    padding: 0;
    margin: .5em 0 0 0;
  }

  .card header {
    grid-row: 1;
    grid-column: 2;
  }

  .card .image {
    grid-row: 1 /3;
    grid-column: 1;
    height:100%;
/*     object-fit: cover; */
  }

  .card .content {
    grid-column: 2;
    grid-row: 2;
    padding: 0 20px 20px 0;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Note: View this example in Chrome Canary with container queries enabled.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For those who aren’t using Chrome canary, here are the output images at different container sizes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2728%2F1%2AuNfTmBCGYj-8Te5UKwjUKQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2728%2F1%2AuNfTmBCGYj-8Te5UKwjUKQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvuWPwrp8B0JfAcEGmRb1Ew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvuWPwrp8B0JfAcEGmRb1Ew.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaQAdmv_sEc4mF-7o9rAVVA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AaQAdmv_sEc4mF-7o9rAVVA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created a simple card that resizes and adapts to fit any layout and container in our example. Our one container has a width of ⅔ and the other one of ⅓. This means our card component will have a width of 1066px and 534px at a viewport width of 1600px.&lt;/p&gt;

&lt;p&gt;We want our container to look slightly different at different breakpoints depending on its available space while remaining responsive. We could do this with a media query, but to do that, we’d have to make changes regarding the viewports meta-information rather than the container itself. This means we must constantly watch for changes to the screen size and adjust our components according to that particular size.&lt;/p&gt;

&lt;p&gt;Although this might not seem like an issue, it could quickly lead to the use of too many media queries to target if we had multiple containers because we would need to make sure all elements on the page, not just the card component, are responsive.&lt;/p&gt;

&lt;p&gt;This is where &lt;strong&gt;CSS Container Queries&lt;/strong&gt; come into play. Let’s go over our above code example again and see how we can turn this into a container:&lt;/p&gt;

&lt;p&gt;We want our container to look slightly different at different breakpoints depending on its available space while remaining responsive. We could do this with a media query, but to do that, we’d have to make changes regarding the viewports meta-information rather than the container itself. This means we must constantly watch for changes to the screen size and adjust our components according to that particular size.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper"&amp;gt;
    &amp;lt;div class="left"&amp;gt;
      &amp;lt;article class="card"&amp;gt;
        &amp;lt;!-- Card Content --&amp;gt;
      &amp;lt;/article&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To query elements, we first need to make the parent element a container by setting the &lt;strong&gt;container&lt;/strong&gt; property on the parent element. The container property takes two values: &lt;strong&gt;container-type&lt;/strong&gt; and &lt;strong&gt;container-name&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Notice how the element with the &lt;strong&gt;.card&lt;/strong&gt; class is wrapped by a parent element? This would be our parent container, and our card would adjust its size, layout, and styles based on the meta information of this element.&lt;/p&gt;

&lt;p&gt;Let’s go ahead and make our element with the &lt;strong&gt;left&lt;/strong&gt; class a container, so its children elements can be queried based on its meta-information.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.left{
  container: inline-size;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We set the &lt;strong&gt;container property&lt;/strong&gt; to &lt;strong&gt;inline-size&lt;/strong&gt; because we want containment to happen on the inline axis.&lt;/p&gt;

&lt;p&gt;The container property and value are set on our &lt;strong&gt;.left&lt;/strong&gt; class, which automatically turns the container element into a queryable container. So now, we can change the card element whenever the size of our container element changes.&lt;/p&gt;

&lt;p&gt;We can change the style or layout of our card element at certain breakpoints. We can set these breakpoints similarly to how media queries breakpoints are set. You can learn more about it by going through our blog on &lt;a href="https://www.lambdatest.com/blog/how-to-use-css-breakpoints-for-responsive-design/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;CSS breakpoints&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s look at the breakpoints we put in the above example to see how CSS Container Queries handle changes based on our breakpoints and how CSS Container Queries compare to media queries.&lt;/p&gt;

&lt;p&gt;In our example, we started by building out how our card component would look when its parent container has the smallest width, which is any width less than 500px. We want it to look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ays6bwg8-HKNQ7FWmQxklIQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ays6bwg8-HKNQ7FWmQxklIQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This would be our starting point for our card component. Since its parent container is now a container that can be queried, we can go ahead and start making changes to the layout and style at different breakpoints depending on the current width of the parent container.&lt;/p&gt;

&lt;p&gt;We do that by setting breakpoints. Our breakpoint is when our parent container is at a min-width of &lt;strong&gt;500px (500px or greater)&lt;/strong&gt;, and we start defining a new look for our card container. Here we want our container to look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUYCeCIuWmH71QZYGrcWWHg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AUYCeCIuWmH71QZYGrcWWHg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Code Example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@container (min-width: 500px) {
    .card {
      grid-template-columns: 1fr 2fr;
      grid-template-rows: auto 1fr;
      align-items: start;
      column-gap: 20px;
    }

    .card h2 {
      padding: 0;
      margin: .5em 0 0 0;
    }

    .card header {
      grid-row: 1;
      grid-column: 2;
    }

    .card .image {
      grid-row: 1 / 3;
      grid-column: 1;
    }

    .card .content {
      grid-column: 2;
      grid-row: 2;
      padding: 0 20px 20px 0;
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If we want our card element to look slightly different at another breakpoint, we can simply follow the same process for every new breakpoint.&lt;/p&gt;

&lt;p&gt;CSS Container Queries enable us to create more robust and reusable UI components that can adapt to nearly any layout and container, as shown in the above two examples. This would’ve been a lot more difficult with media query because it relies on the information of the entire viewport.&lt;/p&gt;

&lt;p&gt;With container queries, the card component could be placed in a narrow or wide column on the webpage and still look good and responsive. Furthermore, if there is enough space in our container queries example, it displays as a two-column layout, otherwise, it has a block layout.&lt;/p&gt;

&lt;p&gt;In our example above, container queries helped us achieve this:-&lt;/p&gt;

&lt;p&gt;A block layout for smaller sections of the webpage:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACgIf_9HxS-c79xfuG2id5A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACgIf_9HxS-c79xfuG2id5A.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A two-column layout for when we have more space:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A13Wk2rrgKIIRoM543v4J8Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A13Wk2rrgKIIRoM543v4J8Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The examples above show the power of CSS Container Queries and how vital they are in the component-driven development world. Now that we have a basic understanding of CSS Container Queries and how they function, let’s look at a more detailed code example.&lt;/p&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="page-container"&amp;gt;
  &amp;lt;div class="card-container card-1" data-size="0"&amp;gt;
    &amp;lt;div class="card"&amp;gt;
      &amp;lt;figure&amp;gt;
        &amp;lt;img src="lamdatest.png" /&amp;gt;
      &amp;lt;/figure&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div class="meta"&amp;gt;
          &amp;lt;h2&amp;gt;Cloud Selenium Testing&amp;lt;/h2&amp;gt;
          &amp;lt;span class="subtitle"&amp;gt;A cross-browser testing platform&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="notes"&amp;gt;
          &amp;lt;p class="desc"&amp;gt;
            In this episode we narrow our focus on user-preference-based media
            queries, which enable you to create personalized experiences based
            on your users custom settings and needs.
          &amp;lt;/p&amp;gt;
          &amp;lt;div class="links"&amp;gt;
            &amp;lt;h3&amp;gt;Lists&amp;lt;/h3&amp;gt;
            &amp;lt;ul&amp;gt;
              &amp;lt;li&amp;gt;
                Selenium Testing →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/selenium-automation&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Cypress Testing →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/cypress-testing&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Hyper Execute&amp;lt;a href="#"
                  &amp;gt;https://www.lambdatest.com/hyperexecute&amp;lt;/a
                &amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Visual Regression Cloud
                &amp;lt;a href="#"
                  &amp;gt;https://www.lambdatest.com/smart-visual-ui-testing&amp;lt;/a
                &amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Automation Testing Cloud&amp;lt;a href="#"
                  &amp;gt;https://www.lambdatest.com/automation-testing&amp;lt;/a
                &amp;gt;
              &amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;button&amp;gt;Start Free Testing&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="card-container card-2" data-size="0"&amp;gt;
    &amp;lt;div class="card"&amp;gt;
      &amp;lt;figure&amp;gt;
        &amp;lt;img src="lamdatest.png" /&amp;gt;
      &amp;lt;/figure&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div class="meta"&amp;gt;
          &amp;lt;h2&amp;gt;Cloud Selenium Testing&amp;lt;/h2&amp;gt;
          &amp;lt;span class="subtitle"&amp;gt;A cross-browser testing cloud&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="notes"&amp;gt;
          &amp;lt;p class="desc"&amp;gt;
            LambdaTest is a cloud-based cross browser testing tool that allows
            you to perform cross browser testing for web applications across
            more than 2000 browsers, operating systems, and devices
          &amp;lt;/p&amp;gt;
          &amp;lt;div class="links"&amp;gt;
            &amp;lt;h3&amp;gt;Lists&amp;lt;/h3&amp;gt;
            &amp;lt;ul&amp;gt;
              &amp;lt;li&amp;gt;
                Selenium Testing →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/selenium-automation&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Cypress Testing →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/cypress-testing&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Hyper Execute →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/hyperexecute&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Visual Regression Cloud →
                &amp;lt;a href="#"
                  &amp;gt;https://www.lambdatest.com/smart-visual-ui-testing&amp;lt;/a
                &amp;gt;
              &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;
                Automation Testing Cloud →
                &amp;lt;a href="#"&amp;gt;https://www.lambdatest.com/automation-testing&amp;lt;/a&amp;gt;
              &amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;button&amp;gt;Start Free Testing&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  font-family: "Google Sans", system-ui, serif;
  line-height: 1.5;
  padding: 2rem 1rem;
  background: whitesmoke;
}

.page-container {
  display: grid;
  grid-template-columns: 35% 1fr;
  gap: 1rem;
}

img {
  width: 100%;
}

.card {
  display: grid;
  grid-template-columns: 40% auto;
  gap: 2rem;
  margin: 0 auto;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  padding: 1rem;
  border-radius: 7px;
}

.card-container:before {
  content: attr(data-size);
  position: absolute;
  padding: 4px;
  left: 0;
  right: 0;
  top: -1.4rem;
  width: 6ch;
  margin: 0 auto;
  text-align: center;
  display: inline-block;
  border-radius: 4px;
  background: black;
  color: white;
}

h2 {
  font-size: 2.5rem;
  font-weight: 400;
  line-height: 1;
}

h3 {
  font-size: 1.15rem;
  font-weight: 800;
  text-transform: uppercase;
  margin: 1rem 0 0.25rem;
  line-height: 1;
}

a {
  color: gray;
}

a:hover {
  color: black;
}

.subtitle {
  font-size: 1.2rem;
  line-height: 1.2;
  font-weight: 300;
  color: gray;
}

button {
  border: none;
  padding: 0.7rem;
  background: black;
  color: white;
  font-weight: 600;
  letter-spacing: 0.1rem;
  text-transform: uppercase;
  margin-top: 1rem;
}

/* Container Queries */

.card-container {
  container-type: inline-size;
}

@container (max-width: 850px) {
  .links {
    display: none;
  }

  .subtitle {
    font-size: 1.25rem;
  }

  h2 {
    font-size: 2.2rem;
  }
}

@container (max-width: 650px) {
  .desc {
    display: none;
  }

  h2 {
    font-size: 2rem;
  }

  .card {
    gap: 1rem;
  }
}

@container (max-width: 460px) {
  .card {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 0.5rem;
  }

  button {
    display: block;
    margin: 1rem auto 0;
  }
}

@container (max-width: 300px) {
  h2 {
    font-size: 1.5rem;
  }

  .subtitle {
    display: none;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;HTML:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="page-container"&amp;gt;
  &amp;lt;div class="card-container"&amp;gt;
    &amp;lt;div class="card"&amp;gt;
      &amp;lt;figure&amp;gt;
        &amp;lt;img src="https://i.imgur.com/2xiaL5l.png" /&amp;gt;
      &amp;lt;/figure&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div class="meta"&amp;gt;
          &amp;lt;h2&amp;gt;Cloud Selenium Testing&amp;lt;/h2&amp;gt;
          &amp;lt;span class="subtitle"&amp;gt;A cross-browser testing platform&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="notes"&amp;gt;
          &amp;lt;p class="desc"&amp;gt;In this episode we narrow our focus on user-preference-based media queries, which enable you to create personalized experiences based on your users custom settings and needs.&amp;lt;/p&amp;gt;
          &amp;lt;div class="links"&amp;gt;
            &amp;lt;h3&amp;gt;Features&amp;lt;/h3&amp;gt;
            &amp;lt;ul&amp;gt;
              &amp;lt;li&amp;gt;Selenium Testing &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Cypress Testing &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Hyper Execute &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Visual Regression Cloud &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Automation Testing Cloud &amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;button&amp;gt;Start Free Testing&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="card-container"&amp;gt;
    &amp;lt;div class="card"&amp;gt;
      &amp;lt;figure&amp;gt;
        &amp;lt;img src="https://i.imgur.com/2xiaL5l.png" /&amp;gt;
      &amp;lt;/figure&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div class="meta"&amp;gt;
          &amp;lt;h2&amp;gt;Cloud Selenium Testing&amp;lt;/h2&amp;gt;
          &amp;lt;span class="subtitle"&amp;gt;A cross-browser testing cloud&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div class="notes"&amp;gt;
          &amp;lt;p class="desc"&amp;gt; LambdaTest is a cloud-based cross browser testing tool that allows you to perform cross browser testing for web applications across more than 2000 browsers, operating systems, and devices&amp;lt;/p&amp;gt;
          &amp;lt;div class="links"&amp;gt;
            &amp;lt;h3&amp;gt;Features&amp;lt;/h3&amp;gt;
            &amp;lt;ul&amp;gt;
              &amp;lt;li&amp;gt;Selenium Testing &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Cypress Testing &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Hyper Execute &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Visual Regression Cloud &amp;lt;/li&amp;gt;
              &amp;lt;li&amp;gt;Automation Testing Cloud &amp;lt;/li&amp;gt;
            &amp;lt;/ul&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;button&amp;gt;Start Free Testing&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;CSS:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  font-family: 'Google Sans', system-ui, serif;
  line-height: 1.5;
  padding: 2rem 1rem;
  background: whitesmoke;
}

.page-container {
  display: grid;
  grid-template-columns: 35% 1fr;
  gap: 1rem;
}

img {
  width: 100%;
}

.card {
  display: grid;
  grid-template-columns: 40% auto;
  gap: 2rem;
  margin: 0 auto;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
  padding: 1rem;
  border-radius: 7px;
}

h2 {
  font-size: 2.5rem;
  font-weight: 400;
  line-height: 1;
}

h3 {
  font-size: 1.15rem;
  font-weight: 800;
  text-transform: uppercase;
  margin: 1rem 0 0.25rem;
  line-height: 1;
}

li {
  color: gray;
  cursor:pointer;
  letter-spacing:1px;
}

li:hover{
  color: black;
}

.subtitle {
  font-size: 1.2rem;
  line-height: 1.2;
  font-weight: 300;
  color: gray;
}

button {
  border: none;
  cursor:pointer;
  padding: 0.7rem;
  background: black;
  color: white;
  font-weight: 600;
  letter-spacing: 0.1rem;
  text-transform: uppercase;
  margin-top: 1rem;
}

button:hover{
  color: lightgray;
}

/* Container Queries */

.card-container {
  container-type: inline-size;
}

@container (max-width: 850px) {
  .links {
    display: none;
  }

  .subtitle {
    font-size: 1.25rem;
  }

  h2 {
    font-size: 2.2rem;
  }
}

@container (max-width: 650px) {
  .desc {
    display: none;
  }

  h2 {
    font-size: 2rem;
  }

  .card {
    gap: 1rem;
  }
}

@container (max-width: 460px) {
  .card {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 0.5rem;
  }

  button {
    display: block;
    margin: 1rem auto 0;
  }
}

@container (max-width: 300px) {
  h2 {
    font-size: 1.5rem;
  }

  .subtitle {
    display: none;
  }
}

strong {
  font-weight: 800;
}

i {
  font-style: italic;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We created two similar card components that can resize and adapt to fit in any container by using the CSS Container Queries. Now, we want our container to look slightly different at different breakpoints depending on its available space while remaining responsive. So as we can see in the above CSS code, we added 4 different breakpoints for four different layouts. Let’s have a look at them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For containers more than 850px:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACEOB3_NtkxmdWVHhurMQNw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ACEOB3_NtkxmdWVHhurMQNw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For containers less than 850px :&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4k7oJga9eOkOw8jrBOd1NQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A4k7oJga9eOkOw8jrBOd1NQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For containers less than 650px:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AujQGHCtzsgipV-ijx5VftA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AujQGHCtzsgipV-ijx5VftA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For containers less than 460px:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKtLN5N6unkXF2G82vvcgzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKtLN5N6unkXF2G82vvcgzg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For containers less than 300px:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKtLN5N6unkXF2G82vvcgzg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AKtLN5N6unkXF2G82vvcgzg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we’ve seen from the previous examples, CSS Container Queries are best used for highly reusable components with a layout that depends on the available container space and that can be used in various contexts and added to different containers on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;This Playwright tutorial will guide you through the setup of the &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;playwright automation&lt;/a&gt; framework, which will enable you to write end-to-end tests for your future projects.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to perform responsiveness testing of CSS Container Queries?
&lt;/h2&gt;

&lt;p&gt;It’s important to test your website on multiple screen sizes to ensure that it looks and behaves correctly on all of them.&lt;/p&gt;

&lt;p&gt;You can use a &lt;a href="https://www.lambdatest.com/mobile-friendly-test?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;mobile-friendly tester&lt;/a&gt; like &lt;a href="https://www.lambdatest.com/lt-browser?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LT Browser&lt;/a&gt; to test the responsiveness of your website across various pre-installed device viewports for Android, iOS, Windows, and macOS. It also offers other features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check mobile view of websites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare side-by-side view of the website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Generate performance reports of your websites powered by Google Lighthouse.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Get JavaScript Error reports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Test websites across different network conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;One-click bug logging and video recording of test sessions.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also try our new Chromium-based LT Browser 2.0, which has several new features and enhancements. &lt;a href="https://www.lambdatest.com/lt-browser-beta?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Try LT Browser 2.0 now&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To get started, check our support documentation — Getting started with LT Browser 2.0.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/K1dlmU3QWWk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Subscribe to the &lt;a href="https://www.youtube.com/c/LambdaTest?sub_confirmation=1?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;LambdaTest YouTube channel&lt;/a&gt; for tutorials around &lt;a href="https://www.lambdatest.com/selenium-automation?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Selenium testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/blog/playwright-framework/?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Playwright browser testing&lt;/a&gt;, &lt;a href="https://www.lambdatest.com/appium-mobile-testing?utm_source=devto&amp;amp;utm_medium=organic&amp;amp;utm_campaign=dec09_pk&amp;amp;utm_term=pk&amp;amp;utm_content=blog" rel="noopener noreferrer"&gt;Appium&lt;/a&gt;, and more.&lt;/p&gt;

&lt;h2&gt;
  
  
  It’s a Wrap!
&lt;/h2&gt;

&lt;p&gt;Once the spec has been implemented and widely supported by browsers, CSS Container Queries might become a game-changing feature. CSS Container Queries are an impending approach for moving beyond media queries tied to the viewport. For many years, developers have desired the ability to change an element’s width based on its container’s width. Therefore, it is only logical that elements have a way to be responsive based on their parent’s container meta information rather than the entire viewport.&lt;/p&gt;

&lt;p&gt;As it stands, CSS Container Queries are still in an early experimental phase, and the implementation is prone to change. We hope to see the final draft specifications for this feature soon so we can all start using it. Until then, keep experimenting !!&lt;/p&gt;

&lt;p&gt;Thank you for reading.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>programming</category>
      <category>css</category>
    </item>
  </channel>
</rss>
