HTML Tutorial
HTML - Introduction HTML - Basic HTML - Structure HTML - Element HTML - Attributes HTML - Headings HTML - Paragraphs HTML - Styles HTML - Formatting HTML - Phrase Tags HTML - Quotations HTML - Comments HTML - Colors HTML - CSS HTML - Links HTML - Images HTML - Tables HTML - List HTML - Inline elements HTML - Block elements HTML - Classes HTML - Id HTML - Javascript HTML - File Path HTML - Iframe HTML - Responsive HTML - Computer Code HTML - Head tag HTML - Events HTML - Url Encoding HTML - Entities HTML - Validation
HTML Forms
HTML - Forms HTML - Form Elements HTML - Input types HTML - Input Attributes
HTML5 - Introduction HTML5 - New Elements HTML5 - Semantics HTML5 - Style Guide
HTML Media
HTML - Video HTML - Audio HTML - Embed Multimedia
HTML Graphics
HTML - Canvas HTML - SVG
HTML - Geolocation HTML - Drag & drop HTML - Web Storage HTML - Web Workers
HTML References
HTML - Tag Reference HTML - Tag by Category HTML - Attributes HTML - Global Attributes HTML - Events HTML - Language Codes HTML - Country Codes HTML - URL Encoding HTTP Methods HTTP Status Codes <input> types

HTML class Attribute

The HTML class attribute makes it possible to define equal styles for elements with the same class name.

So, all HTML elements with the same class attribute will have the same format and style.

In this example we have three <div> elements that point to the same class name:

Run code

Class name is user-defined, that means you can choose any value for class attribute.

In CSS, to select elements with a specific class, write a period (.) character, followed by the name of the class.

Using class Attribute on Inline Elements

The HTML class attribute can be used on any HTML element.

This example uses class attribute on inline element:

Run code

Multiple Classes

HTML elements can have more than one class name, each class name must be separated by a space.

Run code

Using class Attribute in JavaScript

JavaScript can select elements with a specified class name by using the getElementsByClassName() method.

Run code