HTML Attributes

HTML attributes are used to provide additional information about HTML element. Attribute has a name, followed by an equals sign and a value placed inside quotation marks.

It looks like

<tag attribute="value">Your Text</tag>

Let’s consider an example

<!DOCTYPE html>
<html>
  <body>
    <a href="https://www.w3docs.com">Click here and go to homepage.</a>
  </body>
</html>

In our example we used the <a> tag with href attribute. Between the quotation marks we wrote the address of the page, where we will go after clicking the link.

The result of the code is:

Click and go to homepage

Multiple Attributes

You can add more than one attribute to the HTML element. Be sure to add space between them.

It doesn’t matter in what sequence attributes are placed.

Example

<tag attribute1="value" attribute2="value">Your text</tag>

List of HTML Attributes

Below are the most frequently used HTML attributes.

Attribute Description Example
alt Defines an alternate text when the original element is not displayed alt=”HTML Attributes”
height Defines the height of the element height=”250”
href Defines the URL for a link href=”https://www.w3docs.com/”
hreflang Defines the language of the linked document hreflang="en"
id Defines a unique id for an HTML element id="example"
lang Defines the language of the document (used in <html> tag) <html lang="en-US">
rel Defines the relationship between target and linked documents rel="nofollow"
shape Defines the shape of the element shape="circle"
span Groups inline-elements in a document span="2"
src Defines the source of the element src=”image.jpg”
start Sets the start value of an ordered list (used in <ol> tag) <ol start="30">
style Sets CSS style of an HTML element (size, font, color, etc.) style="color:red;text-align:right"
target Defines where to open the link target=”_blank”
wrap Defines whether the text should be wrapped wrap=”hard”
width Specifies the width of the element width=”120”

See also our list of HTML Global Attributes that can be used with any HTML element.