Category: Basic

  • Unicode bidi Property

    CSS unicode-bidi property is used to control how bidirectional text is displayed in a document. Bidirectional text contains both left-to-right (LTR) and right-to-left (RTL) text.

    The unicode-bidi property allows developers to override the default behavior of the browser and ensure that bidirectional text is displayed correctly.

    Possible Values

    • normal − This is the default value, and it specifies that the text should be displayed according to the inherent direction of the text itself. In other words, it will use the direction of the characters in the text to determine how it should be displayed.
    • embed − This value is used to explicitly set the direction of the text within an element. When you set unicode-bidi to embed, you can also use the direction property to specify whether the text should be displayed left-to-right (ltr) or right-to-left (rtl).
    • bidi-override − This value creates an override for inline elements. In case of block elements, it overrides the browser’s bi-directional text algorithm and flows the text inside any inline children strictly according to the direction property.
    • isolate − This value isolates the element from its siblings.
    • isolate-override − This value uses the isolation behavior of the isolate keyword to the surrounding content and the override behavior of the bidi-override keyword to the inner content.
    • plaintext − Prevents bidirectional text (BIDI) algorithms from affecting the text inside the element.

    Applies to

    All positioned elements, but some of the values have no effect on non-inline elements.

    DOM Syntax

    object.style.unicodeBidi = "normal|embed|bidi-override|isolate|isolate-override|plaintext";
    

    CSS properties unicode-bidi and direction are the only properties that are not affected by the all shorthand property.

    This property is only used by Document Type Definition (DTD) designers. It is generally not recommended for web designers or similar authors to override it.

    CSS unicode-bidi – normal Value

    The following example demonstrates using unicode-bidi: normal, the text in its default order from right-to-left direction (RTL) −

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: normal;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - normal Value</h2><p>The following text is displayed in its default order from right-to-left direction.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – embed Value

    The following example demonstrates using unicode-bidi: embed. This value embeds the direction of the text within its surrounding content, and when the direction is set to rtl, the text is displayed in a right-to-left (RTL) direction −

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: embed;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - embed Value</h2><p>The following text is displayed in its default order from right-to-left direction.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – bidi-override Value

    The following example demonstrates using unicode-bidi: bidi-override. This value displays the text in reverse order, with the right most character displayed in the first position.−

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: bidi-override;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - bidi-override Value</h2><p>The following text is displayed in reverse order of the characters in right-to-left direction.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – isolate Value

    The following example demonstrates using unicode-bidi: isolate. This value is used to isolate a bidirectional text from its surrounding text. −

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: isolate;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - isolate Value</h2><p>The following text is displayed in its default order from right to left.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – isolate-override Value

    The following example demonstrates using unicode-bidi: isolate-override. This value is used to isolate and override the bidirectional text from its surrounding text −

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: isolate-override;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - isolate-override Value</h2><p>The following text is displayed in reverse order of the characters in right-to-left direction.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – plaintext Value

    The following example demonstrates using unicode-bidi: plaintext. This value treats the text as plain text without applying any bidirectional text algorithms. −

    <html><head><style>
       .box {
    
      direction: rtl;
      unicode-bidi: plaintext;
      color:red;
    } </style></head><body><h2>CSS unicode-bidi - plaintext Value</h2><p>The following text is displayed in its default order from left-to-right direction.</p><div class="box">
      Lorem Ipsum is simply dummy text of the printing and typesetting industry.  
    </div></body></html>

    CSS unicode-bidi – Related Properties

    Following is the list of CSS properties related to unicode-bidi:

    propertyvalue
    directionSets the direction of text in a block-level element.
  • writing mode Property

    CSS writing-mode property is used to specify the direction of text content flows within an element. It specifies whether text should be displayed horizontally or vertically.

    It is particularly useful for handling text orientation in non-Latin scripts, such as Chinese, Japanese, and Arabic, as well as for creating creative and visually interesting layouts.

    Possible Values

    • horizontal-tb − Default value. It sets the text to be laid out in horizontal writing mode, where text flows from left to right and top to bottom, as in most Western languages.
    • vertical-rl − This value specifies a vertical writing mode from right to left, commonly used for scripts like Chinese, Japanese, or Korean. Text flows vertically, starting from the right and proceeding to the left.
    • vertical-lr − Similar to vertical-rl, this value also represents a vertical writing mode, but the text flows from left to right, which is used in scripts like Mongolian.
    • sideways-rl − This value specifies vertical text flow from top to bottom, but positions the text from right to left. This value is used for vertical scripts like Mongolian or some forms of vertical Japanese text, where the characters are rotated 90 degrees clockwise and read from right to left.
    • sideways-lr − This value specifies vertical text flow from bottom to top, but positions the text from left to right.

    The lr, lr-tb, rl, tb, tb-lr, and tb-rl writing modes in CSS are deprecated, and should no longer be used. Instead, you should use the horizontal-tb or vertical-lr writing modes.

    The following table shows the deprecated writing modes and their equivalents:

    Deprecated ValueEquivalent Value
    lrhorizontal-tb
    rlhorizontal-tb
    lr-tbhorizontal-tb
    tbvertical-lr
    tb-lrvertical-lr
    tb-rlvertical-rl

    Applies to

    All the HTML elements except table row groups, table column groups, table rows, and table columns.

    DOM Syntax

    object.style.writingMode = "horizontal-tb|vertical-rl|vertical-lr|sideways-rl|sideways-lr";
    

    CSS writing-mode – horizontal-tb Value

    The following example demonstartes writing-mode property set to value horizontal-tb, where text is read from left to right and top to bottom −

    <html><head><style>
       .box {
    
      width: 250px;
      background-color: pink;
      writing-mode: horizontal-tb;
    } </style></head><body><h2>CSS writing-mode: horizontal-tb</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div></body></html>

    CSS writing-mode – vertical-rl Value

    The following example demonstartes writing-mode property set to value vertical-rl, where text is read from right to left and top to bottom −

    <html><head><style>
       .box {
    
      height: 250px;
      background-color: pink;
      writing-mode: vertical-rl;
    } </style></head><body><h2>CSS writing-mode: vertical-rl</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div></body></html>

    CSS writing-mode – vertical-lr Value

    The following example demonstartes that the writing-mode property set to value vertical-rl value, where text is read from left to right and top to bottom: −

    <html><head><style>
       .box {
    
      height: 250px;
      background-color: pink;
      writing-mode: vertical-lr;
    } </style></head><body><h2>CSS writing-mode: vertical-lr</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    </div></body></html>

    CSS writing-mode – sideways-rl Value

    The sideways-rl value is only supported by Firefox Browser.

    The following example demonstrates that writing-mode property set to value sideways-rl, where text read vertically from top to bottom, with characters arranged from right to left −

    <html><head><style>
       .box {
    
      height: 300px;
      background-color: pink;
      writing-mode: sideways-rl;
    } </style></head><body><h2>CSS writing-mode: sideways-rl - This example is only supported by Firefox Browser.</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    </div></body></html>

    CSS writing-mode – sideways-lr Value

    The sideways-lr value is only supported by Firefox Browser.

    The following example demonstrates that writing-mode property set to value sideways-lr, where text is read vertically from top to bottom, with characters arranged from left to right −

    <html><head><style>
       .box {
    
      height: 300px;
      background-color: pink;
      writing-mode: sideways-lr;
    } </style></head><body><h2>CSS writing-mode: sideways-lr - This example is only supported by Firefox Browser.</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    </div></body></html>

    CSS writing-mode – Asthetic Use (english Language)

    The values vertical-lr and vertical-rl can be used in English language for asthetics as demonstrated in the following example:

    <html><head><style>
       .mainbox{
    
      max-width: 750px;
      position: relative;
      padding-left: 80px;
      padding-top: 50px;
    } .box {
      height: 250px;
      background-color: pink;
    } h2 {
      padding-top: 70px;
      writing-mode: vertical-rl;
      position: absolute;
      left: 0;
      top: 0;
      line-height: 1;
      color: lightgreen;
      font-size: 40px;
      font-weight: 800;
    } </style></head><body><div class="mainbox"><h2>TutorialsPoint</h2><div class="box">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div></div></body></html>

    CSS writing-mode – Related Properties

    Following is the list of CSS properties related to writing-mode:

    propertyvalue
    displaySets the direction of text.
    unicode-bidiDetermine the behavior of bi-directional text in a document.
    text-orientationSets the orientation of the characters in a line.
    text-combine-uprightCombines multiple typographic character units into the space of a single typographic character unit.
  • clip Property

    CSS clip property is used to create a clipping region for an element, which defines the visible area of the element. Only the specified region will be visible and other regions will be hidden. The clip property only applies to elements with absolute or fixed positioning.

    Syntax

    clip: auto | shape | initial | inherit;

    Property Values

    ValueDescription
    autoNo clipping will be applied to the element. Default value.
    shapeIt clips an element. The only value possible is rect(top, right, bottom, left).
    initialIt sets the property to its default value.
    inheritIt inherits the property from the parent element.

    Examples of CSS Clip Property

    The following examples explain the clip property with different values.

    Clip Property with Auto Value

    To not clip an absolute or fixed positioned element, so that the entire element is visible, we use the auto value of the clip porperty. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .sample {
         width: 200px;
         background-color: lightblue;
         padding: 10px;
      }
      .clip-rect {
         position: absolute;
         width: 200px;
         background-color: lightblue;
         padding: 10px;
         clip: auto;
      }
    </style></head><body><h2> CSS clip property </h2><p>
      Original text:
    </p><div class="sample">
      TutorialsPoint is an educational platform offering 
      a vast array of tutorials and resources across various
      subjects, including programming, web development, and
      technology. It aims to provide accessible and 
      comprehensive learning materials for learners 
      of all levels globally.
    </div><br/><p>
      Clip: auto value
    </p><div class="clip-rect">
      TutorialsPoint is an educational platform offering
      a vast array of tutorials and resources across various
      subjects, including programming, web development,
      and technology. It aims to provide accessible and
      comprehensive learning materials for learners of
      all levels globally.
    </div><br/></body></html>

    Clip Property with rect() Value

    To clip portion of an absolute or fixed positioned element such that only the specified region is visible and remaining region is not visible, we use the rect(top, right, bottom, left) value of the clip property. The specified value will clip the element from the top and left edges. This is shown in the following example.

    Example

    <!DOCTYPE html><html><head><style>
    
      .sample {
         width: 200px;
         background-color: lightgreen;
         padding: 10px;
      }
      .clip-rect {
         position: absolute;
         width: 200px;
         background-color: lightgreen;
         padding: 10px;
         clip: rect(0px 170px 140px 0px);
      }
    </style></head><body><h2>
      CSS clip property
    </h2><p>
      Original text:
    </p><div class="sample">
      TutorialsPoint is an educational platform offering
      a vast array of tutorials and resources across various
      subjects, including programming, web development, 
      and technology. It aims to provide accessible and
      comprehensive learning materials for learners
      of all levels globally.
    </div><br/><p>
      Clip: rect(0px 170px 140px 0px) value
    </p><div class="clip-rect">
      TutorialsPoint is an educational platform
      offering a vast array of tutorials and resources
      across various subjects, including programming,
      web development, and technology. It aims to provide
      accessible and comprehensive learning materials
      for learners of all levels globally.
    </div><br/></body></html>

    Clip Property with Images

    The clip property can also be used with absolute or fixed positioned images. In the following example, auto and rect(top, right, bottom, left) values have been used with the image.

    Example

    <!DOCTYPE html><html><head><style>
    
      img {
         width: 300px;
         height: 200px;
      }
      .clip-auto {
         position: absolute;
         clip: auto;
      }
      .clip-rect {
         position: absolute;
         clip: rect(0px 140px 170px 0px);
      }
    </style></head><body><h2>
      CSS clip property&lt;/h2&gt;&lt;p&gt;Original image:&lt;/p&gt;&lt;img src="/css/images/white-flower.jpg" 
    /><p>
      clip: auto value
    </p><img src="/css/images/white-flower.jpg" /><p>
      clip: rect(0px 140px 170px 0px) value
    </p><img src="/css/images/white-flower.jpg" class="clip-rect" /></body></html>

    Note:

    • The clip property is deprecated and replaced by clip-path property
    • The clip property will not work if ‘overflow: visible’

  • Counters

    CSS counters act as variables that are used for numbering purposes. They can be increased or decreased by CSS rules. Counters enable us to modify the presentation of content depending on its position. For instance, you can use counters to automatically assign numbers to paragraphs, headings, and lists.

    body{counter-reset: section;}/* A simple counter when a new h2 element starts */h2::before{counter-increment: section;content:"Section "counter(section)": ";}

    CSS counters are a kind of variables maintained by CSS, which can be incremented, decremented, or reset at different points in your document. In this tutorial we will how to implemented and manage counter using CSS.

    Table of Contents

    • How to Implement Counters in CSS?
    • Automatic Numbering With Counters
    • Nesting Counters
    • Reversed counter
    • CSS Counter Related Properties

    How to Implement Counters in CSS?

    Counters can be used to create numbered lists, sections, or any other content that needs counting. Follow these steps to create counter in a webpage

    • Initialize the Counter: To start using a counter, you first need to initialize it using the counter-reset property.
    body{counter-reset: section;}

    This example initializes a counter named section with an initial value of 0. The counter is reset to 0 every time the body element appears.Increment the Counter: To increment the counter, use the counter-increment property.

    li::before{counter-increment: section;}

    This example increments the section counter every time an <li> element appears and displays the count before text.Display the Counter: To display the value of the counter, use the counters() function.

    li::before{content:counters(section,".")" ";}

    This example displays the value of the section counter followed by a period and a space before the content of the li element.

    Automatic Numbering With Counters

    Counters can be used to automatically number elements in a document. The following example demonstrates how to use counters to number list items.

    Example

    <!DOCTYPE html><html><head><style>
    
        body {
            counter-reset: section;
        }
        
        h2::before {
            counter-increment: section;
            content: "Section " counter(section) ": ";
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt; CSS Counters&lt;/h1&gt;&lt;h2&gt;SQL Tutorial&lt;/h2&gt;&lt;h2&gt;JavaScript Tutorial&lt;/h2&gt;&lt;h2&gt;Python Tutorial&lt;/h2&gt;&lt;h2&gt;HTML Tutorial&lt;/h2&gt;&lt;h2&gt;CSS Tutorial&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Nesting Counters

    Counters can be nested to create more complex numbering schemes. You can use the counters() function to display the value of a nested counter.

    Example

    <!DOCTYPE html><html><head><style>
    
        ol {
            counter-reset: section;
            list-style-type: none;
        }
        li::before {
            counter-increment: section;
            content: counters(section, ".") " ";
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;ol&gt;&lt;li&gt;Section 1
            &lt;ol&gt;&lt;li&gt;Subsection 1.1&lt;/li&gt;&lt;li&gt;Subsection 1.2&lt;/li&gt;&lt;li&gt;Subsection 1.3&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Section 2
            &lt;ol&gt;&lt;li&gt;Subsection 2.1&lt;/li&gt;&lt;li&gt;Subsection 2.2&lt;/li&gt;&lt;li&gt;Subsection 2.3&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Section 3
            &lt;ol&gt;&lt;li&gt;Subsection 3.1&lt;/li&gt;&lt;li&gt;Subsection 3.2&lt;/li&gt;&lt;li&gt;Subsection 3.3&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Reversed counter

    A reversed counter is a special kind of counter that counts backwards instead of forward. To create a reversed counter, name it with the reversed() function when you set it up with counter-reset.

    body{counter-reset:reversed(section);}

    The reversed counters start with a default initial value equal to the number of elements, not zero. This means that it can simply count down from the number of elements to one.

    The reversed counter property is supported only by Firefox browser

    Example

    Try this in Firefox browser

    <!DOCTYPE html><html><head><style>
    
        body {
            counter-reset: reversed(
            section);
        }
        p::before {
            counter-increment: section -1;
            content: "Section " counter(section) ": "; 
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;This is fourth paragraph&lt;/p&gt;&lt;p&gt;This is Third paragraph&lt;/p&gt;&lt;p&gt;This is second paragraph&lt;/p&gt;&lt;p&gt;This is first paragraph&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Following is the list of CSS properties of counter:

    PropertyDescriptionExample
    counter-resetIt is used to create or reset a counter.Try It
    counter-setIt is used to set a counter to a specific value.Try It
    counter-incrementIt is used to increment the counter value.Try It
    counter()It provides a string that represents the current value of named counter.Try It
    counters()It is used to work with nested counters.Try It
    @counter-stylesIt is used to create custom counter styles.Try It

  • Box Model

    CSS Box Model is a fundamental concept in CSS (Cascading Style Sheets) that define how an elements on a web page will be structured and displayed. It defines the properties and behavior of the contentpaddingborders, and margins of an element. Here in this article you will learn all about the CSS Box Model.

    What is CSS box model?

    The CSS box model is a container that used to structure the elements in a webpage so the element can be displayed visually good. It consists of four essential components content, padding, border, and margin, as shown in the following diagram.

    CSS Box Model

    CSS Box Model Components

    Lets understand each components in detail.

    • Content: This is the innermost part of the box and refers to the actual content of an element, such as text, images, or other media. You can set its size using the properties such as inline size and block-size, also known as width and height.
    • Padding: Represents the space between the content and the element’s border. It can be applied separately to each side of the element (top, right, bottom, and left). The size of this box is set using padding and other related properties.
    • Border: Defines a line or boundary around the padding and content of an element. The size, style and color of this box is set using border and other related properties.
    • Margin: Represents the space outside the border of an element. Like padding, margins can also be set separately for each side and are typically used to create space between elements on a webpage. The size of this box is set using margin and other related properties.

    The total space of an element occupies on the web page is the sum of its content width, padding, border, and margin. Understanding the CSS Box Model is crucial for designing and positioning elements on a webpage, as it allows you to control spacing, layout, and overall design.

    Types of Box-Model

    There are two types of box models as listed below.

    • Standard Box Model (Content-Box)
    • Alternative Box Model (Border-Box)

    Browsers use the standard box model, by default. Let us look into both the types of box models in the following sections.

    Standard CSS Box Model

    In standard box-model, height and width properties include only the content area of element. Padding, borders, and margins are added outside the content area.

    Consider the following styling box. Let us calculate the actual space taken by the box:

    .box {
       width: 300px;
       height: 100px;
       margin: 20px;
       padding: 15px;
       border: 5px solid green;
    }
    

    Standard Box Model Dimension Calculation

    The box area is only upto the margin, and thus margin area does not add up to the final space taken by the box.

    • Total width = 300(width) + 15(left padding) + 15(right padding) + 5(left border) + 5(right border) = 340px
    • Total height = 100(height) + 15(top padding) + 15(bottom padding) + 5(top border) + 5(bottom border) = 140px

    Standard Box-Model Example

    The following example shows how to define a standard box model in HTML. Here we given the default value content-box for box-sizing property. Here we can notice that width of padding and border is included in offsetWidth of the element.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .box {
            width: 300px;
            height: 100px;
            padding: 20px;
            border: 10px solid black;
            margin: 30px;
            /* This is the default value */
            box-sizing: content-box; 
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box" id="myBox"&gt;
      Total Width = 300 (content) + 20 (padding 
      left) + 20 (padding right) + 10 (border  
      left) + 10(border right) = 360 px
    &lt;/div&gt;&lt;p id="dis"&gt;&lt;/p&gt;&lt;script&gt;
        // Get the div element
        var box = document.getElementById('myBox');
        // Get total width of element
        var totalWidth = box.offsetWidth;
        document.getElementById('dis').innerText = 
        'Width of the div using offsetWidth property: ' 
        + totalWidth + 'px';
    &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Alternative Box Model

    In case of an alternative box model, the actual width of an element is the value of width that is passed to it and same is the case with height. There is no need of adding the padding and border while calculating the actual size of the box. In order to enable or turn on the alternative box model for an element, you need to set box-sizing: border-box on it.

    .box {
    
    box-sizing: border-box;
    }

    Let us consider the same dimensions of the box, as mentioned in standard box model example and calculate the actual space taken by the box:

    .box {
       width: 300px;
       height: 100px;
       margin: 20px;
       padding: 15px;
       border: 5px solid green;
       box-sizing: border-box;
    }
    

    Alternate Box Model Dimension Calculation

    The space taken by the box having dimensions listed up will be.

    • Total width = width = 300px
    • Total height = height = 100px

    Alternative Box-Model Example

    Here is an example alternative box models. Here we changed box-sizing property to border-box, hence total width of element not include width of border and padding.

    <!DOCTYPE html><html lang="en"><head><style>
    
        .box {
            width: 300px;
            height: 150px;
            padding: 20px;
            border: 10px solid black;
            margin: 30px;
            /* Change this property to see difference */
            box-sizing: border-box; 
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="box" id="myBox"&gt;
        Total Width = 300 px &lt;br&gt;
        Total Height = 150 px
        
    &lt;/div&gt;&lt;p id="dis"&gt;&lt;/p&gt;&lt;script&gt;
        // Get the div element
        var box = document.getElementById('myBox');
        // Get the total width of element
        var totalWidth = box.offsetWidth;
        document.getElementById('dis').innerText = 
        'Total width of div using offsetWidth property: ' 
        + totalWidth + 'px';
    &lt;/script&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Significance of Box-Model

    • Visual Representation: The box model allows developers to visualize and understand how elements are structured and how they will appear on the web page.
    • Layout and Positioning: The box model affects the layout and positioning of elements on a web page.
    • Size Calculations: The box model allows for precise calculations of element dimensions, including the width and height.
    • Control and Customization: With the box model, developers have fine-grained control over the appearance of elements.
    • Responsive Design: The box model plays a crucial role in responsive web design, where elements need to adapt and respond to different screen sizes and devices.

    Box Model & Inline Boxes

    The inline elements also have boxes around them. They also have margin, padding, borders, just like any other box.

    Example

    Here is an example where the box model around an inline element <p> is explained. Refer the diagram for detail description.

    <html><head><style>
       p {
    
      padding: 1em 2em;
      margin: 5px 10px;
      border: 5px solid red;
      width: 200px;
    } </style></head><body><h1>Box model</h1><p>Example for a box model.</p></body></html>

    Display as Inline Block

    An element with display: inline-block, respects the width and height values. And the values of padding, border, and margin will push away other elements, from the box.

    This feature is useful in cases where you want to give a larger area for an element, for example, a link <a>. You can use the display: inline-block on that element along with padding and other related properties.

    Example 1

    <html><head><style>
       a {
    
      padding: 1em 2em;
      margin: 5px 10px;
      border: 5px solid red;
      width: 50px;
      display: inline-block;
      background-color: beige;
      font-size: 1em;
    } </style></head><body><h1>display: inline-block</h1><a href="">First</a><a href="">Second</a><a href="">Third</a></body></html>

    Example 2

    Here in the code try to reduce the margin, padding, or border, to see the shift in the inline elements.

    <html><head><style>
       a {
    
      padding: 0em 2em;
      margin: 10px 10px;
      border: 5px solid red;
      width: 50px;
      background-color: beige;
      font-size: 1em;
    } </style></head><body><p>
      The display:inline-block respects the 
      width of the element. Here it is applied 
      on the link &lt;a href=""&gt;First&lt;/a&gt;. 
      As you change the value of padding, margin 
      or/and border you can see the change.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Block and Inline Boxes

    CSS offers different types of boxes that are either block boxes or inline boxes. The way these boxes are displayed, it can be of two types: inner display type and outer display type.

    Display of a box can be set using the display property of CSS, which have various values. Based on these values the display can be determined.

    Refer the diagram for a better understanding of 'display: block | inline'.

    CSS Box Model Display

    For detailed information and examples of display property in CSS, visit CSS display property article.

  • root Selector

    CSS :root selector in CSS is a pseudo-class that matches the root element of a document tree. In the case of HTML documents, :root represents the <html> element itself, so this selector is identical to the html element selector. But the :root selector have more specificity than HTML element selector.

    Syntax

    /* Selects the root element (<html>) of the document */:root{
    
    // css variable declarations or properties
    }

    Declaring Global CSS variables

    The main purpose of root selector is to declare variables in CSS. This will have a global access across every selectors in the stylesheet. Lets see an example.

    Example

    <!DOCTYPE html><html><head><style>
    
        :root {
        --main-color: blue;
        --secondary-color: white;
        }
        body {
        background-color: var(--main-color);
        }
        h1 {
        color: var(--secondary-color);
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Welcome to CSS Root Example&lt;/h1&gt;&lt;p&gt; 
        This is an example of using CSS root to define and use 
        custom CSS variables.
    &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Combinators

    CSS Combinators used to specify a particular relationship between selectors so that styling can be done based on relationship between elements in HTML structure. In other words combinators help you target elements based on their position and hierarchy within the HTML document.

    For example, with combinators you can style paragraph element that palaced immediately after div element.

    Table of Contents

    • Types of Combinators
    • CSS Descendant Combinator
    • CSS Child Combinator
    • CSS Adjacent Sibling Combinator
    • CSS General Sibling Combinator
    • Combining Multiple Combinators

    Types of Combinators

    There are four main types of CSS combinators:

    • Descendant Combinator (whitespace)
    • Child Combinator (>)
    • Adjacent sibling Combinator (+)
    • General sibling Combinator (~)

    Now we will look forward to example usage of each of this combinators, before that make sure that you are well versed with CSS selectors.

    CSS Descendant Combinator

    The descendant combinators are used to select elements that are nested within another element, regardless of how deeply they are nested. These are often represented by a single space (” “).

    For example you can target all <p> elements inside the <div> like this:

    div p{/* CSS styles for all p elements inside div */}

    Similarly we can combine any selectors like classes, id etc. In the following example we combined a element selector with class selector.

    Example

    <!DOCTYPE html><html><head><style>
    
        .parent {
            background-color: lightblue;
            padding: 20px;
        }
        .parent p {
            color: red;
            font-weight: bold;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="parent"&gt;&lt;h3&gt; This is h3 tag inside parent element &lt;/h3&gt;&lt;p&gt; This is a p tag inside parent element. &lt;/p&gt;&lt;p&gt; This is a p tag inside parent element. &lt;/p&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt; This is a p tag outside parent element. &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Child Combinator

    The child combinator (>) is used to select elements that are direct children of a specified element. It will not select elements that are further nested inside the child elements.

    For example, you can target all direct <p> child elements inside the <div> like this:

    div > p{/* CSS styles for all direct p children inside div */}

    Similarly, we can combine any selectors like classes, ids, etc. In the following example, we style all the p tags inside class parent.

    Example

    <!DOCTYPE html><html><head><style>
    
        .parent {
            background-color: lightgreen;
            padding: 20px;
        }
        .parent &gt; p {
            color: blue;
            font-weight: bold;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="parent"&gt;&lt;h3&gt; This is an h3 tag inside parent. &lt;/h3&gt;&lt;p&gt; This is a direct p tag inside  parent. &lt;/p&gt;&lt;p&gt; This is another direct p tag inside parent. &lt;/p&gt;&lt;div&gt;&lt;p&gt; 
                This is a p tag nested inside a div in parent element. 
            &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt; This is a p tag outside parent element. &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Adjacent Sibling Combinator

    The adjacent sibling combinator (+) is used to select an element that is immediately preceded by a specified element. It only affects the element that directly follows the specified element.

    For example, you can target a <p> element that immediately follows an <h3> element like this:

    h3 + p{/* CSS styles for the p element immediately following an h3 */}

    In the following example, we target the <p> element that comes right after an <h3> element.

    Example

    <!DOCTYPE html><html><head><style>
    
        .container {
            padding: 20px;
            background-color: lightyellow;
        }
        h3 + p {
            color: purple;
            font-style: italic;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;h3&gt;This is an h3 tag&lt;/h3&gt;&lt;p&gt; 
            This is a p tag that immediately follows the h3 tag.
        &lt;/p&gt;&lt;p&gt;
            This is another p tag, but it is not immediately 
            after the h3 tag.
        &lt;/p&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS General Sibling Combinator

    The general sibling combinator (~) is used to select all elements that are siblings of a specified element and appear after it in the HTML structure. It will select all matching siblings, not just the one immediately following.

    For example, you can target all <p> elements that follow an <h3> element like this:

    h3 ~ p{/* CSS styles for all p elements following an h3 element */}

    In the following example, we target all <p> elements that are siblings of an <h3> element and appear after it.

    Example

    <!DOCTYPE html><html><head><style>
    
        .container {
            padding: 20px;
            background-color: #f0f0f0;
        }
        h3 ~ p {
            color: darkorange;
            text-decoration: underline;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;p&gt; This is a p tag before h3 tag &lt;/p&gt;&lt;h3&gt; This is an h3 tag &lt;/h3&gt;&lt;p&gt; This is a p tag that follows the h3 tag. &lt;/p&gt;&lt;p&gt; This is another p tag that also follows the h3 tag. &lt;/p&gt;&lt;div&gt; This is a div tag. &lt;/div&gt;&lt;p&gt; This is a p tag after div tag &lt;/p&gt;&lt;/div&gt;&lt;p&gt; This is a p tag after h3 tag outside container. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Combining Multiple Combinators

    In CSS, you can combine multiple combinators to create more complex and specific selectors. By combining different combinators, you can target elements based on more complex relationships within the HTML structure.

    For example, you can target a <p> element that is a direct child of a <div> and immediately follows an <h3> element like this:

    div > h3 + p{/* CSS styles for p elements that are direct children of a div and 
    
      immediately follow an h3 element */}</pre>

    In the following example, we combine the child combinator with the adjacent sibling combinator to target anchor elements inside navigation menu.

    Example

    <!DOCTYPE html><html><head><style>
    
        nav {
            padding: 10px;
            background-color: #f0f0f0;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        ul &gt; li {
            display: inline-block;
            margin-right: 15px;
        }
        ul &gt; li + a {
            color: red;
            text-decoration: underline;
        }
        ul &gt; li &gt; a {
            color: blue;
            text-decoration: none;
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;nav&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#"&gt;About&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="#"&gt;Services&lt;/a&gt;&lt;/li&gt;&lt;a href="#"&gt;Contact&lt;/a&gt;&lt;/ul&gt;&lt;/nav&gt;&lt;/body&gt;&lt;/html&gt;</pre>
  • Atrribute Selector Property

    Description

    CSS attribute selectors allow you to select HTML elements based on the presence or value of one or more attributes. They are a powerful way to target specific elements in your HTML markup. Attribute selectors are enclosed in square brackets [] and can take various forms.

    The following sections discusses some common ways to use attribute selectors:

    CSS [attribute] Selector

    This selector selects elements that have specified attribute, regardless of its value.

    Syntax

    [attribute]
    

    Example

    Following is an example to select all the HTML elements with a “data-toggle” attribute

    <html><head><style>
       [data-toggle] {
    
      background: yellow;
      color: red;
    } </style></head><body><h2>CSS [attribute] Selector</h2><div data-toggle="yes">The div with data-toggle attribute</div><div>The div without data-toggle attribute</div><p data-toggle="no">A paragraph with data-toggle attribute</p><p>A paragraph without data-toggle attribute</p></body></html>

    CSS [attribute=”value”] Selector

    This selector selects elements that have a specific attribute with a specific value.

    Syntax

    [attribute="value"]
    

    Example

    This selector selects all elements with a ‘data-toggle’ attribute whose value is set to ‘yes’.

    <html><head><style>
       [data-toggle="yes"] {
    
      background: yellow;
      color: red;
    } </style></head><body><h2>CSS [attribute="value"] Selector</h2><div data-toggle="yes">The div with data-toggle attribute</div><div>The div without data-toggle attribute</div><p data-toggle="no">A paragraph with data-toggle attribute</p><p>A paragraph without data-toggle attribute</p></body></html>

    CSS [attribute*=”value”] Selector

    This selector selects elements that have a specific attribute with a value containing a specific substring.

    Syntax

    [attribute*="value"]
    

    Example

    This selector selects all the elements with a “src” attribute which contain a “images” in the path:

    <html><head><style>
       [src*="images"] {
    
      border: 2px dashed red;
    } </style></head><body><h2>CSS [attribute*="value"] Selector</h2><img alt="Logo" src = "/css/images/logo.png" /></body></html>

    CSS [attribute^=”value”] Selector

    This selector selects elements that have a specific attribute with a value that starts with a specific string.

    Syntax

    [attribute^="value"]  
    

    Example

    This selector selects all elements with a “href” attribute starting with “https://”

    <html><head><style>
       [href^="https"] {
    
      background: yellow;
      text-decoration:none;
      color:red;
    } </style></head><body><h2>CSS [attribute^="value"] Selector</h2><p><a href="https://www.tutorialspoint.com">HTTPS Link</a></p><p><a href="http://www.tutorialspoint.com">HTTP Link</a></p></body></html>

    CSS [attribute$=”value”] Selector

    This selector selects elements that have a specific attribute with a value that ends with a specific string.

    Syntax

    [attribute$="value"]  
    

    Example

    This selector selects all elements with a “src” attribute which ends with “.png”

    <html><head><style>
       [src$=".png"] {
    
      border: 2px dashed red;
    } </style></head><body><h2>CSS [attribute$="value"] Selector</h2><img alt="Logo" src = "/css/images/logo.png" /></body></html>

    CSS [attribute|=”value”] Selector

    This selector select elements that have a specific attribute with a value that begins with a specified substring followed by a hyphen (-). This selector is often used for selecting elements with language-specific attributes, such as lang attributes, which often use hyphens to denote language subcodes.

    Syntax

    [attribute|="value"]
    

    Example

    This selector selects all the elements with a “lang” attribute that starts with “en” followed by a hyphen:

    <html><head><style>
       [lang|="en"] {
    
      border: 2px dashed red;
    } </style></head><body><h2>CSS [attribute|="value"] Selector</h2><div lang="en">Hello World in English!</div><div lang="fr">Bonjour tout le monde en franais!</div><div lang="es">Hola Mundo en espaol!</div></body></html>

    CSS [attribute~=”value”] Selector

    This selector is used to select elements that have a specific attribute with a value containing a specified word. The word should be a standalone word, surrounded by spaces or at the beginning or end of the attribute value.

    Syntax

    [attribute~="value"]   
    

    Example

    This selector select all elements with a “class” attribute containing the word “beautifyme”

    <html><head><style>
       [class~="beautifyme"] {
       background-color:lightblue;
       border:2px solid red;
    
      }
    </style></head><body><h2>CSS [attribute|="value"] Selector</h2><div class="beautifyme">div with <b>beautifyme</b> class</div><div class="beautifyme1">div with <b>beautifyme1</b> class</div><div class="beautifyme-2">div with <b>beautifyme-2</b> class</div></body></html>

    Attribute Selectors For href Links

    You can style elements based on their href attribute is a common attribute used on <a> elements to specify the URL that the link points to.

    Here is an example −

    <html><head><style>
    
      ul {
      list-style: none;
    } a[href] {
      color: rgb(11, 11, 231);
    } a[href="css_backgrounds.htm"] {
      color: rgb(224, 152, 18);
    } a[href~="css_colors.htm"] {
      color: rgb(51, 255, 0);
    } a[href|="css_padding.htm"] {
      color: rgb(0, 255, 255);
    } a[href^="css_margins.htm"] {
      color: rgb(255, 0, 55);
    } a[href$="css_lists.htm"] {
      color: rgb(255, 230, 0);
    } a[href*="css_borders.htm"] {
      color: rgb(112, 108, 108);
    } </style></head><body><ul><li><a href="css_text.htm">CSS Text</a></li><li><a href=".htm">CSS Background</a></li><li><a href="css_colors.htm">CSS Color</a></li><li><a href="css_padding.htm">CSS Padding</a></li><li><a href="css_margins.htm">CSS Margin</a></li><li><a href="css_lists.htm">CSS List</a></li><li><a href="css_borders.htm">CSS Borders</a></li></ul></body></html>

    Attribute Selectors For Inputs

    Attribute selectors can be used to select input elements based on specific criteria, such as their type, name, value, or other attributes.

    Here is an example −

    <html><head><style>
       input {
    
      display: block;
      margin: 10px;
    } input[type] {
      border: 1px solid #e0dd29;
    } input[placeholder="Password"] {
      border: 1px solid #f00;
    } input[name|="emailid"] {
      background-color: rgb(236, 178, 233);
    } input[type~="submit"] {
      background-color: rgb(88, 241, 88);
      padding: 10px;
    } input[value^="But"] {
      background-color: rgb(236, 149, 68);
      padding: 10px;
    } input[type$="box"] {
      border-radius: 5px; 
      height: 50px;
      width: 20px;
    } input[type*="adi"] {
      height: 50px;
      width: 20px;
    } </style></head><body><input type="text" placeholder="Username"><input type="password" placeholder="Password"><input type="email" placeholder="Email" name="emailid"><input type="submit" placeholder="Submit"><input type="button" value="Button"><input type="checkbox" placeholder="Checkbox"><input type="radio" placeholder="Radio"></body></html>

    Attribute Selectors For Title

    To style elements based on the title attribute, you can use the CSS attribute selector title to style elements that have a title attribute containing a specific value.

    Here is an example −

    <html><head><style>
       span {
    
      display: block;
      margin: 10px;
      padding: 5px;
    } span[title] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(109, 177, 236);
    } span[title="CSS Background"] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(250, 163, 192);
    } span[title|="CSS Border"] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(245, 248, 79);
    } span[title^="Mar"] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(255, 147, 23);
    } span[title$="ght"] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(102, 201, 240);
    } span[title*="CSS Width"] {
      border: 2px solid rgb(231, 40, 40);
      background-color: rgb(191, 14, 235);
    } </style></head><body><span title="CSS Text">A text refers to a piece of written or printed information in the form of words or characters.</span><span title="CSS Background">You can set backgrounds of various HTML elements.</span><span title="CSS Border"> border property is used to create a border around an element.</span><span title="Margin">Setting up a margin around an HTML element.</span><span title="Height">The height property sets the height of an element's content area.</span><span title="CSS Width">The width sets the width of an element's content area.</span></body></html>

    Attribute Selectors For Language

    You can use the lang attribute to select elements based on their language. The lang attribute specifies the language of the text contained within an element.

    Here is an example −

    <html><head><style>
       div[lang] {
    
      color: red;
    } div[lang="fr"] {
      color: blue;
    } div[lang~="es"] {
      color: green;
    } div[lang|="de"] {
      color: orange;
    } div[lang^="it"] {
      color: purple;
    } div[lang$="ja"] {
      color: brown;
    } div[lang*="zh"] {
      color: teal;
    } </style></head><body><div lang="en">Hello World in English!</div><div lang="fr">Bonjour tout le monde en franais!</div><div lang="es">Hola Mundo en espaol!</div><div lang="ja"></div><div lang="de">Hallo Welt auf Deutsch!</div><div lang="it">Ciao Mondo in italiano!</div><div lang="zh"></div></body></html>

    CSS Multiple Attribute Selectors

    CSS multiple attribute selectors allow you to select elements based on multiple attribute values. It is use to target specific element that meet multiple criteria.

    Here is an example −

    <html><head><style>
       ul {
    
      list-style: none;
    } a[href] {
      color: rgb(231, 11, 194);
    } a[href="css_backgrounds.htm"][href$=".htm"] {
      color: rgb(224, 152, 18);
    } a[href="css_colors.htm"] {
      color: rgb(51, 255, 0);
    } </style></head><body><ul><li><a href="css_text.htm">CSS Text</a></li><li><a href="css_backgrounds.htm">CSS Background</a></li><li><a href="css_colors.htm">CSS Color</a></li></ul></body></html>

    CSS Attribute Selectors With Sibling Combinator

    CSS attribute selectors and sibling combinators can be used together to select specific elements based on their attributes and their relationship to other elements.

    • General sibling combinator (~) − This combinator selects all sibling elements that follow a specified element, but are not directly adjacent to it.Syntaxselector1 ~ selector2 { /* CSS styles */ }
    • Adjacent sibling combinator (+) − This combinator selects the element that is directly after the specified element.Syntaxselector1 + selector2 { /* CSS styles */ }

    The following example demonstrates that the adjacent sibling combinator (+) selects the paragraph immediately after the heading, while the general sibling combinator (~) selects <div> after the heading −

    <html><head><style>
       h2 + p { 
    
      font-weight: bold;
      color:blue;
    } h2 ~ div {
      color: red;
    } </style></head><body><h2>CSS Background</h2><p>You can set backgrounds of various HTML elements.</p><div><p>Contrary to popular belief, Lorem Ipsum is not simply random text.</p></div><p>There are many variations of passages of Lorem Ipsum available.</p></body></html>

  •  Loaders

    CSS loaders are animation effects that are used to indicate the loading process of a webpage. They are implemented using CSS and can be applied to various elements on a webpage, such as a spinner or a loading progress. CSS loaders are commonly used to improve user experience by visually indicating that content is being loaded or processed.

    Sample of CSS Loaders

    Here you can see what is a CSS loader, you may have seen these kind of loading animation on different websites.

    Table of Contents

    • How to Create a CSS Loader?
    • Basic CSS Loaders Example
    • Create Pulsing Dots Loader
    • Different Types of Spinning Loaders
    • CSS Loaders Using Gradient

    How to Create a CSS Loader?

    To create a loader in CSS, follow the below mentioned steps steps.

    • Create the HTML Structure: Define a outer div container element to hold loader content and a inner div container for loader.
    • Style the Loader Container: Set up the width and height for loader container. Use flex layout to center loader elements properly inside the container.
    • Style the Loader Element: Set up height and width for loader element also. Then set up border-top property as per width and color of loader you want. Also use border-radius value as 50% to ensure a circular loader.
    • Add Animation to the Loader: Use CSS animation to create the loading effect. With this you can add rotation effect, scaling, or any other transformations.
    • Define Keyframes for Animation: Specify the @keyframes rules for your animation, detailing how the loader should move or change over time.

    You may use various color combinations, shape, patterns and animation tricks for the loader. Play around with CSS properties to create your loader.

    You need to add the -webkit- prefix in your code for the browsers that do not support the animation and transform properties.

    Basic CSS Loaders Example

    Following example demonstrates creating a loader using CSS as discussed in the previous section:

    Example

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: flex;
            justify-content: space-around;
            align-items: center;
            height: 150px;
            background-color: #e0f7e9;
            margin: 0;
        }
    
        .loader {
            border: 8px solid #e0f7e9; 
            border-top: 8px solid #34a853; 
            border-radius: 50%;
            width: 60px;
            height: 60px;
            animation: innerFrame-spin 2s ease infinite;
        }
        
        @keyframes innerFrame-spin {
            0% {
                transform: rotate(0deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;div class="loader"&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Create Pulsing Dots Loader

    The pulsing dots loader is commonly used in windows operating system while booting the system. We made this using six div elements inside loader each set with different animation delay using pseudo-class :nth-child.

    Example

    <!DOCTYPE html><html><head><style>
    
        .container {
            display: flex;
            justify-content: space-around;
            align-items: center;
            height: 150px;
            background-color: #e0f7e9;
            margin: 0;
        }
        
        .PulsingDotsLoader {
            display: flex;
            justify-content: space-around;
            align-items: center;
            width: 60px;
            height: 60px;
        }
        
        .PulsingDotsLoader div {
            width: 12px;
            height: 12px;
            background-color: #34a853;
            border-radius: 50%;
            animation: PulsingDotsLoader-animation 1.2s ease infinite;
        }
        
        .PulsingDotsLoader div:nth-child(1) {
            animation-delay: -0.6s;
        }
        .PulsingDotsLoader div:nth-child(2) {
            animation-delay: -0.5s;
        }
        .PulsingDotsLoader div:nth-child(3) {
            animation-delay: -0.4s;
        }
        .PulsingDotsLoader div:nth-child(4) {
            animation-delay: -0.3s;
        }
        .PulsingDotsLoader div:nth-child(5) {
            animation-delay: -0.2s;
        }
        .PulsingDotsLoader div:nth-child(6) {
            animation-delay: -0.1s;
        }
        
        @keyframes PulsingDotsLoader-animation {
            0%, 100% {
                transform: scale(1);
                opacity: 1;
            }
            50% {
                transform: scale(0.5);
                opacity: 0.3;
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="container"&gt;&lt;div class="PulsingDotsLoader"&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Different Types of Spinning Loaders

    This example shows loaders with multiple spinners.

    • First loader have two spinners, because we defined properties border-top and border-bottom.
    • For second loader we defined border-right along with previously defined top and bottom values, this make three spinner loader.
    • And for third loader we defined four different values for border property, which makes a four spinner loader.

    Example

    <!DOCTYPE html><html><head><style>
    
        body {
            display: flex;
            justify-content: space-around;
            align-items: center;
            height: 200px;
            background-color: #f0f0f0; 
        }
        .loader {
            border: 16px solid #f3f3f3; /* Light grey */
            border-top: 16px solid blue;
            border-bottom: 16px solid blue;
            border-radius: 50%;
            width: 70px;
            height: 70px;
            animation: spin 2s linear infinite;
        }
        .second{
            border-right: 16px solid blue;
        }
        .third{
            border-top: 16px solid #ADD8E6;   /* Light Blue */
            border-right: 16px solid #87CEEB; /* Sky Blue */
            border-bottom: 16px solid #1E90FF; /* Dodger Blue */
            border-left: 16px solid #4169E1;  /* Royal Blue */
        }
        @keyframes spin {
            0% { 
                transform: rotate(0deg); 
            }
            100% { 
                transform: rotate(360deg); 
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="loader"&gt;&lt;/div&gt;&lt;div class="loader second"&gt;&lt;/div&gt;&lt;div class="loader third"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    CSS Loaders Using Gradient

    CSS gradients can be used to design custom colors for loader elements by creating a smooth transition between two or more colors.

    Example

    <html><head><style>
    
        .loader-test {
            width: 50px;
            height: 50px;
            padding: 10px;
            aspect-ratio: 1;
            border-radius: 50%;
            margin: 20px;       
            background: linear-gradient(10deg,#ccc,red);
            mask: conic-gradient(#0000,#000), 
                  linear-gradient(#000 0 0) 
                  content-box;
            -webkit-mask-composite: source-out;
            mask-composite: subtract;
            animation: load 1s linear infinite;
        }
        @keyframes load {
            to{
                transform: rotate(1turn)
            }
        }
    &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="loader-test"&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Comments

    In CSS, comments are useful in adding explanatory notes or annotations within your stylesheet that are not interpreted as styling instructions by the web browser.

    Syntax

    /* This is a comment */p{color: red;/* Set text color to red */}

    CSS comments are intended for the benefit of developers and are ignored by the browser when rendering a web page. They are useful in documentation, debugging, etc.

    Types of CSS Comments

    In CSS, there are two main ways to create comments:

    • Single-line Comments: Single-line comments are created using /* to start the comment and */ to end it.
    • Multi-line Comments: Multi-line comments allow you to add comments that span multiple lines. They are also enclosed within /* and */.
    /* Single line Comment *//*
    Comment
    which stretches
    over multiple
    lines
    */

    HTML And CSS comments

    In HTML tutorial we learned that, a command in HTML is defined between <!– and –> symbols.

    Syntax

    <html><head><style>
    
         /* This is a CSS Comment */
      &lt;/style&gt;&lt;/head&gt;&lt;body&gt;&lt;!-- This is an html comment format --&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Example

    Here is an example showing html comment and CSS comment format:

    <html><head><style>
    
      /* Target all div elements */
      div {
         background-color: red; /* Set background color */
         height: 50px; /* Set the height  */
         width: 200px; /* Set the width  */
         padding: 5px; /* Set the padding  */
         border: 5px solid black; /* Set the border  */
      }
    </style></head><body><!-- This is an html comment format --><div>
      Styles Applied
    </div></body></html>