HTML Attributes

HTML attributes are used to provide additional information about HTML elements. Attribute has a name, followed by an equals sign(=) and a value placed inside the quotation marks("").

Syntax

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

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <a href="https://www.w3docs.com">Click here and go to the homepage.</a>
  </body>
</html>

In our example we use 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.

Result


Click and go to the homepage


Multiple Attributes

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

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

Syntax

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

The list of the mostly 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 or not. wrap=”hard”
width Defines the width of the element. width=”120”

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