An HTML element can be added to an HTML class using the attribute class. This can then be used in CSS or JavaScript to manipulate the associated elements in the same way.
HiDrive Next online storage
Your data accessible anywhere and at any time
- Edit, share and store your files
- ISO certified European data centers
- High data security, GDPR compliant
What are HTML classes?
HTML classes are used in HTML to identify and group elements on a web page. class is one of the most important HTML attributes you should know if you are learning to use HTML. Classes allow developers to style or manipulate multiple elements without having to approach them individually.
Advice
The attribute class can be applied to any HTML element.
What are HTML classes for?
HTML classes are a standard tool for web developers. They are particularly essential in two areas of application:
- Styling elements with CSS : When you integrate CSS into your HTML, classes allow you to define styles that can be applied to multiple elements at once. This helps maintain the consistency of a website's design while making the CSS code modular.
- Manipulating Elements with JavaScript : Using HTML classes, programmers can easily select specific groups of elements and manipulate them with JavaScript code. This is particularly useful for dynamic interactions and user interfaces that need to react to user behavior.
HTML class syntax
The syntax for defining a class in HTML is very simple: add the attribute class to the element you want to assign to a class and specify the corresponding class name. In the code it looks like this:
Ce texte appartient à la classe appelée « Classe test ».
html
In the example above, the HTML paragraph has been assigned to the “Test Class” class.
Advice
The class names of HTML classes are case sensitive. This means that upper and lower case play a role here. In the example, “test class” and “test class” would be two different HTML classes.
This more detailed example shows the usefulness of classes:
Exemple d’utilisation de classes HTML
Ce texte est mis en évidence car il appartient à la classe nommée « highlight ».
Ce texte est mis en évidence et centré, car il appartient aux classes « highlight » et « center ».
html
In the code example above, the position and style of paragraphs and headings are influenced using the HTML classes used, by referencing the classes in the CSS code. Note that you access a HTML class in CSS by placing a point (.) in front of the class name.
Advice
A single HTML element can belong to several classes. These are simply listed one after the other, without separators.
What is the difference between HTML classes and HTML identifiers?
Besides the attribute classHTML also knows the HTML attribute id. Although the two attributes serve similar purposes, they should not be confused, as there are some central differences between them:
- Uniqueness: An identifier must be unique within an HTML document, so two elements can never have the same identifier. On the other hand, classes can be shared by several elements in the same document.
- SEO in CSS: to apply styles to classes in CSS, we use the point (
.) in front of the class name, while for IDs, we use the hash mark (#). - Specificity: IDs have higher specificity than classes. This means that if an ID and a class are both applied to the same HTML element and define conflicting styles, the ID's styles take precedence. From this point of view, the class can therefore be overwritten.
Domain name
Your domain in one click
- 1 Wildcard SSL certificate per contract
- Included Domain Connect feature for simplified DNS setup

