HTML class Attribute

HTML class Attribute


Example

Use of the class attribute in an HTML document:

<html>
<head>
<style type="text/css">
h1.intro {color:blue;}
p.important {color:green;}
</style>
</head>

<body>
<h1 class="intro">Header 1</h1>
<p>A paragraph.</p>
<p class="important">Note that this is an important paragraph.</p>
</body>
</html>

Try it yourself »
(more examples at the bottom of this page)


Definition and Usage

The class attribute specifies a classname for an element.

The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by a JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.


Tips and Notes

Note: The class attribute cannot be used in the following HTML elements: base, head, html, meta, param, script, style, and title.

Tip: It is possible to assign multiple classes to one HTML element, e.g. <span class="left_menu important">. This allows you to combine several CSS classes for one HTML element.

Tip: Do NOT start a class name with a number! This is only supported in Internet Explorer.


Support

W3C: The "W3C" column indicates whether or not the attribute is defined in the W3C HTML/XHTML recommendation.

IEFirefoxOperaSafariW3C
YESYESYESYESYES


Syntax

<element class="value">

Attribute Values

ValueDescription
classnameSpecifies the name of a class for an element. To specify multiple classes for one element, separate the classnames with a space
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值