This Page's Contents
What is an Element Attribute?
class
id
What is an Element Attribute?
- Attributes provide additional information, such as width, height, relationship and many more, about the HTML element that they are nested within.
- Attributes are always specified in the element start tag.
- All HTML elements can have attributes.
- The set of available attributes varies depending on the element.
class attribute
- You can style elements using CSS by adding the class attribute to an element.
- Elements can have multiple classes.
- If using more than 1 class for an element, then seperate the class names with a space, see Example class attribute.
- The following using class twice is wrong
<p class="example-colour" class="large">Your text ect. here</p>
- A class can be applied to multiple elements.
- In the CSS markup class names always start with a full stop . symbol.
In the 2 following examples the class names are: example-colour & large
Example class attribute using multiple classes
HTML
<p class="example-colour large">Your text ect. here</p>
When styling a class in CSS remember to start with the full stop . symbol
CSS
.example-colour { color: red;}
.large { font-size: large;}
Result
Your text ect. here
id attribute