0

Hello, dear users of the PinkPen website. I hope you have a good day. In this session, we will talk about the id and class attributes of the Html tutorial series. At the beginning of this article, we want to learn how to create classes in HTML elements or tags. Then we talk about the id and then compare these two attributes.

Learn to use class Attribute in html

class Attribute html

put simply When we want to give all the tags a special feature, for example, the color of all of them is blue, we use the class. This attribute is widely used in the HyperText Markup Language programming language. The most important use is to separate batch tags and give them the same styles using CSS. Suppose we have several different Html tags, such as a photo, paragraph, heading, etc. We want to give them all the same style, for example, the font size of all of them should be 14. The best thing is to define a class, for example, called home. Then in the CSS file, we instruct the home class to have a text size of 14. You can use it with the following general formula.

<element class=”classname“>

The element that is in the first code is the same as HTML tags such as p, h 1, etc., and the class name must be replaced by the name of the selected class. We also use the following method to edit that class in CSS.

.ClassName

{

Enter the CSS commands here

}

Just put a dot before the class name, then easily customize its styles using CSS codes. You can practice in the online compiler of our website.

How to use the id attribute

How to use the id attribute

We use the id attribute when we want to assign a unique identifier to an element. Note that you cannot have multiple elements with the same id on an HTML page. To use this feature in HTML, we use the following syntax.

<element id=”idname“>

Simply enter your desired ID name instead of “idname“.

To edit this element in CSS, just put a # before its ID name and edit its style, as in the following instructions.

#ClassName

{

Enter the CSS commands here

}

Its main use is in JavaScript. Using the id attribute, you can easily access it in a JavaScript file and give it Js commands. The id attribute is supported in all Chrome, Firefox, Opera, Safari, and Internet Explorer browsers. There must be at least one character to name id, and space must not be used in its name.

Well, by now, you must have noticed that style and ID are different. Style is used to use and edit the HTML element group, and ID is used to edit and select a unique element. Also, more style is used to edit the css elements and more IDs are used to command the JavaScript code. Well, thanks to the dear Pink Pan users who were with us until the end of this article. This training session is also over, if you have any questions, be sure to ask in the comments so that our experts can answer them.

moji

moji

I am a computer engineering student, I have been working in SEO and WordPress for almost 8 years and I also have programming skills.

Leave a Reply

asdas

Copyright © 2019 pinkpen.net