HTML, or Hypertext Markup Language, is the standard language used for creating web pages. HTML attributes are a way to provide additional information about an element, such as its behavior, appearance, or content.
In this article, we'll explore HTML attributes and how they can be used to enhance your web pages.
HTML attributes are specified within the opening tag of an HTML element. They are made up of a name-value pair, where the name defines the attribute, and the value provides additional information about it. The syntax for defining an attribute is as follows:
Let's take a closer look at the various types of attributes that can be used in HTML.
1<div id="header"> 2 <h1>Welcome to our website!</h1> 3</div>
class attribute is used to specify one or more classes for an element. Classes are used to group elements with similar properties so that they can be styled together.
1<div class="container"> 2 <p>This is a paragraph of text.</p> 3</div>
style attribute is used to define inline styles for an element. This is useful for making small adjustments to the appearance of an element, such as changing the color or font size.
1<div style="background-color: blue; color: white;"> 2 <h2>This heading has a blue background and white text.</h2> 3</div>
href attribute is used to specify the URL of a hyperlink. This is used in conjunction with the
<a> tag to create clickable links on a web page.
1<a href="https://www.example.com">Visit our website</a>
In addition to the common attributes discussed above, you can also create your own custom attributes. These can be used to provide additional information about an element that is not covered by the standard set of attributes.
1<div data-employee-id="123"> 2 <p>This is a paragraph of text.</p> 3</div>