Attributes

So what are HTML attributes? Generally, HTML attributes provide additional information about an HTML element. It is always declared within an element's opening tag and always comes in name-and-value pairs.  For example, if we want to give our <html> tag a language attribute, then we can do it like this:

1<!DOCTYPE html>

2<html lang=”en-US”>

3<head>

4<title>Learning How to Put Attributes in HTML</title>

5</head>

6</html>

As you can see from the code above, we've incorporated a language attribute in our opening <html> tag. It should always come in a name-and-value format. In this case, “lang” is the name of the attribute, followed the equal sign which denotes designation, and then the value of the attribute which is “en-US”. We're basically declaring that our example HTML document will have an English language format.

Putting a language attribute in the opening <html> tag isn't necessarily required for every HTML document. However, accessibility applications like search engines and screen readers need this piece of information in order to index your web page or website successfully.

––––––––

Aside from the language attribute that we just discussed, there are still many other attributes that we can make use of in HTML. In order to keep this book as concise as possible, we won't be discussing all of them in-depth since there are so many of them that it would require a book on its own.  However, we will go ahead and discuss some of the more common attributes used in HTML. Here they are in no specific order: