CSS Comments

Posted in /   /  

CSS Comments
vinaykhatri

Vinay Khatri
Last updated on March 28, 2024

    Whether it’s a programming, markup, scripting or style sheet language everyone supports the concept of Comments. In every language we have comments which are used to provide information about the code itself. Comments are the bookmark messages that is not interpreted and compiled by any interpreter or compiler.

    CSS Comments

    They are used to explain the code, so you and other developer can easily understand what that specific block of code is supposed to do. Similarly, the CSS comment is used to explain the code. The browser neither parse the comment nor execute it.  The comment must be placed inside the <style> element. The comment message must be start with /* symbol and ends with */.

    Example

    <style>
    /* This code will colour each paragraph blue */
    p {
      color : blue;
    }
    </style>

    The comment can be put any where inside the <style> element.

    <style>
    p {
      color : blue;  /* This code will colour each paragraph blue */
    }
    </style>

    While using the comment make sure that you do not comment the code, if you comment the code the browser will not execute your code.

    <style>
        p {
            /*  color : blue;  This code will not execute*/
           }
    </style>

    The browser will not execute the above code because it is commented.

    Summary

    • Comments in code are used to explain the code.
    • In CSS comments start with /* and ends with */ symbol.
    • The browser does not read comments.
    • Comments can only be used with internal and external CSS.

    People are also reading:

    Leave a Comment on this Post

    0 Comments