The opening tag of an element can have special snippets of information we can attach, called attributes.
Attributes have the
<p class="a-class">A paragraph of text</p>
You can also use single quotes, but using double quotes in HTML is a nice convention.
We can have many of them:
<p class="a-class" id="an-id">A paragraph of text</p>
and some attributes are boolean, meaning you only need the key, for example, see the
defer attribute on the
<script defer src="file.js"></script>
id attributes are two of the most common you will find used.
The difference between the two is that an
id is unique in the context of a web page; it cannot be duplicated.
Classes, on the other hand, can appear multiple times on multiple elements.
id is just one value.
class can hold multiple values, separated by a space:
<p class="a-class another-class"> A paragraph of text </p>
It’s common to use the dash
- to separate words in a class value, but it’s just a convention.
Those are just two of the possible attributes you can have.
Some attributes are only used for one tag, highly specialized. Others have more broad applications, like
class you just saw.
Lessons this unit:
|1:||Your first HTML page|
|9:||DEMO Using CodePen|
|10:||DEMO Using VS Code|