The most common HTML attributes in an overview

HTML attributes store additional information in an HTML tag. They are simply added to the code. There are several other individual attributes in addition to universal, event, and data attributes.

What are HTML attributes used for?

HTML attributes are used to store additional information about elements in an HTML tag. They consist of a name and a value. The HTML attributes are located in the opening tag and are case insensitive. Although their values do not necessarily have to be written in inverted commas, this style is still recommended to avoid errors. The examples below illustrate how HTML attributes are included in the code:

<element attribute name="attribute value"/>

The <a> tag and the attribute href are required to include a link on a website. This looks like this:

<!DOCTYPE html>
<title>sample title</title>.
<a href="">this link will take you to the example site.</a>

Read our detailed article on a href for more on internal and external linking with HTML and its attributes.

What HTML attributes are there?

There are several different HTML attributes, although some options are no longer usable since HTML5 was introduced. The HTML attributes are divided into five different groups:

  • Classic universal attributes can be used in almost all elements and keep a constant role. However, they have no effect for some elements.
  • Specific attributes affect individual elements and define their parameters.
  • Attributes that apply since the introduction of HTML5 can partly create new options or replace older HTML attributes.
  • Event attributes trigger a defined event for an element when users perform a certain action.
  • Data attributes may contain information which is not recognisable to users.

Classic Universal Attributes

Classic universal attributes are allowed in most HTML tags. The examples below are the most common:

HTML attributes




Identifies a HTML element.



Assigns an element to one or more classes.



Defines the style of an HTML element and can determine the colour, font, font size, etc.

style="color: blue; font-size: 2em"


Contains additional information about the content of an element; this is displayed in a separate window when the mouse hovers over the element.



Determines the language of a document.

<html lang="en">


Defines the text’s running direction from left to right or vice versa.

<html dir="ltr"> example</html>

Specific HTML attributes

There are several specific HTML attributes for defining individual elements. The examples below are the most common ones:

HTML attributes




Displays an alternative text if an image cannot be loaded or displayed.

<img src="" alt="Red sports car at a traffic light.">


Sets the height of an element in px.

<img alt="the red car" height="220">


Sets the width of an element in px.

<img alt="the red car" width="220">


Defines the URL for a link.

<a href="" title="Learn more">


Sets the language of the linked document.

<a href="" lang="en" hreflang="en">Information in English</a>


Determines where a link should be opened.

<a href="https://www." target="_blank">


Defines the relationship between the target and the linked documents.

<a rel="nofollow" href="https://www.">sample site</a>


Defines the origin of an element.

<img src="" alt="the red car>


Ensures that specific media content is played automatically; however most browsers can override this setting.

<video autoplay>


Sets a preview image when you embed video into HTML.

<video controls poster="preview.png">

New attributes since HTML5

There are several HTML attributes which have been added since HTML5 and HTML 5.1 were introduced. These include the following:

HTML attributes




Defines whether the content of an element may be edited; the possible values are true and false.

<p contenteditable="false">


Universal attribute which can hide an element.

<p hidden>

This text is hidden



Defines whether an element is copied, linked or moved during drag and drop.

<p dropzone="move">


Universal attribute which defines whether the content of an element can be dragged and dropped.

<p draggable="false">


Specifies how external media is loaded; the allowed values are auto, eager, and lazy.

<img src="" alt="the red car" loading="lazy"


Specifies whether spell checking can be enabled; allowed values are true and false.

<p contenteditable="true" spellcheck="false">

Event attributes

There are many different HTML attributes which trigger an event in a browser. Therefore, the following HTML attributes are only a small selection of the different events which can be triggered with JavaScript in HTML.

HTML attributes




Triggers an event in JavaScript with a mouse click.

<button onclick="samplefunction ( )">click here</button>


Triggered when the element is scrolled.

<div onscroll="examplefunction ( )">


Triggered when a button is pressed.

<input type="text" onkeydown=example function ( ) ">


Triggers a JavaScript as soon as a search is entered in the search form.

<input type="search" onsearch="examplefunction ( )">


Executes a JavaScript in the event of an error.

<img src="" onerror="examplefunction ( ) ">


Triggered when a text is copied.

<input type="text" oncopy="examplefunction ( ) " value="copy this text">


Triggers a JavaScript as soon as you have selected a text in the input element.

<input type="text onselect="examplefunction ( ) " value="exampletext">

Data attributes

In addition to the HTML attributes listed above, there are some attributes which can only be evaluated with a script or used with CSS. This allows information to be included which is not presented visually. These HTML attributes always start with data-. You can set them with setAttribute and read them with getAttribute. Search engines also do not evaluate these HTML attributes. Only lowercase letters, numbers, hyphens, periods, and colons are allowed for the data attributes.

id="example elements"

Conclusion: HTML attributes are important for almost every website

If you decide to learn HTML, you’ll notice that HTML attributes are an important steppingstone to an optimal and fully functional website. The HTML attributes are the best and safest way to employ functions which deviate from everyday use. The stored information will ensure that all aspects of your new website work in conjunction with each other. It is especially easy to use with one of the HTML editors.


A perfect website — just the way you like it. You have access to all the tools you need to build your online presence from the get-go with the Website Builder from IONOS. Alternatively, our experts can create your website according to your individual wishes. Choose the right model for your requirements!

In order to provide you with the best online experience this website uses cookies. By using our website, you agree to our use of cookies. More Info.
Manage cookies