Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • id vs class attribute

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 325
    Comment on it

     There are many different kind of CSS selector which we can use to apply CSS style to an element in html. ID and Class are one of them. Here, in this this blog, I am going to explain you the basic difference between these two :-

    1. In the CSS, a class selector is a name preceded by a full stop (“.”) and an ID selector is a name preceded by a hash character (“#”).

    For example :-

    #id {
        background-color: #ccc;
        padding: 20px
    }
    
    .class {
        color: red;
        font-weight: bold;
    }

    2. ids are unique

    • Each element can have only one id
    • Each page can have only one element with that id

    Example

    <div id="widget1"></div>
    <div id="widget2"></div>
    <div id="widget3"></div>

    classes are NOT unique

    • You can use the same class on multiple elements.
    • You can use multiple classes on the same element.

    Example :-

    <div class="widget"></div>
    <div class="widget"></div>
    <div class="widget"></div>

    3.  Ids can be called through URL whereas classes cant be called through URL.

    For example :-

    In any browser if you want to go to a particular part just write the URL like http://your domain.com#home. Since this (#) id is unique so when you will run this URL in browser,the browser will go directly on home page.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: