All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

CSS Id And Class Together

Last Updated : Mar 11, 2024

CSS Id And Class Together

In this tutorial we will show you the solution of css id and class together, as we know css used to style html elements, here we used internal style method to show demo.

We never had experience of using ‘id and class’ together to apply style on html elements but we can do that and also it will surely work same as set of multiple classes using same styles in css.

Here we defined ‘id and class’ together with some style and applied on para <p> tag of texts.

Step By Step Guide On CSS Id And Class Together :-

We can implement styles using three types (i.e inline,external or internal) Internal means we have to define our style within <style> tag in head block and inline means we have use style within element definition, external means we defined our css at separate file with .css extension we have to import by <link> tag within head block.

In our program we defined two <p> tags with some texts and attributes of class ‘txt1’ and id ‘txt’.

By using them we put’s ‘color and font-weight’ styles on it with respective values ‘blueviolet and bold’.

<!DOCTYPE html>
<html>
    <head>
        <title>ID CLASS TOGETHER</title>
        <style>
            .txt1,#txt{
                color: blueviolet;
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <p id="txt">here i show you what is word wrap and how it is useful for you.</p>
        <p class="txt1">here i show you what is word wrap and how it is useful for you.</p>
    </body>
</html>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is containing information about webpage and if you need any external file those links are declared here. <title> tag is used for set the webpage title.
  4. Within <style> tag we defined font-color to ‘blueviolet’ and font-weight to ‘bold’.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. Here two <p> tag we defined with attributes of ‘class,id’ respective values ‘txt1,txt’ and its styled by as we seen at point 4.
  8. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion we are able to know how to use class and id together in css. When we load our program we can see both para tag texts had same styles as we defined in style section.

So now we can understand how to use id and class together for styling html elements using css and it is not need any internet connection.

We can define any number of styles on ‘id,class’ together in style section and it is same as multiple classes with same styles.

I hope this tutorial on css id and class together helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪