In the previous section, we learned what HTML elements are and how we structure and use them in our HTML document. HTML Attributes are applied to the opening tag of an HTML element to modify the element behavior or add additional information or just to add a reference.
An attribute generally is applied as key value pairs on the starting tag, take a look below, you will see an an attribute
class with a value
lead. This is how an attribute with value is applied.
HTML Tags are generally classified into two categories:
- Tag-Specific Attributes
- Those attributes specific to tags for eg. the
srcattribute is specific to the
<img>tag and so on, such attributes are categorized as Tag-Specific which means it will only work with the tags it is intended for.
- Global Attributes
- These are the common set of attributes that are equally well applicable on almost all tags for eg.
titleetc. You can add them to any HTML tag you need and it will work on all of them. A detailed reference with implementation guide is available here HTML Global Attributes Reference
Some content attributes do not require a value, the presence of these attributes in itself represents a "true" value and their absence is same as "false" and this is why they are called Boolean attributes for eg. the
required attribute in a
<input type="text" required> is a boolean attribute that signifes the input field is required and user must input a value before the form can be submitted.