YouTip LogoYouTip

Att Global Class

## HTML class Attribute The `class` attribute is one of the HTML Global Attributes. It is used to specify one or more class names for an HTML element. The `class` attribute is primarily used to point to a class in a style sheet (CSS). However, it can also be used by JavaScript (via the HTML DOM) to access and manipulate elements with the specified class. --- ## Browser Support The `class` attribute is a standard global attribute and is fully supported by all modern web browsers: * Google Chrome * Mozilla Firefox * Microsoft Edge / Internet Explorer * Safari * Opera --- ## Syntax ```html ``` ### Attribute Values | Value | Description | | :--- | :--- | | *classname* | Specifies the class name of the element.

**Naming Rules & Guidelines:**
β€’ Must begin with a letter (`a-z` or `A-Z`).
β€’ Can contain letters (`a-z`, `A-Z`), digits (`0-9`), hyphens (`-`), and underscores (`_`).
β€’ Class names are **case-sensitive** in HTML.
β€’ To assign multiple classes to a single element, separate the class names with a space (e.g., ``). | --- ## Code Examples ### Example 1: Basic Usage with CSS In this example, we assign classes to an `

` and a `

` element to apply specific styles defined in the `

Heading 1

This is a regular paragraph.

Note: This is an important paragraph styled with a class.

``` ### Example 2: Applying Multiple Classes An HTML element can have multiple class names. The class names must be separated by spaces. ```html YouTip - Multiple Classes Example
This box has a border, padding, and a yellow background.
This box has a border, padding, and red text.
``` ### Example 3: Using Classes in JavaScript You can use the `class` attribute in JavaScript to select elements or dynamically modify their styles. ```html

Hello World!

``` --- ## Differences Between HTML 4.01 and HTML5 * **HTML5:** The `class` attribute is a global attribute and can be used on **any** HTML element (it will validate on any element, though it may not always be semantically useful). * **HTML 4.01:** The `class` attribute could **not** be used with the following elements: ``, ``, ``, ``, ``, `