/

HTML / CSS / JavaScript Tutorial

HTML Standard attribute: class

[this page | pdf | back links]

The HTML class attribute indicates one or more style class names (as per CSS) that apply to the element. If more than one class is to be applied to the same element then they should be separated by a space.

 

Valid attribute values include:

 

Value

Description

CSSclass

CSS style class

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
p {border: 1px solid black; width:200px}
.c1 {background-color: yellow;}
</style>
</head>
<body>
Set using HTML:<br>
<p class="c1">Text</p>

<br><br>Set using JavaScript:<br>
<p id="x1">Text</p>

<script>
document.getElementById("x1").className = "c1";
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Attributes


Desktop view | Switch to Mobile