tutorialstonight logo
A Platform To Learn To Code

HTML ATTRIBUTE



HTML attribute gives additional information to the element.

Generally we use HTML elements in simplest form but using attributes we can control how it's content looks, size of content,position of content and can provide other useful information.

HTML attribute is only specified in the starting tag.

The attribute has two properties:

  1. name: - name is the first part of the attribute which specifies the name of the attribute.
  2. value: - value is the second part of the attribute and it contains value of the attribute.

Syntax:

<tag attribute_name="attribute_value">Content of the element</tag>

Example

Run the code

HTML core attribute

There are few attributes which can be used with most of the HTML element.These attributes are:

  1. style
  2. class
  3. id
  4. title


1).HTML style attribute

The style attribute allows us to use inline CSS in our element.

Using style attribute we can add almost all CSS property to the element.

Example

Run the code

2).HTML class attribute

The class attribute can be used in almost all HTML elements.

When a class is defined in any HTML element then that element contains all the property mentioned for that class.

Example

Run the code

3).HTML id attribute

The id attribute is used to uniquely identify any HTML element.

It is used by css and javascript to perform certain tasks of a specific element.

Example

Run the code
Both class and id look the same when used for css but you can use a specific class as many times you want in you web page but id can be used only once.


4).HTML title tag

The title tag is used to provide additional information to the content of the element.

It shows the information provided when you take the mouse pointer over it.

Example

Run the code

HTML href Attribute

In <a> tag href attribute is used to specify the address of the link.

Example

Run the code

HTML src Attribute

src attribute is used to define file location in <img> tag.

Example

Run the code